Design a Music Streaming App
viaLeetCode
Problem Low-level design of a Spotify-like music streaming app: model the core domain, playback, and the supporting service concerns.
Requirements
- Entities: User, Artist, Album, Song, Playlist (user-owned, collaborative), Library (saved items), PlaybackSession.
- Operations: search catalog, play/pause/skip/seek, build and share playlists, queue management, listening history, recommendations hook.
Core design
- Domain classes: Song(id, artist, album, duration, audio ref), Playlist as an ordered collection of song refs (position-indexed), User with Library and subscription tier; PlaybackSession(currentSong, position, queue, state) with a state machine (playing/paused/buffering).
- Services behind interfaces: CatalogService (search/browse), PlaybackService (issues stream URLs, tracks progress), PlaylistService, HistoryService feeding RecommendationService (observer/event pattern on play events).
- Playback path: client requests a song → service authorizes (tier, region) → returns a CDN/signed URL for chunked/adaptive streaming; player buffers ahead.
Discussion points
- Caching strategy: hot songs at CDN edge, catalog metadata in Redis, playlist reads cached with invalidation on edit.
- Scalability seams: read-heavy catalog vs write-heavy play-event stream (queue events, aggregate async).
- Design patterns to justify: strategy (audio quality selection), observer (history/recs), factory (media source), composite (playlist folders).
- Offline/downloads, gapless playback, and collaborative-playlist conflicts as extension probes.
asked …