How would you design an analytics/metrics pipeline?
523 views
80 of 106
1
The problem
Question presented to candidate:
"Our web and mobile apps emit a firehose of product events: page views, clicks, sign-ups, purchases. Product managers want dashboards that update within a minute, and finance wants daily numbers they can trust. Design the pipeline from the device to the dashboard."
What a strong answer should cover:
Collection: batched client SDKs, a stateless ingest API, an event schema with event ID, event time and receive time, schema validation and versioning
A durable log (Kafka or similar) as the backbone, partitioned for throughput, retained for replay
Stream processing with event-time windows and watermarks, a policy for late events, and deduplication of retries; why processing-time windows give wrong answers
Storage: raw events in a columnar data lake, pre-aggregated rollups in an OLAP store for fast dashboards; partitioning and sort keys
Distinct counts with mergeable sketches (HyperLogLog), because unique counts do not add across hours or regions
Lambda vs Kappa: stream for freshness, batch or replay for corrections; a worked capacity estimate and what breaks at 10x
Clarifying questions expected:
How many events per day, how large, and how bursty?
How fresh must dashboards be, and how exact must the numbers be (approximate uniques acceptable)?
How late can events arrive (offline mobile clients), and must corrections update past numbers?
Code / implementation expected: Optional โ the examples run event-time windows with watermarks, duplicates and late events against a batch truth, and compare exact and HyperLogLog distinct counts.
analytics
pipeline
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Engineers who have sent analytics events from an app and want to know how they become trustworthy dashboard numbers, and candidates preparing for a data-pipeline design round.
Difficulty: Hard
Verified with: Node 22.22 and Python 3.12 (both examples print identical output in both). The Lambda/Kappa history is from coverage of Jay Kreps's 2014 O'Reilly essay "Questioning the Lambda Architecture" (HPCwire, Kai Waehner); Redis HyperLogLog size and error (12 KB, 0.81%) from the Redis documentation.
How to read this doc: Every idea is explained in plain language first, then tagged with ๐ Interview term: so you also learn the words an interviewer expects. Every number comes from running the examples; the Verified section quotes their full output.
1. Why This Even Matters โ A Story First
An election night newsroom receives vote counts from thousan
The solution is hidden so you can try first
19 min read ยท 17 sections
4
Read the code
Event-time windows with watermarks, late events and retry duplicates, compared with processing-time windows and a batch recompute