KatInterview

Real-Time Leaderboard for a High-Traffic Content Platform

System DesignModel answer
MediumModel answerSystem Designstream-processingdistributed-systemsapproximation-algorithms

Last updated

Design a distributed service that tracks the most-viewed content items over a rolling one-hour window at 100K events/sec, serving ranked results with low latency.

Scenario

A video streaming platform wants to surface a "Trending Now" rail on its homepage. The rail shows the top-K most-watched videos over the past hour and refreshes every minute. Product analytics says the platform receives roughly 100,000 play-start events per second across tens of millions of distinct video IDs.

What You Need to Design

Build the backend service that powers this feature end to end.

Functional requirement

Expose an API that returns the current top-K trending videos. Callers should be able to request any K up to 1,000 and optionally filter by region or content category.

Scale and performance targets

  • 100K write events per second on average; plan for 3× spikes.
  • Millions of distinct video IDs active within any given hour.
  • Dashboard read latency: p99 under 50 ms, high availability.
  • Rankings may lag reality by a few seconds to one minute — eventual consistency is fine.

What your answer should cover

  1. Ingestion — how you get 100K events/s reliably into the processing pipeline without losing data during spikes.
  2. Aggregation — how you count efficiently across distributed nodes over a sliding one-hour window, and why you prefer streaming over re-scanning the full window each minute.
  3. Memory and accuracy trade-offs — exact counters versus a probabilistic sketch; when each is appropriate and what the error bounds look like.
  4. Storage and serving — where precomputed rankings live, how reads stay fast and isolated from the write path, and how you avoid serving a partially-written result.
  5. Reliability — what happens when a processing node crashes, traffic spikes far above average, or the pipeline stalls entirely.

Describe your architecture as a labeled data-flow (text is fine, no diagram tool required), then walk through each component and the key trade-offs you made.

Hints

Hint 1

Think about where the heaviest computation should happen — the write path or the read path. Precomputing rankings before a request arrives is almost always the right call at this scale.

Hint 2

A sliding window does not require re-reading all 360M events every minute. Each node can maintain per-minute delta buckets: add the new minute's counts, subtract the minute that just expired, and the running total stays current in O(active items) work.

Hint 3

Exact hash maps work fine when cardinality is in the tens of millions (roughly 640 MB cluster-wide at 64 B per entry). A Count-Min Sketch only becomes necessary if cardinality or the number of dimension combinations explodes — know the error formula (εN overcount with probability 1 − δ) so you can justify the switch.