Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Global Most-Listened Songs Leaderboard

Count qualified song listens once at high write volume and publish an exact global top ten with bounded freshness.

Problem statement

An original-author Meta E5 interview report says a design round asked for the top ten listened-to songs. It does not identify the audience, time window, listen rule, tie break, scale, or update deadline. All such details below are authored exercise assumptions.

For this exercise, assume a music service shows one global, non-personalized top-ten chart for qualified completed listens since chart launch. A playback service emits a qualified completion event after at least thirty seconds of a song have played.

Each event has stable playback ID, song ID, event time and producer identity; producer retries preserve the original playback ID, song ID, event time and qualified payload. Each accepted qualified event contributes exactly one count to its song, and the chart orders songs by count descending, then song ID ascending.

A read returns up to ten song IDs with exact published counts, snapshot version and freshness time.

Design admission, deduplication, high-volume counting, exact top-ten computation, atomic snapshot publication, reads, and recovery. Event time may be up to five minutes behind or thirty seconds ahead of arrival.

Age validation precedes dedup lookup: too-old and implausibly future submissions, including retries, are rejected or quarantined and never counted again. Counts are all-time from chart launch, so ordinary accepted events only increase totals.

Fraud reversals, royalty accounting, local/country charts, personal rankings, and recommendation models are outside this first version.

What to build

  1. Accept authorized qualified completion events with stable identity, observable duplicate/invalid outcomes, and durable replay position.
  2. Maintain exact all-time per-song counts for accepted events, including retries and recoverable worker restarts, without letting a hot song block other songs.
  3. Compute a deterministic exact global top ten and atomically publish a versioned snapshot with counts and freshness.
  4. Return the current complete snapshot quickly and disclose stale or unavailable state rather than combining ranks from different generations.

At scale

  • For this exercise, assume 100,000 qualified completion events per second at peak across ten million songs; one viral song may receive 25 percent of writes. The chart receives 30,000 reads per second.
  • For this exercise, 99 percent of healthy accepted listens must affect a published chart within 60 seconds of acceptance. A chart read completes within 200 milliseconds p95. If the latest snapshot is more than two minutes old, readers must see its stale status rather than a claim of current ranking.
  • For this exercise, accept event times no more than five minutes behind and thirty seconds ahead of server arrival. Validate age before dedup: old or future submissions, even with a known playback ID, return TOO_OLD or FUTURE without a count effect. An in-window same-ID/same-immutable-payload retry returns its prior receipt; a changed in-window payload conflicts. Retain replayable accepted events and dedup receipts seven days, while durable cumulative counts and published snapshot lineage persist.
  • For this exercise, qualified completion events are immutable after admission. No retractions are required in version one; any later correction policy would need a new count and ranking contract rather than an implicit decrement.