Products›🎵 Music›Spotify
🎵

Spotify

Music streaming with hyper-personalized Discover Weekly algorithms

99.9%
SLA
10
SERVICES
10
NODES
REQ/SEC0
LATENCY0ms
ERROR RATE0%
CACHE HIT95%
ACTIVE CONNS0
QUEUE DEPTH0

Spotify Architecture Blueprint

Click ▶ RUN to animate active particle streams across microservices

client
gateway
service
database
cache
queue
cdn
storage
SYSTEM ARCHITECTURE WALKTHROUGH

How Traffic Flows Through Spotify

EDGE TIER01

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.

Listener AppAPI GatewayEdge Audio CDN
APPLICATION TIER02

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.

Track Catalog ServiceDiscover Weekly ML EngineAudio Stream GatewayPlaylist Service
DATA TIER03

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.

Audio File VaultCassandra History DB
MESSAGING TIER04

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.

Play Events Kafka Bus
📖 SYSTEM DESIGN WHITE PAPERS & LOW-LEVEL SPECIFICATIONS

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.

🏆 #1 HARDEST SYSTEM CHALLENGE

Instant Audio Playback (<50ms) & Discover Weekly ML Pipeline

⚠️The Engineering Bottleneck

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.

💡The Winning Architectural Solution

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.

SCALE & PRODUCTION METRICS:Sub-40ms playback start, 600M personalized playlists generated weekly, zero gap between tracks.

⚖️ Architectural Trade-Offs & Decisions

Why the engineering team chose this specific stack over competing alternatives

Why OGG Vorbis instead of MP3 for audio streaming?
CHOSEN:✓ OGG Vorbisvs MP3, AAC, FLAC (lossless)

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.

Why Apache Spark batch matrix factorization instead of real-time recommendation updates?
CHOSEN:✓ Apache Spark Weekly Batch Pipelinevs Real-time SQL joins, Graph queries on demand

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.

🚨 REAL-WORLD POST-MORTEM

The Expired TLS Certificate Outage (2020)

The Incident

Spotify desktop and mobile apps across Europe and North America failed to play music for over an hour, displaying "Spotify is offline" errors.

Root Cause Analysis

An internal TLS certificate securing traffic between edge API gateways and core backend microservices expired without automated renewal.

How They Re-Architected It

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

ComponentTier / LayerTech StackProduction FunctionStatus / Chaos
Listener AppCLIENT
iOSAndroidDesktop
iOS, Android, Desktop, and Car web clients streaming audio and managing playlists
API GatewayGATEWAY
JavaEnvoyOAuth2
Gateway for user authentication, subscription verification, and API routing
Track Catalog ServiceSERVICE
JavaCassandra
Manages 100M+ tracks, artist metadata, album artwork, and search indexes
Discover Weekly ML EngineSERVICE
PythonApache SparkTensorFlow
Machine learning recommendation pipeline combining matrix factorization and NLP
Audio Stream GatewaySERVICE
GoC++OGG Vorbis
Manages audio chunk requests, licensing keys, and adaptive bitrate selection
Edge Audio CDNCDN
AkamaiCloudflare
Global edge CDN caching compressed audio chunks close to listeners
Audio File VaultSTORAGE
Google Cloud Storage
Petabyte object store retaining lossless FLAC masters and compressed OGG chunks
Playlist ServiceSERVICE
JavaPostgreSQL
Manages collaborative user playlists, liked songs, and folder hierarchies
Cassandra History DBDATABASE
Apache Cassandra
Distributed database storing listening history checkpoints and stream telemetry
Play Events Kafka BusQUEUE
Apache Kafka
Real-time event stream logging 30-second play counts for royalty payouts and analytics