Preparing your design workspace

Loading the problem and your latest saved attempt…

Design Rolling Top-N Movie Recommendations

Rank movies by views over the latest seven days with fresh, replay-safe streaming aggregates.

Problem statement

Design a system that recommends the top N movies based on views collected over the last seven days. For this exercise, assume every accepted view has a unique event ID, movie ID, viewer region, and event time; retried events count once, and events may arrive up to six hours late.

The primary query returns up to 100 movies globally or for one region, ordered by seven-day view count descending and movie ID ascending, with window bounds and a freshness watermark. Cover ingestion, deduplication, windowed counting, top-N maintenance, late events, skew, serving, rebuilding, and recovery.

Personalization and content ranking beyond view count are outside scope.

What to build

  1. Accept view events idempotently while retaining event-time and region dimensions.
  2. Maintain correct rolling seven-day counts and expire old contributions.
  3. Return deterministic global or regional top-N results with bounds and freshness.
  4. Apply bounded late events and rebuild serving state from retained accepted data.

At scale

  • For this exercise, assume two million view events per second, ten million movies, and 5,000 top-N queries per second.
  • For this exercise, healthy views should influence rankings within 30 seconds at p95 and queries should complete within 300 milliseconds at p95.
  • For this exercise, accept events up to six hours late, retain raw accepted events for ten days, and retain daily aggregate history for one year.
  • For this exercise, a single premiere may receive 20 percent of all views and must not stall unrelated keys or regions.