KatInterview

Building a Streaming Clickstream Metrics Platform End to End

System DesignModel answer
MediumModel answerSystem Designkafkaflinkstream-processing

Last updated

Design a streaming platform that turns raw website click events into fresh, correct, queryable aggregates, covering partitioning, windows, state, sinks, back-pressure and failures.

Scenario

Your company's website emits a continuous stream of click events. Product managers want dashboards that update within about a minute, and analysts want to run ad-hoc SQL over correct historical numbers. You are asked to own the data path from the browser to the queryable tables.

The intended building blocks are:

  • Kafka as the ingestion log,
  • Flink as the stream processor,
  • a warehouse or analytics store as the serving layer.

Task

Walk through the complete pipeline design. Your answer should cover:

  1. Requirements and scale. The questions you would ask first, and the numbers you assume (event rate, peak, event size, latency target, tolerance for late data).
  2. Kafka layout. How you choose the partition count and the partition key, and which producer and topic settings you rely on.
  3. Flink processing. The time semantics, window types and watermark strategy you would use, and how you deal with late and duplicate events.
  4. State management. The state backend, checkpointing setup, and how you handle large state such as deduplication and unique-user counts.
  5. Delivery guarantees. How you get correct results end to end, and what the sink must do.
  6. Table modeling. How downstream tables are shaped so that dashboards and analysts can use them safely, including schema evolution.
  7. Back-pressure and failure handling. How you detect and react to slow operators, bad records, job crashes, and the need to reprocess history.

Explain the trade-offs behind your choices, and say how you would verify the pipeline is producing correct results.

Hints

Hint 1

Start by writing down assumed numbers (events per second, peak, event size, freshness target, maximum lateness). Partition count, state size and checkpoint interval all follow from them.

Hint 2

Treat delivery guarantees as a property of the whole chain: at-least-once ingest plus deduplication, checkpointed Flink state and offsets, and a sink that is either transactional or idempotent.

Hint 3

Make late data and replays harmless: aggregate in event time, let late firings overwrite rows keyed by window and dimensions, and use mergeable sketches rather than summed counts for unique users.