Design a High-Throughput IoT Telemetry Ingestion Pipeline
System DesignModel answerLast updated
Design a backend that ingests millions of concurrent device data streams, separating critical alerts from bulk telemetry while explicitly reasoning through availability, scalability, and maintainability trade-offs.
Context
A large fleet of connected devices — think smart sensors, industrial equipment, or consumer electronics — continuously streams health and status signals to a central cloud backend. Each device emits a small payload (roughly 1 KB) every 10 seconds containing readings like temperature, power draw, component status, and any active fault codes.
Your task is to design the backend ingestion and processing service for this platform.
Functional Requirements
- Accept a continuous stream of device telemetry over persistent connections (gRPC, MQTT, or WebSocket are all reasonable choices).
- Detect and route critical safety or fault signals to an alert dispatcher within 1 second of receipt.
- Make fleet data available to operational dashboards (near-real-time) and downstream batch analytics jobs.
Scale
| Dimension | Target |
|---|---|
| Connected devices | 5,000,000 active |
| Average ingress | 500,000 messages/sec |
| Peak ingress | 1,000,000 messages/sec (~1 GB/s) |
| Ingestion ack latency | < 100 ms |
| Critical alert latency | < 1 second end-to-end |
| Critical path availability | 99.99% |
| General telemetry availability | 99.9% |
What to Address
Your answer should cover architecture, data flow, storage choices, and — critically — how you reason through the following three tensions:
- Availability vs. Consistency: How do you handle network partitions between devices and your ingestion layer? What guarantees do you offer for critical alerts versus routine metrics?
- Scalability vs. Maintainability: At 1 million RPS, it is tempting to over-engineer with bespoke caching layers and finely sliced microservices. How do you keep the architecture understandable and operable while still handling the load?
- Backpressure and Failure Isolation: How does the system protect itself when a downstream store degrades, without silently dropping critical alerts?
You are expected to justify your choices, call out trade-offs explicitly, and identify what you would cut or simplify to reduce operational burden.
Hints
Hint 1
Start by deriving the numbers you will need: raw bytes per day, broker count, gateway node count. These estimates shape every major decision before you draw a single box.
Hint 2
The most important structural choice is whether critical alerts and bulk telemetry share the same write path. Think about what happens to alert latency if the high-volume path is under backpressure.
Hint 3
For availability vs. consistency, classify each data type separately. Routine heartbeats and critical fault codes have very different tolerance for loss, duplication, and ordering — design their guarantees independently rather than applying one model to both.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify Requirements and Derive the Key Numbers
Before drawing any architecture, derive the figures that drive sizing decisions:
| Quantity | Estimate |
|---|---|
| Persistent connections | 5 M devices (plus reconnect bursts after regional outages) |
| Average ingress | 500 K RPS, 500 MB/s |
| Peak ingress | 1 M RPS, ~1 GB/s |
| Raw data per day | ~0.5 GB/s × 86,400 s ≈ 43 TB/day; ~6–8 TB compressed |
| Critical alert share | < 0.1% of messages, but availability requirement is 99.99% (~52 min downtime/year) |
| Kafka (telemetry cluster) | 1 GB/s × replication factor 3 = 3 GB/s replicated writes; at ~100–150 MB/s per broker that is ~25–35 brokers; 72 h retention ≈ 40–60 TB compressed |
| Gateway nodes | ~100 K connections per stateless Go node → ~50 nodes minimum; run ~100 across 3 AZs to absorb AZ loss and reconnect storms |
Two questions worth asking upfront: Does the device classify alerts locally, or must the cloud derive them? (Answer: both — devices flag known fault codes; the cloud also detects patterns the device cannot see.) What delivery guarantee is expected? (Answer: alerts are at-least-once with dedup; bulk telemetry is best-effort with edge buffering.)
2. API Contract
Devices hold a gRPC bidirectional stream to a regional gateway:
message Telemetry {
string device_id = 1;
uint64 seq_no = 2; // monotonic per device, used for dedup
int64 ts_device_ms = 3;
Priority priority = 4; // NORMAL or CRITICAL
bytes payload = 5; // Protobuf, versioned via schema registry
}
enum Priority { NORMAL = 0; CRITICAL = 1; }
message Ack {
uint64 seq_no = 1;
oneof result {
bool ok = 2;
uint32 retry_after_ms = 3; // explicit backpressure signal
}
}
retry_after_ms is the backpressure escape valve: the gateway tells the device to back off rather than silently dropping messages.
Dashboard and analytics consumers use REST: GET /devices/{id}/latest, GET /fleet/metrics?signal=&window=, GET /alerts?since=.
3. High-Level Architecture
Device (edge buffer)
│ gRPC stream
▼
Regional Load Balancer
│
▼
Go Gateway nodes (stateless: authn, validate, route by priority)
│ │
│ CRITICAL lane │ NORMAL lane
▼ ▼
Kafka (alerts cluster) Kafka (telemetry cluster, 256–512 partitions)
│ │
▼ ├──► Flink (enrichment, rollups, derived alerts)
Flink alert engine │ ├──► TimescaleDB (hot, 7–30 days)
(+ derived alerts) │ └──► Latest-state KV (Redis/Cassandra)
│ ├──► Kafka Connect → S3/Iceberg (cold, system of record)
▼ └──► Kafka Connect → Elasticsearch (fault codes only)
Alert dispatcher
(on-call, ops tools, device commands)
The single most important structural decision here is splitting the write path at the gateway by priority. The critical alerts land in a separate, smaller, over-provisioned Kafka cluster. A backpressure event or broker slowdown on the high-volume telemetry cluster cannot affect alert throughput. Flink also reads the telemetry stream to derive alerts the device did not flag (e.g., a fleet-wide temperature gradient or a rate-of-change anomaly) and publishes those into the alerts cluster.
Alert latency budget:
| Stage | Budget |
|---|---|
| Gateway receive + produce | ~30–50 ms |
Kafka acks=all (RF=3) | ~20–50 ms |
| Flink consumer + rules eval | ~100 ms |
| Dispatch | ~200 ms |
| Total | ~350–400 ms — well under the 1 s target |
4. Trade-off Deep Dives
Availability vs. Consistency
These two data types have fundamentally different needs, so treat them separately:
Bulk telemetry is AP. Accept writes, ack fast, and tolerate duplicates and mild out-of-order delivery. Consumers dedup on (device_id, seq_no) and use event-time windows with watermarks in Flink. Occasional gaps in a temperature chart are acceptable. The fleet operates single-region, multi-AZ — 99.9% SLA allows ~8.7 hours of downtime per year, which a client-side ring buffer covers for transient outages.
Critical alerts prioritize durability, then availability via redundancy. The device maintains a persistent outbox and retransmits until it receives an ack, giving at-least-once delivery at the source. The alerts Kafka cluster runs active-active across two regions. If the primary region is partitioned, devices fail over using DNS or anycast with a pre-configured secondary endpoint. Dispatch is idempotent on (device_id, alert_id), so cross-region duplicates are harmless.
A common mistake is applying one consistency model to everything. That leads to either over-engineering routine telemetry storage or under-protecting critical alerts.
Scalability vs. Maintainability
At this scale, the temptation is to add layers: custom caches, a microservice per signal type, a bespoke routing engine. Resist it. Complexity has an on-call cost that compounds over time.
The architecture above has roughly five deployable components: gateways, two Kafka clusters, Flink, managed storage. Each one is a well-known, horizontally scalable primitive:
- Gateways are stateless — authn, validate, produce. They hold no business logic and scale on connection count.
- Kafka is the single decoupling point. Scaling is adding partitions or brokers.
- Flink owns all stateful stream logic with checkpointing for fault tolerance.
- Kafka Connect sinks are configuration, not code.
Deliberately accept some storage redundancy (raw data in S3 plus rollups in TimescaleDB rather than a single clever store) in exchange for operational simplicity.
Backpressure and Failure Isolation
Backpressure must work at every layer:
-
Device edge buffer. Devices keep a bounded ring buffer on local flash covering hours of telemetry. On
retry_after_msor a disconnect, they buffer and replay with jittered exponential backoff — this prevents a 5 M device reconnect storm from compounding an outage. When the buffer fills, NORMAL data is downsampled first. CRITICAL data is never dropped at the edge. -
Gateway admission control. If produce latency to the telemetry cluster exceeds a threshold, gateways return
retry_after_msfor NORMAL messages. Per-gateway token buckets and Kafka client quotas enforce this. The CRITICAL lane has reserved broker capacity and is never subject to shedding. -
Kafka absorbs downstream slowness. A slow TimescaleDB sink just adds consumer lag — Kafka is disk-backed with bounded retention. Raw data is always captured.
-
Sinks are independent consumer groups. A degraded Elasticsearch instance does not affect the S3 sink or Flink processing. The system of record is always intact.
5. Common Mistakes to Avoid
- Mixing alert and telemetry paths. A single Kafka cluster or gateway pool creates a noisy-neighbor problem at peak load. Physical separation is cheap; missing a brake-failure alert is not.
- Storing every heartbeat in Elasticsearch. Elasticsearch is optimized for search, not raw time-series at 1 M RPS. Use it only for fault events and diagnostics; use a proper TSDB for metrics.
- Forgetting schema evolution. At 5 M devices with varying firmware, payloads drift over time. Protobuf with a schema registry and CI-enforced backward/forward compatibility prevents silent data corruption downstream.
- Ignoring reconnect storms. A regional outage followed by recovery can produce a 5 M simultaneous reconnect. Jittered backoff at the device and pre-scaled gateway capacity (2× steady-state) absorb this without manual intervention.