Time-series database implementation for metrics, IoT, financial data, and observability backends. Use when building dashboards, monitoring systems, IoT platforms, or financial applications. Covers TimescaleDB (PostgreSQL), InfluxDB, ClickHouse, QuestDB, continuous aggregates, downsampling (LTTB), and retention policies.
npx skills add https://github.com/ancoleman/ai-design-components --skill using-timeseries-databases
Implement efficient storage and querying for time-stamped data (metrics, IoT sensors, financial ticks, logs).
Choose based on primary use case:
TimescaleDB - PostgreSQL extension
InfluxDB - Purpose-built TSDB
ClickHouse - Columnar analytics
QuestDB - High-throughput IoT
Automatic time-based partitioning:
CREATE TABLE sensor_data (
time TIMESTAMPTZ NOT NULL,
sensor_id INTEGER NOT NULL,
temperature DOUBLE PRECISION,
humidity DOUBLE PRECISION
);
SELECT create_hypertable('sensor_data', 'time');
Benefits:
Pre-computed rollups for fast dashboard queries:
-- TimescaleDB: hourly rollup
CREATE MATERIALIZED VIEW sensor_data_hourly
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 hour', time) AS hour,
sensor_id,
AVG(temperature) AS avg_temp,
MAX(temperature) AS max_temp,
MIN(temperature) AS min_temp
FROM sensor_data
GROUP BY hour, sensor_id;
-- Auto-refresh policy
SELECT add_continuous_aggregate_policy('sensor_data_hourly',
start_offset => INTERVAL '3 hours',
end_offset => INTERVAL '1 hour',
schedule_interval => INTERVAL '1 hour');
Query strategy:
Automatic data expiration:
-- TimescaleDB: delete data older than 90 days
SELECT add_retention_policy('sensor_data', INTERVAL '90 days');
Common patterns:
Use LTTB (Largest-Triangle-Three-Buckets) algorithm to reduce points for charts.
Problem: Browsers can't smoothly render 1M points
Solution: Downsample to 500-1000 points preserving visual fidelity
-- TimescaleDB toolkit LTTB
SELECT time, value
FROM lttb(
'SELECT time, temperature FROM sensor_data WHERE sensor_id = 1',
1000 -- target number of points
);
Thresholds:
Time-series databases are the primary data source for real-time dashboards.
Query patterns by component:
| Component | Query Pattern | Example |
|-----------|---------------|---------|
| KPI Card | Latest value | SELECT temperature FROM sensors ORDER BY time DESC LIMIT 1 |
| Trend Chart | Time-bucketed avg | SELECT time_bucket('5m', time), AVG(cpu) GROUP BY 1 |
| Heatmap | Multi-metric window | SELECT hour, AVG(cpu), AVG(memory) GROUP BY hour |
| Alert | Threshold check | SELECT COUNT(*) WHERE cpu > 80 AND time > NOW() - '5m' |
Data flow:
Auto-refresh intervals:
For implementation guides, see:
references/timescaledb.md - Setup, tuning, compressionreferences/influxdb.md - InfluxQL/Flux, retention policiesreferences/clickhouse.md - MergeTree engines, clusteringreferences/questdb.md - Line Protocol, SIMD optimizationFor downsampling implementation:
references/downsampling-strategies.md - LTTB algorithm, aggregation methodsFor examples:
examples/metrics-dashboard-backend/ - TimescaleDB + FastAPIexamples/iot-data-pipeline/ - InfluxDB + Go for IoTFor scripts:
scripts/setup_hypertable.py - Create TimescaleDB hypertablesscripts/generate_retention_policy.py - Generate retention policiesBatch inserts:
| Database | Batch Size | Expected Throughput |
|----------|------------|---------------------|
| TimescaleDB | 1,000-10,000 | 100K-1M rows/sec |
| InfluxDB | 5,000+ | 500K-1M points/sec |
| ClickHouse | 10,000-100,000 | 1M-10M rows/sec |
| QuestDB | 10,000+ | 4M+ rows/sec |
Rule 1: Always filter by time first (indexed)
-- BAD: Full table scan
SELECT * FROM metrics WHERE metric_name = 'cpu';
-- GOOD: Time index used
SELECT * FROM metrics
WHERE time > NOW() - INTERVAL '1 hour'
AND metric_name = 'cpu';
Rule 2: Use continuous aggregates for dashboard queries
-- BAD: Aggregate 1B rows every dashboard load
SELECT time_bucket('1 hour', time), AVG(cpu)
FROM metrics
WHERE time > NOW() - INTERVAL '30 days'
GROUP BY 1;
-- GOOD: Query pre-computed rollup
SELECT hour, avg_cpu
FROM metrics_hourly
WHERE hour > NOW() - INTERVAL '30 days';
Rule 3: Downsample for visualization
// Request optimal point count
const points = Math.min(1000, chartWidth);
const query = `/api/metrics?start=${start}&end=${end}&points=${points}`;
DevOps Monitoring → InfluxDB or TimescaleDB
IoT Sensor Data → QuestDB or TimescaleDB
Financial Tick Data → QuestDB or ClickHouse
User Analytics → ClickHouse
Real-time Dashboards → Any TSDB + Continuous Aggregates
Efficient database search tool for bioRxiv preprint server. Use this skill when searching for life sciences preprints by keywords, authors, date ranges, or categories, retrieving paper metadata, downloading PDFs, or conducting literature reviews.
Access BRENDA enzyme database via SOAP API. Retrieve kinetic parameters (Km, kcat), reaction equations, organism data, and substrate-specific enzyme information for biochemical research and metabolic pathway analysis.
Access ClinPGx pharmacogenomics data (successor to PharmGKB). Query gene-drug interactions, CPIC guidelines, allele functions, for precision medicine and genotype-guided dosing decisions.
Query NCBI ClinVar for variant clinical significance. Search by gene/position, interpret pathogenicity classifications, access via E-utilities API or FTP, annotate VCFs, for genomic medicine.
Access COSMIC cancer mutation database. Query somatic mutations, Cancer Gene Census, mutational signatures, gene fusions, for cancer research and precision oncology. Requires authentication.
Query Ensembl genome database REST API for 250+ species. Gene lookups, sequence retrieval, variant analysis, comparative genomics, orthologs, VEP predictions, for genomic research.
Query openFDA API for drugs, devices, adverse events, recalls, regulatory submissions (510k, PMA), substance identification (UNII), for FDA regulatory data analysis and safety research.
Query NCBI Gene via E-utilities/Datasets API. Search by symbol/ID, retrieve gene info (RefSeqs, GO, locations, phenotypes), batch lookups, for gene annotation and functional analysis.
Take ancoleman/using-timeseries-databases from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.