Home›Design›IoT and telemetry
Design doc · IoT and telemetry

IoT, metrics and telemetry

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.

The short answerA time-series database (TimescaleDB, InfluxDB) or a column store (ClickHouse), with time partitioning, compression, downsampling and retention. Device metadata stays relational.
1 · The workload

What the application asks of the database

DimensionThis application
WritesVery high, steady, in time order. Mostly appends.
ReadsRanges of time for one device or a group, and aggregates per minute or hour.
Read to writeLow. Most data is written and rarely read.
ConsistencyLoose. A late reading is fine.
LatencyDashboards in a second or two.
GrowthHuge. Retention is the main design decision.
Connected

Real failures behind this design

These incidents are why the choices below matter. Each one is written up with its numbers and sources.

2 · What goes where

Each kind of data, its store, and why

ApplicationReadingsTimescaleDB, InfluxDB or ClickHouseSOURCE OF TRUTHDevices, owners, locationsPostgreSQLSOURCE OF TRUTHLatest value per deviceRedis, or a small table updated in placeCAN BE LOST IN REDISRaw archiveObject storage in ParquetARCHIVE

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.

DataWhere it goesWhy
ReadingsTimescaleDB, InfluxDB or ClickHouseTime partitions, compression of similar values, and dropping old partitions whole.
Devices, owners, locationsPostgreSQLFew rows, many relationships.
Latest value per deviceRedis, 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 archiveObject storage in ParquetCheap, and readable later by analytics tools.

How each family of store behaves under traffic: Database families.

3 · Data model

The core tables and the queries they serve

-- 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;
4 · How it grows

Start simple, change one thing at a time

  1. PostgreSQL with time partitionsWorks for a modest number of devices.
  2. Write rate or storage growsA time-series extension or a column store, with compression and rollups.
  3. Very large fleetsA message queue in front to absorb bursts, and several ingest workers writing batches.

Scale it: watch this design grow

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.

5 · What breaks first

The failures to plan for

What happensWhat you seeWhat I do
Row-by-row insertsCommit rate caps throughput long before disks doBatch. See what one commit costs in Notebook 2.
High cardinality labelsIndex size explodes in metric storesDo not use user IDs or request IDs as tags.
No retentionStorage bill grows every month without endDecide retention per resolution on day one.
6 · Alternatives

What I considered and did not pick

Cost. Compression and retention decide the bill. Column and time-series stores often compress telemetry many times over, so measure on your own data.

How this page was writtenFrom the engines' documentation and common practice. Measured on real servers: what one commit costs, which is why telemetry is inserted in batches, in the notebooks. Before you build: check the anti-patterns, size it with the capacity calculator, and write your own version from the design doc template. Want a second opinion? Submit it for review.
7 · Where to run it

On-prem, managed, EC2 or Kubernetes

StageWhere it runs
Where I would startA managed time-series or ClickHouse service
When it growsSelf-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.

8 · Estimate it

The numbers, worked live

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.

Part 3 of 4 · Design · 24 pagesAll pages

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.