Spotify
Music streaming with hyper-personalized Discover Weekly algorithms
Spotify Architecture Blueprint
Click ▶ RUN to animate active particle streams across microservices
How Traffic Flows Through Spotify
1. Ingress & Edge Routing
User requests arrive at the edge network. Global CDNs cache static assets and media. API Gateways terminate TLS, validate JWT authentication tokens, enforce token-bucket rate limits, and scrub malicious bot traffic before forwarding to internal services.
2. Microservice Processing
Stateless domain services execute core business logic. Microservices communicate via high-performance internal gRPC/REST APIs and autoscaling worker pods, ensuring that high load on one domain never exhausts compute resources of another.
3. In-Memory Caching & Storage
Read-heavy traffic is served from in-memory Redis clusters with sub-millisecond latencies, protecting primary databases. Persistent databases (PostgreSQL, Cassandra, DynamoDB) maintain ACID consistency for financial ledgers, user accounts, and immutable state records.
4. Asynchronous Event Streams
Heavy operations (notifications, audit logging, analytics, ML training, fan-out delivery) are decoupled into durable event logs like Kafka and SQS. This prevents user-facing requests from blocking on slow external networks.
Study Spotify's database schemas, capacity math & production contracts
Beyond the visual blueprint, explore the exhaustive 7-section engineering whitepaper with real DDL schemas, API endpoints, failure mitigation matrices, and 45-minute FAANG interview scripts.
Instant Audio Playback (<50ms) & Discover Weekly ML Pipeline
If a user presses Play and hears silence for 500 milliseconds, the app feels broken and slow. Furthermore, recommending music cannot rely only on popularity, or indie artists would never be heard.
Spotify client apps dynamically pre-fetch the opening 10-second compressed chunk of the next predicted song into local RAM before the current track finishes. For recommendations, Spotify combines collaborative filtering on billions of playlists with deep convolutional neural networks that analyze raw audio waveforms directly.
⚖️ Architectural Trade-Offs & Decisions
Why the engineering team chose this specific stack over competing alternatives
OGG Vorbis provides superior audio quality at lower bitrates compared to legacy MP3. 160kbps OGG matches the acoustic quality of 320kbps MP3, cutting mobile bandwidth consumption and CDN transit costs in half while sounding crystal clear.
Computing latent factor vectors across 600M users × 100M tracks involves immense matrix math that would melt real-time web servers. Running massive distributed Spark batch jobs on Sunday nights pre-computes recommendations ready for listeners on Monday morning.
The Expired TLS Certificate Outage (2020)
Spotify desktop and mobile apps across Europe and North America failed to play music for over an hour, displaying "Spotify is offline" errors.
An internal TLS certificate securing traffic between edge API gateways and core backend microservices expired without automated renewal.
Automated certificate lifecycle management was deployed via Let's Encrypt / internal vault with alerts firing 30 days prior to expiration, and automated canary certificate rotations were added.
📋 Complete Microservice Specifications
Every service in the Spotify ecosystem with production tech stacks and failure impact
| Component | Tier / Layer | Tech Stack | Production Function | Status / Chaos |
|---|---|---|---|---|
| Listener App | CLIENT | iOSAndroidDesktop | iOS, Android, Desktop, and Car web clients streaming audio and managing playlists | |
| API Gateway | GATEWAY | JavaEnvoyOAuth2 | Gateway for user authentication, subscription verification, and API routing | |
| Track Catalog Service | SERVICE | JavaCassandra | Manages 100M+ tracks, artist metadata, album artwork, and search indexes | |
| Discover Weekly ML Engine | SERVICE | PythonApache SparkTensorFlow | Machine learning recommendation pipeline combining matrix factorization and NLP | |
| Audio Stream Gateway | SERVICE | GoC++OGG Vorbis | Manages audio chunk requests, licensing keys, and adaptive bitrate selection | |
| Edge Audio CDN | CDN | AkamaiCloudflare | Global edge CDN caching compressed audio chunks close to listeners | |
| Audio File Vault | STORAGE | Google Cloud Storage | Petabyte object store retaining lossless FLAC masters and compressed OGG chunks | |
| Playlist Service | SERVICE | JavaPostgreSQL | Manages collaborative user playlists, liked songs, and folder hierarchies | |
| Cassandra History DB | DATABASE | Apache Cassandra | Distributed database storing listening history checkpoints and stream telemetry | |
| Play Events Kafka Bus | QUEUE | Apache Kafka | Real-time event stream logging 30-second play counts for royalty payouts and analytics |