Design a Product Analytics System
Design a billion-event-per-day analytics pipeline with fast minute-count dashboards, accurate late-event warehouse totals, and a measurable recovery and scaling plan.
Problem statement
For this exercise, assume a growing startup wants to track user behavior across its product. It is scrappy and does not want to use services like Amplitude or Mixpanel. Its mobile and web applications generate events, such as a user clicking add to cart or making a purchase.
Design an SDK for the applications and an API to receive the emitted events, then ingest and store those events.
Dashboards need a low-latency endpoint that shows only how many events happened per minute. For example, an internal user can ask for the number of installs per minute over the last 2 hours, for the latest minute, hour or day, or for today's add-to-cart count.
Any such query, going back 1 week, must complete in under 500 ms 99% of the time.
Events are also enriched. Enrichment is any addition or update of event data needed for analysis, such as a reverse-geo lookup, finding location from the client IP, or context tagging. Store the events.
Also provide a warehouse system that runs more complex queries and may answer slowly, such as counting page load events grouped by US state over the last 3 months, counting click events in the US region over the last 3 months, or counting how many users added to cart over two months.
The system receives about 1 billion events per day and has many event types. Use this as the steady-state baseline. For this exercise, also explain how the pipeline handles a sustained rise to twice that rate and catches up after a processor outage; an unbounded flash crowd is outside scope.
Expect follow-up questions on events that arrive out of order, on deduplication, and on how you keep dashboard reads fast. Explain what each component does and why it is there, including load balancers, rather than only naming it.
For this exercise, assume one company with up to 10,000 event types. Each event has an event ID, an event type, a user ID, an event time from the device, and bounded attributes, about 1 KB in total. A dashboard query names one event type and a time range, and it counts events by UTC minute of event time.
Retries of one event ID count once. An event up to 24 hours late still updates its minute; an older one reaches only the warehouse. The SDK may hold events on an offline device for up to 7 days. The event ID, event type and event timestamp do not change on retry.
A malformed or implausible timestamp is flagged rather than silently assigned to another day. A dashboard response says which accepted input its counts have processed; this progress does not mean that offline devices have sent all events for that day.
Newer minutes are still filling, and any minute in the last 24 hours can still rise slightly from late events. Warehouse data appears within 1 hour and is kept for 6 months.
Daily warehouse aggregates deduplicate by event ID and assign events to their original UTC event date, including offline events that arrive after the dashboard correction window. Such daily totals remain provisional through the seven-day offline window and the warehouse load delay.
Raw client IP addresses are not kept after the location lookup. Alerting, funnels and sessions, experiments, per-user activity feeds, and drawing the dashboard UI are out of scope.
For this exercise, target a durable ingest acknowledgement within one second at p99 and visibility of 99% of valid, dashboard-eligible events within two minutes of server acceptance during normal operation. Device offline time is outside that processing deadline and must be measured separately.
Discuss lag, throughput, checkpoint and sink health, backpressure and autoscaling. In the retry and recovery deep dive, explain one concrete Spark or Flink source-to-sink path; naming an engine alone does not establish exactly-once results.
A minute older than 24 hours can still change after an outage if previously accepted, eligible input has not finished processing; cached results must follow that processing progress or output version.
What to build
- Mobile and web apps use an SDK to send events to an ingest API, which accepts them durably and handles retries safely.
- Internal users get per-minute counts for one event type over any range in the last week, in under 500 ms at p99, with late and retried events counted once.
- Events get added or updated data, such as location from a reverse-geo lookup and context tags, and the enriched events are stored.
- Internal users can run slower complex queries in a warehouse, such as page load counts grouped by US state over the last 3 months.
At scale
- About 1 billion events per day, about 11,600 per second on average. For this exercise, support a sustained rise to twice that baseline with bounded capacity; up to 10,000 event types and about 1 KB per event.
- Dashboard queries going back 1 week complete in under 500 ms at the 99th percentile. For this exercise, one query covers one event type and returns at most 10,080 minute points.
- For this exercise, events arriving up to 24 hours after their event time update dashboards; offline queues and client retries last at most 7 days. All accepted events reach the warehouse within 1 hour of acceptance and are kept for 6 months, about 180 TB raw before compression. Warehouse daily totals remain provisional through 7 days plus the load delay; retain and deduplicate later replay within the stored history.
- For this exercise, target 99.9% monthly ingest and dashboard availability, p99 durable ingest acknowledgement within 1 second, and 99% of eligible events visible in counts within 2 minutes of acceptance. A small team must observe lag and safely scale toward twice baseline without losing accepted input or weakening deduplication.