System design interview: design a music streaming service like Spotify

A music streaming service stores a large catalog of tracks, plays any of them within a moment of a tap, and counts every listen accurately enough to pay rights holders. In the interview, the hard parts are getting audio bytes to listeners cheaply through a CDN, starting playback fast, and turning billions of play events into trustworthy counts.

By Published 8 min read

1. Clarify the requirements

"Design Spotify" is huge, so choose a slice with the interviewer. The walk-through below treats this as a generic music service of that kind; it does not describe how Spotify itself is built.

  • Functional: search the catalog; play a track, album or playlist; create and edit playlists; download for offline listening (paid tier); record each play for artist payouts.
  • Non-functional: playback starts fast after a tap (aim for a few hundred milliseconds on a good connection); no gaps between tracks; the catalog is read by everyone and written rarely; play counts must not be lost or double-counted.
  • Usually out of scope: recommendations and personalized home screens (a separate design), podcasts and video, social features, artist upload tools.

2. Estimate the scale

These numbers are assumptions picked for easy arithmetic, not any real service's figures.

Back-of-envelope estimate for a large music service (assumed figures)
QuantityAssumptionResult
Catalog100 million tracks, about 3.5 minutes (210 s) eachthe base for storage
Encodings per trackthree bitrates: 96, 160 and 320 kbps576 kbps x 210 s, about 15 MB per track for all three
Audio storage100 million x 15 MBabout 1.5 PB before replication
Peak streams20 million concurrent at an average of 160 kbpsabout 3.2 Tbps of audio, nearly all served by the CDN
Play events200 million daily listeners x 15 plays3 billion events a day, about 35,000 a second on average
Back-of-envelope estimate for a large music service (assumed figures). Scroll sideways on a small screen.

Two lessons: storage is large but simple, because files never change; and the event stream is the busiest write path in the whole system, far busier than playlist edits.

3. Define the API

GET  /v1/tracks/{id}                 -> 200 { title, artists, album, durationMs, explicit }
GET  /v1/tracks/{id}/playback        -> 200 { manifestUrl, licenseToken?, expiresAt }
GET  /v1/search?q=...&type=track,artist,album&limit=20
POST /v1/playlists                    { name } -> 201 { playlistId }
POST /v1/playlists/{id}/items         { trackIds[], position, expectedVersion } -> 200 { version }
POST /v1/events/plays                 [{ eventId, trackId, startedAt, msPlayed, offline }] -> 202
The player asks for a manifest, then fetches chunks from CDN URLs; the API never streams audio itself.

Two details are worth calling out. The playback call returns a signed, short-lived manifest URL, so CDN links cannot be shared forever. Play events carry a client-generated eventId and are accepted in batches, because a phone that was offline for a flight will upload a day of listens at once.

4. Sketch the data model

Metadata in databases, bytes in object storage
DataStoreNotes
Tracks, albums, artists, rights by countryRelational database, read replicas plus cacheSmall (well under a terabyte), read constantly, written by the ingestion pipeline
Audio chunksObject storage, fronted by the CDNPath like audio/{trackId}/{bitrate}/{chunk}, immutable, never overwritten
PlaylistsWide-column or document store keyed by playlist IDOrdered list of track IDs plus a version number; huge playlists split into pages
Play eventsDurable log (Kafka-style), then a data warehouseAppend only; raw events kept for audits and disputes
Search indexInverted index serviceBuilt from the catalog, with popularity as a ranking signal
Metadata in databases, bytes in object storage. Scroll sideways on a small screen.

5. Get audio to the listener fast and cheaply

This is the heart of the design. Each track is transcoded once at ingestion into the bitrate ladder and cut into short chunks of a few seconds each. A small manifest lists the chunks for each bitrate.

  1. TapThe app calls the playback endpoint and gets a signed manifest URL. If the track is in the local cache, it starts playing from disk immediately.
  2. First chunkThe player fetches the first chunk at a modest bitrate from the nearest CDN edge. A lower first bitrate is a deliberate trick: it arrives sooner, so sound starts sooner.
  3. AdaptAs the buffer fills, the player measures throughput and steps up to a higher bitrate for later chunks, or down when the train enters a tunnel.
  4. PrefetchNear the end of a track, the player fetches the start of the next one in the queue, so there is no silence between songs.

Popularity is extremely skewed: a small set of current hits gets a large share of plays, while most of the catalog is rarely heard. That shape is ideal for a CDN. Edges keep the hits; a regional or shield cache keeps the middle; object storage serves the cold tail on a miss. The Netflix walk-through covers pre-positioning large video files on edge servers; audio files are much smaller, so plain pull-through caching with long TTLs works well here.

Offline downloads

Downloaded files are stored encrypted on the device. The key comes in a license tied to the account and device with an expiry date, and the app must reconnect within that period to renew it. If the subscription lapses, renewal fails and the files stay unplayable. Cap the number of devices holding downloads per account so one subscription cannot feed many people.

6. The architecture

  1. Clients
    • Mobile, desktop, web and car players
    • Local audio cache
  2. Edge
    • CDN edges for audio
    • API gateway
  3. Services
    • Catalog
    • Search
    • Playlists
    • Playback manifests and licenses
  4. Storage
    • Catalog DB and cache
    • Playlist store
    • Object storage (audio)
  5. Events
    • Event ingestion
    • Durable log
    • Stream counts
    • Warehouse and royalty batch
Metadata, audio and event paths of a music streaming service. Mobile, desktop and web players call an API gateway for metadata, search, playlists and playback manifests. Catalog, playlist and search services sit behind it with their own stores and a shared cache. Audio chunks are fetched directly from CDN edges, which pull from object storage on a miss. Players send batches of play events to an ingestion service that writes them to a durable log; stream processors produce near-real-time counts and a nightly batch job produces royalty reports in the warehouse.

Search is its own service with an inverted index over titles, artists and albums, plus prefix suggestions as the user types. The search autocomplete walk-through covers that typeahead part in detail.

7. Count every play exactly once

Payouts depend on play counts, so this path needs the care of a billing system. A play usually only counts after a minimum amount of listening that the business defines, so the client reports how many milliseconds were played and the server decides whether it qualifies.

  • Durable first. The ingestion service writes each batch to the log before answering 202. If the write fails, the client keeps the batch and retries later.
  • Deduplicate by event ID. Retries and offline uploads produce repeats. A stream processor keeps recently seen eventIds for a window and drops duplicates; the nightly batch job deduplicates again over the full day.
  • Two speeds of truth. Fast counts for the artist dashboard come from the stream and may be slightly off. Royalty reports come from the batch job over raw events and are the numbers that pay people.
  • Fraud checks. Flag accounts that play the same track on loop around the clock or from many devices at once, and exclude them before reports go out.

8. What breaks, and what you do about it

Failure modes worth naming
FailureEffectMitigation
A new album dropsMillions request the same new files at once, all cache missesPre-warm the CDN with the new tracks before release time; request collapsing at the shield
A CDN provider has an outage in a regionPlayback fails thereMulti-CDN: the playback service hands out URLs from a second provider when error rates rise
Event ingestion is downPlay events pile up on phonesClients buffer and retry with backoff; the log is replicated; nothing is counted twice thanks to event IDs
Rights change for a countryA track must stop playing thereRights checked at the playback call, not baked into cached files; short-lived signed URLs expire on their own
Playlist edited on two devicesOne edit overwrites the otherVersion number on each write; a conflicting write gets 409 and the client merges and retries
Failure modes worth naming. Scroll sideways on a small screen.

9. Trade-offs to discuss

  • Chunked or whole-file delivery. Whole files are simpler and cache well, but chunks allow faster starts, mid-song quality changes and cheaper seeking.
  • Number of bitrates. Each extra step costs storage and transcoding; too few steps make quality jumps noticeable on shaky networks.
  • Real-time or batch counting. Stream processing gives fresh numbers; batch over raw events gives auditable ones. Use both and say which one pays.
  • Strong or eventual consistency for playlists. A collaborative playlist needs ordering and conflict handling; a personal library can tolerate a short delay across devices.
  • One CDN or several. Multiple providers improve resilience and bargaining power but add routing logic and log merging.

10. How to talk through it in the interview

Fictional example

A deep dive on start-up time
Interviewer
Users say the first song takes too long to start. What would you look at?
Candidate
I would break the delay into parts: the playback API call, DNS and TLS to the CDN, the first chunk download, and decoder start. The cheapest wins are fetching the first chunk at a lower bitrate, keeping warm connections to the CDN, and returning the manifest URL in the same response as the track metadata.
Interviewer
And if the track is not cached at the edge?
Candidate
Then the miss goes to a regional shield before object storage. For the long tail I accept a slower first play, and I would measure start time by popularity bucket so a slow tail does not hide inside a good average.
  • Separate the three paths (metadata, audio bytes, events) on the board and say which one is the expensive one.
  • When royalties come up, say "at least once delivery plus deduplication" and explain where the dedupe happens.
  • Do not wander into recommendations unless invited. Mention it as a separate system that reads the play events.

Practicing this design with Natively

A good rehearsal for this prompt is a timed mock where the other person keeps changing the focus: start-up time, then royalties, then offline files. Natively listens on your computer during that call, writes a running transcript of both voices, and can offer a few talking points when a new question lands. If you have sketched the three paths on paper or a whiteboard tool, a screenshot lets it describe what your diagram shows and what it leaves out. Review the notes afterwards and check whether you ever explained how a play becomes a payout.

Questions people ask

How would you design Spotify in a system design interview?

Split it into three paths: metadata and search served by ordinary services with caches, audio bytes served as small encoded chunks from a CDN, and play events collected through a durable log for counts and royalties. Then go deep on start-up time or on counting plays exactly once, whichever the interviewer prefers.

How does a music app start playing a song so quickly?

It fetches a short manifest, then the first few seconds of audio at a modest bitrate from a nearby CDN edge, and starts playing while later chunks load. Warm connections, a local cache of recent tracks and prefetching the next song in the queue remove most of the remaining delay.

How are play counts kept accurate for royalties?

Clients send play events with a unique event ID and the time listened. The server writes them to a replicated log before acknowledging, drops duplicates by event ID, and a daily batch job over the raw events produces the counts used for payouts, after fraud filtering.

How do offline downloads work in a streaming service?

The app stores encrypted audio on the device and keeps a license that holds the key and an expiry date. The app has to come online before the license expires to renew it, so downloads stop playing if the subscription ends or the device is removed from the account.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP