Labs

System lab · medium · 28 min

Spotify: Music streaming

Near-instant playback for a catalog of millions of tracks, even on weak networks.

You tap a song and it plays. That's the whole product, and it hides most of its engineering behind one feeling: instant. If a song takes three seconds to start, people notice. If it stutters in a tunnel, they notice more.

In this lab you'll design a music streaming service like Spotify's from a blank page. The audio files themselves are boring. The interesting part is getting the first second of sound to someone's ear before they've finished lifting their thumb, on a train, on 3G, anywhere in the world.

The brief

People pick a song, an album or a playlist and listen. Most listening happens in long sessions: a commute, a workout, a workday with headphones on. Songs follow each other, usually in an order the app already knows.

Who uses it:

  • Listeners on phones, desktops, cars and smart speakers. Mostly on mobile networks, often moving.
  • Artists and labels upload tracks and care about one number from us: how many times each track was played, because that's how they get paid.

For this lab:

  • In: playing a track, playlists and queues, a catalogue of 100 million tracks, adapting to bad networks, recording plays.
  • Out: recommendations, search ranking, podcasts and video, social features, the royalty maths itself. We'll record plays reliably and hand them to someone else.

Requirements

Functional

  • A listener can play any track in the catalogue.
  • A listener can play a playlist or album in order, or shuffled.
  • Playback adapts to the network: lower quality on a bad connection, higher on Wi-Fi.
  • Premium listeners can download tracks for offline listening.
  • Every play of 30 seconds or more is recorded for royalties.

Non-functional

  • Playback starts within 300 ms for the median tap, and within 1 second for 99% of taps.
  • No stalls mid-song for a listener with any working connection.
  • Skipping to the next track in a queue feels instant (under 100 ms).
  • Play events are not lost. A missing play is lost money for an artist.
  • Available in every region, with traffic served close to the listener.

The first requirement drives almost every decision in this lab. Keep an eye on it.