Preparing your design workspace

Loading the problem and your latest saved attempt…

Design Friend-Shared Charts for a Music Player

Turn every counted play into each listener's weekly top-10 chart, let listeners share their charts with friends, and build a combined friends chart, while a chart stops being visible to a person within a minute of sharing being turned off or the friendship ending.

Problem statement

Design the backend for the charts feature of an online music player.

For this exercise, assume the player already streams songs, and that playback, the song catalog, search and recommendations are out of scope. A play counts once it has lasted 30 seconds; the app then reports it with a play ID, the song ID and the time.

If the app gets no confirmation, it resends the same play with the same play ID, usually within a few seconds and always within 10 minutes.

Each listener has a weekly chart: the 10 songs they played most in the current week, with each song's play count. Weeks run from Monday 00:00 to Sunday 24:00 UTC. When a week ends, its chart is final and is kept for 52 weeks.

Also assume friendships are mutual and are kept by an existing friend service, which can list a person's current friends and publishes an event whenever a friendship starts or ends. A listener can turn sharing on or off; it is off by default.

While it is on, each of their current friends can see their current chart and their kept past charts. A listener can also open a friends chart: this week's 10 songs that appear on the most current charts of their friends who share.

Privacy matters more than freshness. Within a minute after a listener turns sharing off, or after two people stop being friends, the other person must no longer see that listener's charts, and their friends chart must stop counting that listener. A page that is already open may keep what it shows until it is refreshed.

What to build

  1. The app can report counted plays, and each play is counted exactly once toward its listener's weekly chart, even when the app resends it.
  2. A listener can see their current weekly top 10 with play counts, updated within a minute of a play, and their charts from the past 52 weeks.
  3. A listener can turn sharing on or off; while it is on, every current friend can see that listener's current and past charts, and within a minute after sharing is turned off or the friendship ends, the other person no longer can.
  4. A listener can see a friends chart: this week's 10 songs that appear on the most current charts of their friends who share, never more than 5 minutes out of date.

At scale

  • For this exercise, assume about 100 million listeners a day with about 40 counted plays each: about 4 billion plays a day, about 46,000 a second on average and about 150,000 a second at the evening peak.
  • For this exercise, assume a person has up to 5,000 friends and typically about 200, and about 3 in 10 listeners turn sharing on.
  • For this exercise, assume about 20,000 chart page views a second at peak, about a quarter of them friends charts, and that 99% of chart pages must load within 300 ms.
  • For this exercise, assume a listener's own chart reflects a play within 1 minute, friends may see a chart change up to 5 minutes late, and a chart must stop being visible to a person within 1 minute after sharing is turned off or the friendship ends.