The whole course ▾

System Design · Mock interview 11 of 20

Design Spotify

Updated 22 Oct 2026 · By Akshay, software engineer, India · 9 min read

Design a music streaming app like Spotify.

Try it first

Before you read the interview, answer the question yourself. Give yourself 10 minutes: say your design out loud, or sketch it on paper. What would you ask? Which numbers matter? Which boxes, and what's the hard part? Then read on, and score yourself with the feedback at the end.

The video for this mock interview is coming soon.

New System Design videos go up at 6 pm. Subscribe on YouTube so you don't miss it.

Got a doubt? Ask in the comments under the video.Subscribe

Requirements

Requirements
Clarifying questions
->
Features? -> Play, search, playlists, offline
->
Scale? -> 200M daily listeners, 100M songs
->
Quality? -> Several levels, up to 320 kbps
->
Start time? -> Under 300 milliseconds
Functional requirements
Play any song, instantly
Search songs, artists, albums
Playlists, synced on every device
Download for offline listening
Non-functional requirements
->
Playback starts in under 300 ms
->
No gaps on a patchy network
->
Playlists consistent across devices
->
Highly available, worldwide
Out of scope
Recommendations
Podcasts and video
Paying artists
interviewer
Hi, good to see you. Shall we start?
candidate
Yes. I'll draw as I go.
interviewer
Design a music streaming app, like Spotify.
candidate
Okay. It's tempting to call it YouTube for audio. But songs are short, played again and again, skipped constantly, and listened to on the move. Let me ask a few questions to see what matters.
interviewer
Sure.
candidate
Which features?
interviewer
Play, search, playlists, and offline downloads.
candidate
What scale?
interviewer
Two hundred million daily listeners, and a hundred million songs.
candidate
What audio quality?
interviewer
Several levels, up to three hundred and twenty kilobits a second.
candidate
And how fast must a song start after a tap?
interviewer
Under about three hundred milliseconds.
candidate
That matters a lot, because people skip all the time.
candidate
So, what it does. Play any song, starting instantly. Search across songs, artists and albums. Playlists that stay in sync on your phone, laptop and speaker. And download songs for offline listening, on a plane or in the metro.
candidate
And how well. Playback starts in under three hundred milliseconds. No gaps in the music when the network gets patchy. Playlists stay consistent across devices. And it's highly available, worldwide.
interviewer
All fair.
candidate
I'll leave out recommendations, podcasts and video, and paying artists, though I'll keep the listening data they'd need. Does that match what you had in mind?
interviewer
Yes. Start with playback.

Estimation

Estimation
Back of the envelope
100M songs × ~15 MB (all qualities) ~ 1.5 PB
200M listeners × 90 min a day
At 160 kbps ~ 1.2 MB a minute
~ 20 PB delivered every day
WHAT THE NUMBERS DECIDE
Bytesdelivereddwarf
bytesstored:theCDNis
thedesign,andhitsongs
makeitwork.
candidate
Let me size the catalogue, then the listening.
interviewer
How much data, and how much traffic?
candidate
Songs first, then the people listening to them.
candidate
A hundred million songs, each stored in several qualities, about fifteen megabytes in all, is around one and a half petabytes. Big, but fixed. Now the listeners: two hundred million, for about ninety minutes a day. At a typical hundred and sixty kilobits a second, that's about one point two megabytes a minute. So roughly twenty petabytes delivered every day.
interviewer
How many play at once at peak?
candidate
Maybe thirty million songs at the busiest moment, which is why the edge matters so much.
candidate
So every day we send out more than ten times the whole catalogue. The CDN is the design. And music has a lucky property: a few thousand hit songs make up most of the listening, and those stay cached at every edge.
interviewer
And the phone?
candidate
The phone is a cache too, since people replay the same songs.

API and data

API and data
Tracks
title, artist,
album, file keys
Playlists
owner, name,
version
Playlist
entries
playlist,
position, track
Audio files
object storage
1 : many
points to
file keys
Endpoints
1
GET /tracks/{id}/stream ->
signed URLs
2
GET /search?q=…
3
PATCH /playlists/{id} + version
4
POST /offline/{track} -> licence
+ file
candidate
Next, the API, and the tables.
interviewer
What does the API look like?
candidate
Four groups: play, search, playlists, offline.
candidate
GET a track's stream returns short-lived, signed URLs for the audio chunks, at each quality, on the CDN, so the app downloads audio from the CDN, never from our servers. GET slash search. PATCH slash playlists, an ID, with the changes and the version they were based on. And POST slash offline, a track, returns an encrypted file and a licence to play it.
interviewer
Why sign the URLs?
candidate
So the CDN can check a request is allowed without asking us, and a leaked link stops working within minutes.
candidate
Tracks: the song's details, and the keys of its encoded audio files, which live in object storage. Playlists: owner, name, and a version number. And playlist entries: one row per song in a playlist, with its position, pointing at a track. A song in fifty million playlists is stored once. And every song is encoded ahead of time into each quality, so playback never waits for processing.
interviewer
Why encode ahead of time, and not on demand?
candidate
A song is encoded once but played billions of times. On demand would repeat the work on every first play.

High-level design

High-level design
Spotify
app
API
gateway
Playback service
signs CDN URLs
CDN edge
hit songs cached
Object storage
every song, every
quality
play track 77
1
2
signed URLs
3
audio
chunks
4
only on a miss
Catalogue service
plus search index
Playlist
service
Kafka
listening
events
search
playlists
played 30 s
TWO RISKS
Asongmuststartinunder
300ms,eventhrougha
tunnel.Andplaylistsmust
stayconsistent.
interviewer
Okay. Let's see the design.
interviewer
Walk me through what happens when someone presses play.
candidate
There's a small control path and a huge audio path. I'll show them separately.
candidate
The Spotify app asks, through the API gateway, to play a track. The playback service checks the user may play it, and returns signed URLs for its audio chunks. The app then fetches the audio itself from the nearest CDN edge, which holds every hit song, and goes back to object storage only on a miss. Our servers handle a tiny request; the CDN handles the megabytes.
interviewer
Why check the user at all, if the CDN serves the file?
candidate
Licensing. Some songs aren't available in some countries, and free users have limits. The signed URL carries that decision.
candidate
Alongside, a catalogue service, with a search index, cached heavily, because the catalogue barely changes. A playlist service. And every play, skip and pause goes as a listening event into Kafka, which feeds play counts, recommendations, and the reports artists are paid from.
interviewer
How many events is that?
candidate
Tens of billions a day. Small, but many, which is what Kafka is built for.
interviewer
What's hard here?
candidate
Two things. A song has to start in under three hundred milliseconds, and keep playing through a tunnel. And a playlist edited on a phone and a laptop at once has to stay consistent.
interviewer
Start with playback.

Deep dive: instant, smooth playback

Deep dive: instant, smooth playback
Download the whole file
Waits for megabytes before playing
Wastes data on skipped songs
Can't change quality midway
Stream in small chunks
Plays after the first few seconds
Skips waste almost nothing
Quality can change per chunk
Starting fast
1
Hit songs cached at every edge
2
First chunk at a lower quality
3
Pre-fetch the next song in the queue
4
Keep 30+ seconds buffered ahead
High-level design
Spotify
app
API
gateway
Playback service
signs CDN URLs
CDN edge
hit songs cached
Object storage
every song, every
quality
play track 77
1
2
signed URLs
3
audio
chunks
4
only on a miss
Catalogue service
plus search index
Playlist
service
Kafka
listening
events
search
playlists
played 30 s
~1% of songs, most plays
next song pre-fetched
TWO RISKS
Asongmuststartinunder
300ms,eventhrougha
tunnel.Andplaylistsmust
stayconsistent.
interviewer
Let's start with what users feel.
interviewer
How does a song start in under three hundred milliseconds, every time, even when people skip constantly?
candidate
First, how the audio is fetched. Two options.
candidate
Downloading the whole file before playing means waiting for megabytes on a slow network, wasting data on songs skipped after five seconds, and being stuck with one quality. Streaming in small chunks, a few seconds each, means sound starts after the first chunk, a skip wastes almost nothing, and the quality can change from chunk to chunk. So, chunks.
interviewer
How big is a chunk?
candidate
A few seconds of audio, a few dozen kilobytes. Small enough to start quickly, big enough not to waste requests.
candidate
Then four tricks make the start feel instant. Hit songs are cached at every CDN edge, close to the listener. The first chunk can come at a lower quality, so sound starts sooner, then quality rises. The app pre-fetches the next song in the queue while the current one plays, so pressing next is instant. And during playback, the app keeps thirty seconds or more buffered ahead.
interviewer
That's a lot of tricks.
candidate
Each saves a few dozen milliseconds. Together, a skip feels like nothing happened.
candidate
So the edge holds the small share of songs that gets most of the plays, and the app pre-fetches whatever's next in its queue. The long tail, a rare song nobody nearby has played this month, comes from a regional cache or from object storage. Its first play takes a little longer, and after that it's cached nearby too.
interviewer
Who decides what counts as a hit?
candidate
The CDN does it for us. Whatever is requested often simply stays in the cache.
interviewer
The train enters a long tunnel, longer than the buffer. What does the listener hear?
candidate
First, the buffer plays on. As the network weakens, the app drops to a lower quality, which downloads faster and stretches the buffer. If it truly runs dry, the music pauses, and resumes when signal returns. And songs played often can be cached on the phone automatically, so favourites keep playing with no signal at all.
interviewer
Nice.

Deep dive: playlists and offline

Deep dive: playlists and offline
Syncing playlists
1
Send changes, not the whole list
2
Each change names the version it saw
3
Server applies them in order: v8, v9
4
Devices fetch changes since their version
OFFLINE DOWNLOADS
Downloadsareencrypted;
thelicenceexpiresunless
theappchecksin,about
every30days.
interviewer
Now, the playlists.
interviewer
Your phone adds a song to a playlist, while your laptop, offline, removes another. How does the playlist stay in sync everywhere?
candidate
By syncing changes, not whole lists.
candidate
Each device sends changes: add this song after that one, remove this entry. Each change names the version it was based on. The server applies changes in order, giving each new version a number, and since adding and removing different songs don't collide, both survive. Every device then fetches the changes since its own version.
interviewer
And if both move the same song?
candidate
The later change wins, and nothing is lost.
interviewer
Why not send the whole playlist each time?
candidate
Two devices sending whole lists would overwrite each other. Small changes merge.
interviewer
What about offline downloads?
candidate
The song is stored on the phone encrypted, and can only be played with a licence key from the app. The licence expires unless the app comes online now and then, about every thirty days. So a cancelled subscription, or a song removed from the catalogue, stops playing offline too, without the server needing to reach the phone.
interviewer
Can someone copy the file to another phone?
candidate
They can copy it, but without the licence key it won't play.
interviewer
One playlist has ten thousand songs. Any problem?
candidate
I'd load it in pages, with a cursor, and show the first fifty instantly. Positions are stored as sortable keys with gaps between them, so inserting a song in the middle doesn't renumber nine thousand rows. And the playlist is cached as a whole, since people read playlists far more than they edit them.
interviewer
Good.

Wrap-up

Wrap-up
Next steps
1
Recommendations from listening events
2
Exact play counts for artists
3
Watch start time and rebuffering
4
Regions near listeners
INTERVIEWER'S FEEDBACK
Strong:theCDNatthecentre,chunked
streaming,aninstantstart,playlists
syncedbyversionedchanges.Nexttime:
awordonCDNcost.Verdict:hire.
interviewer
A few minutes left.
interviewer
What would you improve with more time?
candidate
A few things.
candidate
First, recommendations, trained offline on the listening events we're already collecting. Second, exact play counts for paying artists, with a running count and a nightly recount, because it's money. Third, I'd watch the time from tap to sound, and how often playback pauses to rebuffer. And fourth, regions near listeners, for playlists and accounts, while the audio keeps coming from the CDN.
interviewer
Which would you do first?
candidate
The watching. Start time is what every listener feels, every day.
interviewer
Okay, let's stop there. Good job. You saw that the bytes delivered dwarf the bytes stored and put the CDN at the centre, your tricks for an instant start were concrete, and playlists sync by small, versioned changes. If I push: at twenty petabytes a day, the CDN bill is one of the biggest costs in the company, and it deserves a sentence. I'd say a hire.
candidate
Thanks. I'll think about the cost side.
Interviewer's feedback

Strong: the CDN at the centre, chunked streaming, an instant start, playlists synced by versioned changes. Next time: a word on CDN cost. Verdict: hire.

Score yourself

Interviewers score these seven things. Give your own attempt a tick for each one you did.

  • Asks before drawing. Agrees what the system does, and how well: scale, speed, consistency.
  • Turns users into requests a second and bytes a day, and says what the numbers decide.
  • A small, clear contract, and a data model that fits how the data is read.
  • A working path end to end before any detail. Every box has a reason.
  • Picks the hard parts, compares two options, and chooses one with a trade-off said out loud.
  • What breaks, what happens then, and how users notice. Retries, duplicates, limits.
  • Thinks out loud, checks in with the interviewer, and takes a hint without losing the thread.

0 of 7

Your progress stays on this device.
New System Design videos at 6 pm

Lessons on weekdays, the week's revision on Saturday, a mock interview on Sunday.