Streaming Audio Backend: Catalog Lookup, Shared Lists, Remote Control
System DesignModel answerLast updated
Design a backend for a streaming audio app covering searchable catalog, concurrently edited playlists, and ordered cross-device playback control at 50M MAU scale.
Design a Streaming Audio Backend
You are designing the backend for an audio streaming product with about 50 million monthly active users. The service is global, and users often change networks (Wi-Fi to cellular, for example) while listening. The product has three core capabilities.
Capabilities
1. Catalog lookup
- Users search by artist name, album name, or track title.
- The catalog holds tens of millions of tracks.
- When metadata changes, search results should reflect it quickly.
2. Shared and personal playlists
- Users create playlists, modify them, and reorder tracks.
- Several people may edit the same playlist at once, so concurrent edits must stay consistent.
3. Remote playback control
- A user may control playback from one device (a phone) while audio plays on another (a smart speaker).
- Commands such as play, pause, skip, and seek must be synchronized across devices.
- Commands can arrive late or out of order, and latency matters: aim for under 200 ms.
What to cover
- Storage strategy. How do you store the rarely-changing catalog versus the frequently mutated playlist data? What distinguishes the two access patterns?
- Playback API. Define the interface for playback commands. How do you cope with a "play" that arrives after a later "pause" because of network jitter?
- Concurrency. How do you prevent lost updates when two users reorder the same playlist at the same moment?
- Service boundaries and isolation. How do you split the system so a spike in search traffic cannot degrade playback?
Give back-of-the-envelope numbers where they help justify your choices, and discuss trade-offs.
Hints
Hint 1
Start by naming three workloads with different needs: search (read-heavy, eventually consistent), playlists (mutable user data needing correctness), and playback state (small, ordered, latency-critical).
Hint 2
For command ordering, think about a single owner per listening session that assigns a monotonically increasing version, plus a per-device sequence number so stale commands can be discarded and retries made idempotent.
Hint 3
For playlist reordering, avoid index-based positions. Consider stable entry IDs, fractional position keys so a move touches one row, and optimistic concurrency with a version check on write.
Hint 4
For isolation, give each workload its own service, datastore, and capacity, and put per-route rate limits at the edge. Persistent connections for playback should not share resources with search.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
Treat this as three systems with different consistency and latency needs behind one product. Saying this early drives the rest of the design:
- Search: read-heavy, eventually consistent.
- Playlists: mutable user data that must stay correct under concurrent edits.
- Playback control: a small, strictly ordered, latency-critical state machine.
Scale estimates
- 50M MAU, roughly 20M DAU, about 5M peak concurrent listening sessions.
- Catalog: 50M tracks at about 2 KB each is roughly 100 GB. This is small, so the challenge is query volume, not storage.
- Search: 20M DAU x 5 searches is about 100M/day, around 1.2K QPS average and 5K peak. Typeahead can multiply this by about 10, so plan for roughly 50K QPS on the suggestion path.
- Playlists: about 1B playlists averaging 50 entries gives roughly 50B rows. Writes are a few thousand per second; reads are far higher and cache well.
- Playback: 5M sessions x about 1 command per minute is roughly 80K commands/s, each fanned out to the user's other devices within 200 ms.
1. Data model
Catalog (read-mostly).
- Source of truth: a relational or key-value store with
track,artist, andalbumrecords (id, title, artist ids, album id, duration, region availability, version). - Search index: Elasticsearch/OpenSearch with denormalized documents (artist and album names inlined), analyzers for prefix, fuzzy, and transliteration matching, and popularity as a ranking signal.
- Freshness: change data capture from the source of truth into a log (Kafka), consumed by an indexer that upserts into the index. With a refresh interval near 1 s, metadata changes show up within a few seconds.
- Caching: metadata and artwork are cacheable at a CDN and in Redis.
Playlists (mutable, per-user).
playlist(id, owner_id, title, collaborative, version, updated_at)playlist_entry(playlist_id, entry_id, track_id, position_key, added_by, added_at), partitioned byplaylist_id.position_keyis a fractional index (LexoRank-style string). Moving a track rewrites one row instead of shifting N. Inserting between "a" and "b" yields something like "an". Rebalance keys in the background occasionally.- Access is by key, so DynamoDB or sharded Postgres both work. Require conditional writes.
| Catalog | Playlists | |
|---|---|---|
| Reads | Full-text, fan-out queries | Key lookups |
| Freshness | Eventual is fine | Read-your-writes required |
| Writes | Controlled ingestion | Arbitrary user edits |
2. Playback API and ordering
Model playback as a session owned by exactly one Playback State Service partition, sharded by user_id.
State = { session_id, version, active_device_id, track_id, queue_ref,
status, position_ms, position_ts_server, shuffle, repeat }
POST /v1/sessions/{sid}/commands
{ command_id, device_id, device_seq, expected_version?,
type: PLAY|PAUSE|SKIP|SEEK|TRANSFER, args }
-> 200 {state} | 409 {current_state}
GET /v1/sessions/{sid}
WS /v1/sessions/{sid}/stream -> pushes {state, version}
Handling out-of-order commands:
- Single serializer. One leader per session assigns a monotonically increasing
version; server order is the logical order. - Per-device sequence numbers. Each device increments
device_seq. The server drops any command withdevice_seqless than or equal to the last one seen from that device. If PLAY (seq 7) is overtaken by PAUSE (seq 8), the late PLAY is discarded. expected_versionfor intent-sensitive commands such as "skip from track X" or relative seeks. If state has moved on, return 409 and let the client re-render. A plain pause can apply unconditionally.- Idempotency.
command_idmakes retries after a network switch safe. - Absolute state in events. Pushes carry
position_msplus a server timestamp so devices extrapolate position locally, and devices ignore events whose version is not newer than what they hold.
Vector clocks are only needed with multiple writers per object. A single owner per session plus device sequence numbers is simpler and sufficient.
Latency. Devices hold persistent WebSocket/MQTT connections to regional edge gateways. The session is homed in the user's nearest region. A command costs one hop to the leader, an in-memory apply, and a push. State is replicated to Redis or a log so a replacement leader can take over within seconds. On reconnect, a device fetches current state and resumes the stream.
3. Concurrent playlist reorders
Use optimistic concurrency control:
- The client reads the playlist at
version = 42. - It sends
MOVE entry_id=E after entry_id=P, expected_version=42. - The server does a conditional write that updates E's
position_keyand setsversion = 43only ifversion = 42. - The losing writer gets a 409 with the latest state and either rebases automatically or prompts the user.
Because moves reference stable entry_ids rather than indexes, most concurrent edits rebase cleanly. Two moves of the same entry resolve to the last committed one. Avoid pessimistic locks: edits are short and conflicts rare, so locks add latency for little gain. For heavily collaborative playlists, CRDT-style ordered lists are an option, at the cost of complexity.
4. Service boundaries and isolation
Clients -> Edge / API Gateway (per-route rate limits)
|- Search Service -> OpenSearch (+ query cache)
|- Catalog Service -> Catalog DB + Redis/CDN
|- Playlist Service -> Playlist DB -> events
|- Connection Gateway -> Playback State Service -> session store
Isolation techniques:
- Separate services, clusters, and autoscaling groups per workload. Search never shares compute or datastores with playback.
- Per-route rate limits and load shedding at the edge; typeahead is debounced client-side and heavily cached.
- Bulkheads and timeouts so a slow search dependency cannot exhaust shared thread or connection pools.
- Playback gateways keep long-lived connections on dedicated capacity.
- Degrade gracefully: if search is down, playback and existing playlists still work.
Trade-offs and common mistakes
- Using a single database for everything, which couples workloads with opposite needs.
- Index-based playlist positions, which cause O(N) rewrites and brittle merges.
- Relying on client timestamps for ordering; clocks drift, so use server-assigned versions.
- Skipping idempotency, so retries after a network switch double-apply commands.
- Making playback state multi-master across regions, which introduces needless conflict resolution. Home each session in one region and fail over.
- Ignoring the cost of the search path: typeahead dominates QPS, so cache and rate-limit it.