Design Spotify Mobile: Offline Music, Downloads, and Streaming

“Design Spotify mobile” is a layered question. The basic streaming case is straightforward — fetch a manifest, download audio, play. The hard parts are offline downloads (with DRM), gapless playback across tracks, Spotify Connect handoff to other devices, and keeping a 100K-track library searchable on a phone.

Functional requirements

  • Stream music on Wi-Fi and cellular
  • Download playlists and albums for offline listening
  • Search across 100M+ tracks instantly
  • Sync playback state across devices (Spotify Connect)
  • Show recommendations, recently played, and queue

Architecture

Three core modules: player, library, sync.

Streaming

Each track has a manifest pointing to chunks at multiple bitrates (96k, 160k, 320k Ogg Vorbis or AAC). Player fetches first ~10 seconds, starts playback, prefetches the rest while playing.

For the next track in the queue, prefetch starts ~30 seconds before the current track ends. This enables gapless playback.

Offline downloads

The user toggles “Available offline” on a playlist. The download manager queues the tracks with priority, fetches them on Wi-Fi (or cellular if user opts in), and stores encrypted blobs locally.

DRM: tracks are downloaded encrypted with a per-device key. Subscription validation happens at playback time — the local player calls a license server to decrypt. If the user goes offline for too long (typically 30 days) without a re-validation, downloads expire.

Library

The user’s library (saved tracks, playlists, albums) is fully synced to local SQLite. This enables instant search across the user’s collection. Global track search is server-side.

Spotify Connect

Phone discovers other Spotify-enabled devices via mDNS or via the Spotify backend. State (current track, position, queue) is held server-side; any device can take control. The phone becomes a remote — it tells the server “play track X on speaker Y.”

Battery and data

  • Adaptive bitrate based on network — start at 160k, upgrade to 320k if Wi-Fi
  • Pause prefetch when battery is below 15%
  • Background audio uses iOS/Android audio sessions; minimal CPU overhead

Frequently Asked Questions

How does gapless playback work?

The player crossfades or seamlessly hands off between two prefetched tracks. The decoder for the next track is warmed up before the current one finishes, and audio buffers are stitched without a gap.

What format does Spotify use?

Ogg Vorbis historically; AAC and Opus increasingly. Premium tier offers higher-quality streams. Format selection is per-device based on hardware decoder support.

How is search so fast?

Global search uses an inverted index served from a search cluster (Elasticsearch-style). Personal library search is local SQLite FTS. Combined results are merged client-side.

Scroll to Top