← Create New Paste

System Design Interview: A Music Streaming Service Like Spotify

3 views
"Design a music streaming service" covers large-scale media delivery, catalog search, personalized playlists, and licensing constraints. Here is a structured way to approach it in an interview. 1. Requirements Functional: users search a catalog of tens of millions of tracks, stream songs with minimal startup delay, create and share playlists, and get recommendations. Optional: offline downloads, lyrics, podcasts. Non-functional: playback should start in under about 200 ms, skipping between tracks should feel instant, the system must handle hundreds of millions of users with peaks in the evening, and licensing rules (some tracks are not available in some countries) must be enforced. 2. Rough numbers A 3.5-minute track at 160 kbps is about 4 MB. If 50 million users each stream 2 hours a day, that is a huge volume of egress, so a content delivery network is essential. Storing 80 million tracks in several bitrates (96, 160, 320 kbps) is in the petabyte range, which fits object storage well. 3. High-level architecture - Clients (mobile, desktop, web) talk to an API gateway. - Catalog service: metadata about tracks, albums, and artists in a relational store or wide-column store, with a search index (Elasticsearch-style) for typeahead. - Playback service: checks the user's subscription and the track's regional rights, then returns a short-lived signed URL to the audio file on the CDN. - Audio storage: encoded files in object storage, replicated to CDN edges. Popular tracks stay cached at the edge; long-tail tracks are fetched from origin on demand. - Playlist service: playlists are lists of track IDs with owner and collaborator info; store them in a key-value store keyed by playlist ID. - Event pipeline: every play, skip, and like is sent to a streaming platform like Kafka. 4. Fast playback Explain chunking: audio is split into small segments so playback starts after downloading the first few seconds. The client prefetches the next track in the queue so skipping is instant. Adaptive bitrate lowers quality on weak connections. 5. Recommendations Batch jobs process listening events to build collaborative-filtering models and audio embeddings, producing personalized playlists that refresh weekly. A real-time layer adjusts "up next" suggestions based on recent skips. Store precomputed results so reads are cheap. 6. Royalties and analytics Play counts drive royalty payments, so the event pipeline must be durable and deduplicated, with a counted play defined by a minimum listen time. This is a good place to discuss exactly-once processing versus idempotent aggregation. 7. Offline mode and DRM Downloaded tracks are encrypted, with keys tied to the device and a periodic license check online. 8. Trade-offs to mention CDN cost versus origin load, the freshness of recommendations versus compute cost, and consistency of collaborative playlists (last-write-wins versus operation-based merging). Staying structured in the round System design interviews reward clear structure. Linkjob AI (https://linkjob.ai) provides real-time help during live job interviews and technical interviews, reminding you of areas such as capacity estimates or failure handling you have not covered yet, while you lead the design discussion.
Created Nov 17, 2026 15:58 Expires Nov 17, 2027 15:58