KatInterview

Designing a Real-Time and Batch Device Telemetry Pipeline

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsstream-processingdata-pipeline

Last updated

Architect an ingest-to-query system that handles millions of device messages per second while serving both sub-second dashboards and long-range batch analytics.

You are asked to design a system that collects telemetry from a very large fleet of connected devices — think millions of units — and makes that data useful in two distinct ways:

  • Near-real-time consumption: live dashboards that refresh within seconds, plus threshold and anomaly alerts that fire within roughly half a minute.
  • Batch consumption: historical queries spanning months, scheduled aggregates, offline model-training jobs, and ad-hoc SQL against the raw data.

Your design should address:

  1. How devices connect and deliver data (transport protocols, authentication, buffering on the device and server side).
  2. Where data lives at each stage — a fast "hot" tier for recent data and a cheap "cold" tier for the long tail.
  3. How the real-time path and the batch path relate to each other (two separate pipelines? one unified stream? how do you reconcile them?).
  4. How you model the schema and how you partition/shard data through the pipeline.
  5. How the system scales, stays reliable, and stays affordable.
  6. A small, concrete set of APIs and query shapes you intend to support.

Assume devices are multi-tenant (grouped into customer fleets), sometimes go offline for hours and reconnect in bursts, occasionally retransmit duplicate readings, and may report clock times that are wrong or out of order. State your assumptions about scale explicitly before drawing the architecture.

Hints

Hint 1

Write down the arithmetic first: devices × messages per second per device gives you sustained throughput; multiply by payload size to get bytes per second and per day. Peak load often hits 3–5× the average because of reconnect storms after an outage.

Hint 2

The single most important architectural decision is inserting a durable, replayable log between producers and consumers. Once the gateway acknowledges a write only after the log commits, you get your no-loss guarantee and you can attach as many independent readers as you want.

Hint 3

Separate the hot tier from the cold tier by *latency requirement*, not just by age. The latest-value cache, the time-series store for dashboard queries, and the object-store lake answer very different questions. Missing-heartbeat detection is really an event-time timer problem.

Hint 4

Late and duplicate data are the crux: pick event time with bounded watermarks for the streaming path, let anything later than the bound land in the lake, and recompute the affected aggregate partitions in batch. That reconciliation is exactly why keeping both paths pays for itself.