← Questions
Top 10 songs per user from listening history
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in Meta's technical phone screen, last asked Aug 2025. It tests streaming, aggregation and top-k.
Design a service that shows every user of a music streaming app their ten most-played songs, computed from their listening history. The list should cover recent windows, such as the last 7 and 30 days, and stay fresh as people keep listening.
Requirements
- Functional:
GET /users/{id}/top-songs?window=7d|30d|allreturns ten songs with play counts. - Functional: plays count from listening events. Duplicates and very short plays (skips) are filtered out.
- Functional: backfill and replay, so counts can be rebuilt after a bug or a rule change.
- Non-functional: hundreds of millions of users and billions of play events a day.
- Non-functional: low-latency reads, and freshness within minutes for recent windows.
- Non-functional: listening history is personal data, with privacy and deletion rules.
Clarifying questions
- What counts as a play: a minimum duration, a full listen, or a play from start?
- Does "top" mean raw play count, or are personalization signals mixed in?
- How fresh must the list be: real time, minutes, or daily?
- Which time windows, and are they sliding or calendar-based?
- How are ties ranked?
What a strong answer covers
- Ingestion: clients send play events into a durable log partitioned by user id. Deduplication by event id, and sessionization to merge pauses and resumes into one play.
- The aggregation choice, decided: a streaming job keeps per-user counts in daily buckets (so a 7-day sliding window is a sum of 7 buckets) and updates each user's top-10. A daily batch job over the warehouse corrects the counts and handles replays.
- Storage: per-user, per-day song counts in a wide-column store, and the precomputed top-10 list per user and window in a key-value store or cache for reads.
- Maintaining the top-10 when counts change, and when old days expire out of the window. Recomputing from the buckets is cheap because one user's song set is small.
- Hot users and heavy listeners, late events, and the exact definition of the window boundary.
- Privacy: deleting a user's history, minimizing stored personal data, and regional rules.
Follow-ups
- Add top artists and top genres without new pipelines.
- A yearly summary for every user, all published on one day.
- A bug double-counted plays for six hours. How do you fix the numbers?
- Show the top songs among a user's friends.
Where it's asked
- Meta · Technical phone screen · Last asked Aug 202545 min · Two coding problems in CoderPad, about 20 minutes each · Usually no AI; some newer screens are AI-assisted
What it tests
streaming · aggregation · top-k
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing
