KatInterview

Warehouse Schema for a Consumer App's Engagement Events

System DesignModel answer
HardModel answerSystem Designdata-modelingpartitioningevent-analytics

Last updated

Model a high-volume user event stream in a relational warehouse so engagement metrics are cheap to compute, handling duplicates, late data, backfills and incremental rollups.

A consumer mobile app emits a continuous stream of user events (app opens, posts, taps, and so on). The analytics team wants to compute standard product metrics from this stream: daily, weekly and monthly active users, new users, D1/D7/D30 retention, funnel conversion (for example signup to first post), sessions per user and session length, and event counts sliced by platform or country.

Design a relational schema that lets these metrics be computed efficiently. State any assumptions about the metric list and scale first.

Your answer should cover:

  • Table definitions with columns and data types, primary and foreign keys, and a few sample rows.
  • The partitioning, clustering and indexing strategy.
  • Where you normalize and where you denormalize, and why.
  • How you deal with duplicate events and events that arrive late (or carry unreliable client clocks).
  • How the design supports backfills and incrementally maintained aggregate tables.
  • How the main metrics map onto your tables.

Hints

Hint 1

Almost every listed metric is 'per user per day' before it is aggregated further. Consider making a user-day table the central grain, and keep a separate raw, append-only layer underneath it.

Hint 2

Mobile clients retry and go offline, so each event needs a client-generated unique ID, and you must distinguish arrival time (trusted) from the device timestamp (not trusted). Think about which one drives partitioning at each layer.

Hint 3

Make every pipeline step idempotent: recompute and overwrite whole date partitions instead of updating rows. Then late data and backfills become 'rerun the affected days' rather than special cases.