System Design Arena

System Design: Spotify

Architect a global music streaming service with real-time playback, personalization, and licensing controls.

Functional RequirementsNon-Functional RequirementsAPI Endpoints

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.

🎯 Start guided practice (free)

Scorecard

What the interviewer is evaluating

Requirements7/10
Scale estimation8/10
API design6/10
Architecture8/10
Trade-offs8/10
Failure handling6/10

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.

1

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.

2

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.

3

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.

4

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.

5

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

1

Ingest pipeline

2

object storage +

object storage + metadata DB

3

CDN distribution

Playback

1

client obtains token

2

CDN stream

3

telemetry backhaul

Personalization

1

batch

2

streaming pipelines feeding recommendation API

Offline

1

encrypted packages stored locally

encrypted packages stored locally, license service validates keys

Observability

1

per-region playback latency

per-region playback latency, license audit logs, ML feedback loop

Flow Diagram

How the API maps to this flow

  1. 1GET /api/catalog?region=β€” returns available tracks.
  2. 2POST /api/playback/sessionβ€” issues playback token + CDN URL.
  3. 3POST /api/offline/requestβ€” schedules encrypted download package.
  4. 4GET /api/playlists/{id}β€” personalized playlist or editorial mix.
  5. 5POST /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.