Design Spotify (music streaming)
Stream a catalog of 100M+ tracks instantly, sync playlists across devices, work offline and count every play precisely enough to pay artists. Audio is small compared to video, so the interesting parts are licensing, the play-event pipeline and recommendations.
In one sentence
Serve audio from a CDN plus the device's own cache, keep playlists in a horizontally scalable store, and treat every play as an event that feeds royalties, charts and batch-computed recommendations.
A reference design: it covers what an app like this needs and follows how these companies have described their systems publicly, simplified to be learnable.
Requirements
Functional
- Search and play any track instantly
- Playlists synced across devices, collaborative
- Offline downloads
- Personalized playlists and radio
Non-functional
- Playback starts in < 300 ms, no gaps between songs
- Licensing rules per country
- Accurate play counts for royalties
- Read-heavy catalog, write-heavy event stream
Back-of-the-envelope estimates
| Metric | Estimate |
|---|---|
| Monthly users | ~650M (public figure), ~30% active at peak hours |
| Catalog | 100M+ tracks × ~4 MB × 3 qualities ≈ 1+ PB |
| Plays | Billions per day → tens of thousands of play events/s |
| Bandwidth per stream | 160 kbps vs ~5 Mbps for HD video: 30× less than Netflix per user |
API and data model
GET /search?q=… → tracks, artists, albums
GET /tracks/:id/play → { signedUrl, quality }
POST /playlists/:id/tracks { trackId } → { version }
POST /events [ { type: "play", trackId, ms, ts } … ] (batched)
tracks(id, title, artist_id, album_id, duration, rights_by_country)
playlists(id, owner_id, name, version) playlist_tracks(playlist_id, position, track_id)Architecture
Step by step · Play a song
- 01Taps a song
- 02GET /tracks/42/play
- 03Licensed in Spain? Signed URL for 320 kbps
- 04Track metadata from cache
- 05Downloads the first chunk and starts playing
- 06File from the nearest edge (or the device cache)
- 07"Played > 30 s" event sent
At this scale · 1M users
Services and an event pipeline
- ▸Playback checks licensing rights per country
- ▸Every play is an event: royalties, charts and recommendations depend on it
- ▸Discover Weekly-style playlists computed in weekly batch jobs
Tap any box to see what it does.
Deep dive: every play is money
Artists and labels are paid per stream, so plays must be counted reliably and only once, but not instantly. Clients batch events and send them to an event delivery system (Kafka/Pub-Sub). From there they land in a data warehouse that produces royalty reports, charts and training data.
- At-least-once delivery + deduplication by event id: a phone that retries doesn't create a second stream.
- Offline plays are stored on the device and uploaded when it reconnects.
- Recommendations like weekly discovery playlists are produced by batch jobs over everyone's history, then written as ordinary playlists.
- Gapless playback: the client prefetches the next track while the current one plays.
How it changes with scale
Step by step · Edit a playlist
- 01Adds a song to "Road trip"
- 02INSERT into playlist_tracks
- 03Saved
- 04Other devices and collaborators sync the new version
At this scale · 100 users
Tracks in a bucket, playlists in SQL
- ▸Audio files in object storage, metadata and playlists in PostgreSQL
- ▸Search with PostgreSQL full-text
- ▸Plays counted with a simple insert
Tap any box to see what it does.
| Users | What you run | Why it changes |
|---|---|---|
| 100 | App + PostgreSQL + S3 | A small catalog and a few listeners |
| 10K | CDN, Redis, device cache, prefetching | Bandwidth and perceived latency |
| 1M | Playback/licensing, playlist, search services; event pipeline; batch recommendations | Licensing, royalties and personalization become core |
| 100M+ | Cassandra for playlists, data warehouse, offline downloads, multi-region | Billions of playlists and events per day |
Key takeaways
- 01Audio is small: a CDN plus on-device caching makes playback instant.
- 02Licensing is a per-country check on every play.
- 03Play events feed royalties, charts and recommendations: deliver them reliably and deduplicate.
- 04Personalized playlists are precomputed in batches and stored like any other playlist.
Check your understanding
1 of 3
Why does audio start instantly on Spotify?