KatInterview

Engagement Analytics Pipeline: Daily and Monthly Unique Users

System DesignModel answer
MediumModel answerSystem Designsystem-designdistinct-countinghyperloglog

Last updated

Design a pipeline that ingests app events and serves daily and monthly distinct-user counts, with sliced dashboards, correct handling of late data, and sound data-quality and privacy practices.

Problem

A consumer app with web and mobile clients needs an internal system that reports how many distinct people use it each day and each month. Design that system end to end.

A user counts as active in a time window if they produced at least one qualifying event in that window. Qualifying events are things like app open, session start, page view, or login. Passive traffic such as background pings does not count.

What to cover

  1. Definitions. Define the daily unique-user metric. For the monthly metric, pick either calendar-month uniques or a rolling 30-day window, justify the choice, and explain what you give up.
  2. Ingestion and event schema. Explain how events from web and mobile reach your backend, and list the fields every event must carry.
  3. Identity and duplicates. Describe how you handle repeated deliveries of the same event, and define a single canonical user key when events may carry a user_id, a device or anonymous ID, or neither (logged-out usage).
  4. Correctness of the numbers. Explain how you deal with time zones and day boundaries, late events, out-of-order events, client clock skew, and reprocessing of history.
  5. Storage and compute. Justify your choices between streaming and batch, and between exact and approximate distinct counting.
  6. Serving. Support near-real-time dashboards plus historical queries by date range, platform, country, and app version. Discuss latency, caching, and what correctness you promise to consumers.
  7. Operations. Cover anomaly detection, reconciliation, failure handling, and privacy (PII handling and retention).

Scale assumptions you may adopt or adjust

State your own numbers. A reasonable starting point is around 100M daily users, 300M monthly users, and several billion events per day.

Hints

Hint 1

Distinct counts are idempotent: a duplicated event cannot inflate the number of unique users. Think about where deduplication actually matters and where it is only an optimization.

Hint 2

You cannot add 30 daily unique counts to get a monthly one. Think about storing something per day that can be merged later, such as a per-day set of user IDs (bitmap) or a mergeable sketch.

Hint 3

Separate a fast, provisional path from a slow, authoritative one, and make the authoritative path a deterministic, re-runnable function of raw data plus a definition version so backfills are safe.

Hint 4

Keep the design simple enough to explain clearly: one raw store, one compact per-user-per-day table, one serving store. Be explicit about what lives where and why.