Design an IoT Platform
Understanding the Problem
📡 What is an IoT platform? An IoT platform is the backend that a fleet of connected devices talks to: thermostats, factory sensors, smart meters, cold-storage trackers. Devices keep a long-lived connection open, send small readings every few seconds, and receive configuration changes, commands and firmware updates. Applications on top query the readings, show dashboards and fire alerts. AWS IoT Core, Azure IoT Hub and self-hosted brokers like EMQX or HiveMQ are examples of the connection layer; the rest is usually custom.
A narrower version of this question is "1 million temperature sensors each report a reading every few seconds; store them and show per-building averages." That's the telemetry half of this design at a tenth of the scale, and everything below applies to it. We'll call out where the smaller number changes a choice.
Functional Requirements
Core Requirements
- Devices should be able to connect securely and send telemetry readings (temperature, humidity, power, battery).
- Users and applications should be able to query recent and historical readings for a device or a group of devices, including aggregates like average, min and max per minute or hour.
- Operators should be able to manage devices: register them, change their configuration, send commands, and roll out firmware updates.
- Users should be able to define alert rules ("freezer temperature above -15°C for 5 minutes") and be notified when they fire.
Below the line (out of scope)
- Device hardware and on-device firmware internals.
- Billing per device or per message.
- Analytics and ML on the data beyond aggregates and alert rules.
Non-Functional Requirements
Core Requirements
- The system should support 10 million devices connected at once, each sending a reading about every 10 seconds: around 1 million messages per second.
- Readings should be visible on dashboards within about 5 seconds, and alerts should fire within 30 seconds of the triggering reading.
- Telemetry must not be lost once a device has sent it and received an acknowledgment (at-least-once delivery). Duplicates are acceptable if we can dedupe.
- Commands and config changes should reach online devices within a second, and offline devices as soon as they reconnect.
- The platform must tolerate flaky networks: devices that drop off for hours, then reconnect and send buffered data, sometimes all at once after a regional outage.
Below the line (out of scope)
- Hard real-time control loops (milliseconds). Those run on the device or a local gateway, not in the cloud.
Let's run the numbers, because they shape every storage decision.
- Ingest: 10M devices / 10 s = 1M messages/s. At around 200 bytes per message (device ID, timestamp, a few metrics, MQTT and JSON overhead), that's 200 MB/s arriving, or 17 TB per day of raw payload.
- Data points: 1M readings/s × 86,400 s = 86 billion readings per day. Stored as rows in a relational database at 100+ bytes each with indexes, that's over 10 TB a day, which no row store will take for long.
- Compressed: time series databases compress regular numeric series very well (delta-of-delta timestamps, XOR-encoded floats, columnar layouts), often to a few bytes per point. At around 3 bytes per point, 86B points is about 260 GB per day. Thirty days of raw data is under 10 TB. That's manageable.
- Connections: 10M long-lived TLS connections. A well-tuned broker node holds on the order of hundreds of thousands of connections, so we need a few dozen broker nodes, plus headroom for reconnect storms.
For the 1M-sensor variant: 100k readings per second, 26 GB a day compressed, and a handful of broker nodes. The architecture is the same; the shard counts are smaller.
The key insight: the number of messages is high, but each message is tiny and the access pattern is predictable (append by time, read by device and time range, aggregate). That's exactly what time series storage and stream processing are built for. Don't reach for a general-purpose database for raw readings.