KatInterview

Real-Time Event Processing Pipeline for High-Volume Telemetry

System DesignModel answer
MediumModel answerSystem Designstreamingdata-pipelinedistributed-systems

Last updated

Build a scalable pipeline ingesting ~1B events/day from distributed clients, delivering both low-latency metrics and accurate daily reports.

You're building a telemetry platform for a consumer application with clients running on web browsers, mobile devices, and connected TVs. These clients generate behavioral events: user interactions, playback actions, screen views, and periodic health checks.

The platform handles approximately 1 billion events daily. Business stakeholders need two outputs from this single pipeline:

  1. Live operational metrics — dashboards showing current activity, user counts, and feature usage, refreshed within minutes
  2. Trusted aggregate reports — finalized daily summaries that downstream teams rely on for decisions and financial reporting

Design a complete pipeline from event generation through query-serving that maintains throughput during traffic surges so metrics reflect current state quickly rather than falling hours behind. Address the journey from client instrumentation, through collection and computation, to the systems where aggregated data is queried.

Your design must handle:

  1. System topology and capacity planning — Components from client through collection, buffering, computation, storage, and query layers. Include rough calculations (throughput rates, data volumes, partition counts, compute parallelism) that inform your choices.

  2. Throughput management — How you identify when processing is falling behind incoming volume, and how you maintain pace during traffic increases without silently losing data.

  3. Out-of-order arrivals — Devices lose connectivity and batch-upload events much later. Events may arrive hours or days after they actually occurred. How do you keep daily totals correct when relevant events arrive after a day's report has been published?

  4. Event deduplication — Network behavior means clients may send the same event multiple times. How do you ensure each real-world event increments your counters exactly once?

Operating Parameters

  • Average daily volume ~1B events; traffic follows usage patterns with peak loads 3-10× the average — sustained rates of tens of thousands events/sec with spikes approaching 100k events/sec
  • Events average 0.5-1 KB (identifiers, timestamps, event classification, contextual attributes) in JSON or Avro; roughly 0.5-1 TB raw data daily
  • Each event includes event timestamp (when it occurred on the device) distinct from arrival timestamp (when received by infrastructure)
  • Client delivery is at-least-once — network retries mean duplicate sends are possible
  • Live dashboards should reflect reality within minutes; hourly rollups within several minutes; final daily numbers within hours of day boundary
  • Aggregates must be correct and auditable — late events and duplicates cannot corrupt counts; finalized daily figures must be trustworthy
  • System should buffer rather than drop during overload, then recover
  • Assume cloud infrastructure with managed storage, message queues, stream processors, and analytical databases

Key Questions to Explore

  • What latency guarantees do consumers need — sub-minute updates or hourly/daily batch acceptable?
  • Can published daily totals be revised, or must they be immutable once released?
  • Is approximation acceptable (probabilistic distinct counts) or must all aggregates be exact and reconcilable?
  • What's the realistic window for late data — minutes, hours, days — and is there a cutoff beyond which late events are handled separately?
  • What serves as the deduplication key? Do events carry stable client-generated IDs, or must you construct keys from event attributes?
  • Which metrics matter most (distinct user counts, additive counters like plays, conversion funnels) and what's the dimensional cardinality?
  • How stable is the event schema — do you need versioning and evolution support?
  • What are retention, cost, and compliance constraints (raw vs aggregated retention, PII, deletion handling)?
  • Is the priority lowest latency, lowest cost, or operational simplicity?

Hints

Hint 1

Consider separating the speed layer (real-time approximations) from the batch layer (accurate reconciliation) and how they eventually converge

Hint 2

Use event-time windowing with watermarks to handle out-of-order delivery while eventually closing windows for finalization

Hint 3

Think about how idempotency keys and stateful deduplication within bounded windows can achieve exactly-once semantics