Where should millions of sensor readings per minute go?
Applications like this: device telemetry, application metrics, fleet tracking, smart meters. This page is written the way I write a database design doc: the workload first, then where each kind of data goes and why, then how it grows, what breaks, and what I rejected.
| Dimension | This application |
|---|---|
| Writes | Very high, steady, in time order. Mostly appends. |
| Reads | Ranges of time for one device or a group, and aggregates per minute or hour. |
| Read to write | Low. Most data is written and rarely read. |
| Consistency | Loose. A late reading is fine. |
| Latency | Dashboards in a second or two. |
| Growth | Huge. Retention is the main design decision. |
These incidents are why the choices below matter. Each one is written up with its numbers and sources.
Solid arrows: the application writes there. Dashed arrows: a copy fed from the source of truth (change data capture, an outbox, or a cache fill), which can be rebuilt from it.
| Data | Where it goes | Why |
|---|---|---|
| Readings | TimescaleDB, InfluxDB or ClickHouse | Time partitions, compression of similar values, and dropping old partitions whole. |
| Devices, owners, locations | PostgreSQL | Few rows, many relationships. |
| Latest value per device | Redis, or a small table updated in place | "What is the temperature now" should not scan the history. In Redis the latest value can be lost; in the small table it is durable, but every reading writes the same hot row. |
| Raw archive | Object storage in Parquet | Cheap, and readable later by analytics tools. |
How each family of store behaves under traffic: Database families.
-- TimescaleDB (a PostgreSQL extension)
CREATE TABLE readings (
device_id bigint NOT NULL,
ts timestamptz NOT NULL,
metric text NOT NULL,
value double precision
);
SELECT create_hypertable('readings', 'ts');
-- per-minute averages for the dashboard
SELECT time_bucket('1 minute', ts) AS minute, avg(value)
FROM readings
WHERE device_id = 42 AND ts > now() - interval '1 day'
GROUP BY minute ORDER BY minute;
Pick a stage, then throw something at it. The numbers are a model to show the shape of each change, not a measurement; the measured numbers are in the lab notebooks.
| What happens | What you see | What I do |
|---|---|---|
| Row-by-row inserts | Commit rate caps throughput long before disks do | Batch. See what one commit costs in Notebook 2. |
| High cardinality labels | Index size explodes in metric stores | Do not use user IDs or request IDs as tags. |
| No retention | Storage bill grows every month without end | Decide retention per resolution on day one. |
Cost. Compression and retention decide the bill. Column and time-series stores often compress telemetry many times over, so measure on your own data.
| Stage | Where it runs |
|---|---|
| Where I would start | A managed time-series or ClickHouse service |
| When it grows | Self-managed on VMs when volume is high and steady, and storage cost dominates |
For a team without a dedicated database team. Who does which job in each option, and the full-cost comparison: Where to run the database.
The back-of-the-envelope numbers I would want before choosing anything. Move the assumptions to match your application. The link keeps your numbers, so a colleague sees the same ones.
Which database does my application need? What kind of application data goes in which database, and why, as design docs, plus the anti-patterns and the decisions behind them.