System Design Arena
System Design: Spotify
Architect a global music streaming service with real-time playback, personalization, and licensing controls.
Case Study
Music Streaming Platform
Same conversation, diagrams, and wrap-up you expectβnow framed with clearer scaffolding and iconography.
Prompt
Build Spotify for 400M listeners. Support personalized playlists, offline downloads, social sharing, and live metrics for artists.
Interview snapshot
- β’ Topic: Music Streaming Platform
- β’ Expected depth: 45 - 60 minutes
- β’ Focus areas: APIs, scale estimation, resilient architecture
- β’ Wrap-up: risk, monitoring, disaster recovery
Key takeaways
- β’ Music ingestion (labels, artists) with metadata and licensing windows.
- β’ Playback start time < 300 ms for cached assets.
- β’ GET /api/catalog?region= - returns available tracks.
ποΈ Interview mode
Practice this like a real interview
Don't read the answer first. Work the framework against the bare prompt, then compare against what the interviewer expected at each step.
Scorecard
What the interviewer is evaluating
Staff-level signal
Does the candidate notice audio is small enough to cache aggressively (unlike video) and spend their depth on metadata, playlists, and personalization instead?
π§ Staff engineer judgment
Audio at 4MB is not a CDN-scale problem β a single hot song is trivially cacheable. Spend your complexity budget on user data consistency, not on bytes.
Calibration
The common (bad) answer
App β API β Music Service β Song storage
β Why this scores poorly: Copies the YouTube answer at 1/100th the file size. Audio streamingβs hard parts are catalog rights, playlist consistency, and recommendation freshness β none of which appear.
β What a strong answer adds
- Size a song (~3β5MB Ogg): whole catalogs fit on edge caches; devices prefetch aggressively.
- Split the catalog (read-heavy, slowly changing) from user data (playlists, likes β write-heavy).
- Playlists need read-your-own-writes; global charts do not β say which store gives each.
- Offline downloads as a licensed lease with expiry, not a file copy.
- Personalization pipeline as async batch + near-real-time signals.
Build it up
Step-by-Step Walkthrough
Music streaming looks like small-file CDN delivery until licensing, sub-300ms playback, and a billion daily events walk in. Build the boring pipe first, then layer the systems that make it feel instant and personal.
Naive: an MP3 server with a login page
Tracks sit in object storage, a catalog table maps track β file, and GET /api/stream/{id} proxies audio bytes through your app servers. With a small catalog and few users, done.
Two things break at once. Egress: ~10M concurrent streams at ~256 kbps is on the order of ~2.5 Tbps β through your app tier, that is absurd. Licensing: labels license per region with time windows, so serving any track to anyone is not a bug, it is a contract violation. The catalog needs to be region-aware from day one.
Ingest pipeline plus tokenized CDN playback
Ingestion becomes a real pipeline: labels deliver masters, the pipeline transcodes to multiple bitrates (Ogg/AAC), writes metadata with licensing windows and territory rights, and pushes assets to object storage and out to CDN caches. The full catalog β ~60M tracks at ~5 MB β is only ~300 TB compressed, tiny by video standards, so the hot set caches beautifully.
Playback splits control from data: POST /api/playback/session checks the user's region against licensing, then issues a short-lived playback token plus CDN URL. The sub-300ms start trick is that the client prefetches the first seconds of likely-next tracks (rest of the album, top of the queue), so most 'starts' are already on the device.
?Licensing is the constraint that shapes everything
Interviewers reward candidates who treat region rights as a first-class filter β checked at catalog browse AND token issuance, with data residency for EU vs US catalogs β rather than an afterthought bolted onto a generic file server.
The event firehose feeds personalization
Every play, pause, skip, and like backhauls to POST /api/plays β around ~1B plays/day (~11.5K/sec average, ~50K/sec with interaction events at peak) into a Kafka cluster. These events are simultaneously the analytics source, the royalty-accounting input, and the raw material for recommendations, so losing them is losing money.
Personalization runs on two clocks: batch pipelines compute taste vectors and weekly playlists (Discover Weekly, Release Radar) overnight, while streaming pipelines update session features in near-real-time. Both feed a feature store β ~400M users at ~1 KB per vector is only ~400 GB in Redis/Scylla β that the recommendation API reads at request time.
Offline downloads without giving the music away
Offline is not 'save the MP3.' POST /api/offline/request schedules an encrypted package; tracks land on the device encrypted, and a license service issues time-limited decryption keys tied to an active subscription. The client re-validates when connectivity returns β lapse the subscription and the keys stop renewing, so the cached bytes become inert.
The interviewer follow-up is sync conflicts: playlists edited on a phone in airplane mode and on a laptop simultaneously. Per-item operations with last-writer-wins timestamps (or a simple op-log merge) handle it β say the strategy out loud rather than hand-waving 'it syncs.'
!DRM keys are a availability dependency
If the license service is down, paying users lose access to music already on their device. State the mitigation: keys valid for days not minutes, renewed opportunistically in the background, with a grace window before playback is refused.
Close the loop: observability and artist analytics
Operationally you watch per-region playback start latency (the product metric), CDN hit rates, and Kafka consumer lag β because a lagging pipeline silently degrades tomorrow's recommendations. License audit logs answer the label question 'prove this track never streamed outside its window,' which is a compliance requirement, not nice-to-have.
The same event stream powers artist dashboards: near-real-time stream counts and payout reporting. Ending here shows you see the two-sided marketplace β listeners get sub-300ms magic and Discover Weekly; artists and labels get trustworthy numbers, which is what keeps the catalog licensed at all.
Blueprint
Architecture Diagram
The narrated components above, laid out as an actual flow β so you can see how a request moves through the system, not just read a list of pieces.
Ingest pipeline
Ingest pipeline
object storage +
object storage + metadata DB
CDN distribution
Playback
client obtains token
CDN stream
telemetry backhaul
Personalization
batch
streaming pipelines feeding recommendation API
Offline
encrypted packages stored locally
encrypted packages stored locally, license service validates keys
Observability
per-region playback latency
per-region playback latency, license audit logs, ML feedback loop
Flow Diagram
How the API maps to this flow
- 1
GET /api/catalog?region=β returns available tracks. - 2
POST /api/playback/sessionβ issues playback token + CDN URL. - 3
POST /api/offline/requestβ schedules encrypted download package. - 4
GET /api/playlists/{id}β personalized playlist or editorial mix. - 5
POST /api/playsβ client telemetry: play/pause/skip/like events.
?But why does this actually hold up at scale?
10M concurrent streams at 256 kbps -> 2.5 Tbps egress β need multi-CDN.
Video walkthrough
Google system design interview: Design Spotify
IGotAnOffer: Engineering Β· ex-Google interviewer Β· 42 min
A recorded mock with a real ex-Google interviewer β watch how the candidate is pushed on storage and streaming.
Work the prompt yourself first β guided practice grades your own answer step by step. Watching someone else design it feels like progress and teaches you far less.
Interview flow
Dialogue timeline
Interviewer
Outline the major flows.
Candidate
Ingest/licensing pipeline for tracks, personalization (recommendations & playlists), streaming delivery with DRM, offline sync, artist analytics.
Interviewer
How do you serve playback globally?
Candidate
Use a multi-CDN with token-auth so clients fetch encrypted chunks. Local edge caches handle popular songs; fallback to origin if miss.
Interviewer
Describe personalization at scale.
Candidate
Event stream (listens, skips) -> Kafka -> feature store -> ML pipelines (collaborative filtering, embeddings). Pre-compute daily mixes; serve via low-latency API.
Scoping
Requirements & trade-offs
Functional Requirements
- βMusic ingestion (labels, artists) with metadata and licensing windows.
- βUser playback with adaptive streaming, offline downloads, cross-device sync.
- βPersonalized playlists (Discover Weekly, Release Radar), search, social sharing.
- βArtist dashboards with live metrics, payout reporting.
Non-Functional Requirements
- βPlayback start time < 300 ms for cached assets.
- βData residency for licensing (e.g., EU vs US catalogs).
- βDRM compliance, secure token-based downloads.
- βScalability: 10M concurrent streams, 1B daily events for analytics.
Blueprint
Architecture modules
Module 1
API Endpoints
- β’GET /api/catalog?region= - returns available tracks.
- β’POST /api/playback/session - issues playback token + CDN URL.
- β’POST /api/offline/request - schedules encrypted download package.
- β’GET /api/playlists/{id} - personalized playlist or editorial mix.
- β’POST /api/plays - client telemetry: play/pause/skip/like events.
Module 2
Back-of-the-Envelope
- β’10M concurrent streams at 256 kbps -> 2.5 Tbps egress β need multi-CDN.
- β’Library: 60M tracks * 5 MB avg -> 300 TB (compressed) replicated across storage + CDN caches.
- β’Events: 1B plays/day ~ 11.5K events/sec; with likes/skips ~50K events/sec β Kafka cluster 6 brokers.
- β’Personalization store: user vectors (1 KB) for 400M users -> 400 GB in feature store (Redis/Scylla).
Module 3
System Diagram Notes
- β’Ingest pipeline -> object storage + metadata DB -> CDN distribution.
- β’Playback: client obtains token -> CDN stream -> telemetry backhaul.
- β’Personalization: batch + streaming pipelines feeding recommendation API.
- β’Offline: encrypted packages stored locally, license service validates keys.
- β’Observability: per-region playback latency, license audit logs, ML feedback loop.
Module 4
Design Playbook
- β’Clarify DRM/licensing constraints per region.
- β’Explain caching/CDN plus token auth for secure playback.
- β’Detail personalization pipeline (offline batch + online features).
- β’Cover offline downloads: storage, tamper-proof license, sync conflicts.
- β’Discuss monitoring (playback latency, churn signals) and artist analytics.