How Spotify recommendations work
Spotify's recommendation engine combines collaborative filtering (matrix factorization on listening history), NLP on playlist metadata, and audio analysis. Learn how Discover Weekly and Daily Mixes are generated at scale.
The Problem Statement
Interviewer: "Every Monday morning, Spotify drops a personalized 30-track playlist called Discover Weekly on each of its 600M+ users. Most users say it feels like magic. Walk me through the architecture that generates these recommendations at scale, from the raw signals to the final playlist."
This question tests three things: whether you understand the signal sources that power recommendations (listening history, metadata, audio features), how collaborative filtering works at scale using matrix factorization, and whether you can reason about the batch pipeline that produces personalized outputs for hundreds of millions of users on a weekly schedule.
Most candidates say "they track what you listen to and recommend similar stuff." That is correct at a 30,000-foot level and completely insufficient for an interview. The strong answer explains the three signal sources, how they complement each other's blind spots, the candidate generation and ranking pipeline, and the diversity injection that prevents the playlist from feeling monotonous.
I have seen variants of this question at Spotify, Netflix, YouTube, TikTok, and Amazon. The collaborative filtering + content features + ranking pipeline pattern is universal across recommendation systems.
Clarifying the Scenario
You: "Great question. Before I answer, let me clarify a few things to scope this properly."
You: "When you say 'recommendations,' should I focus on Discover Weekly specifically, or also cover Daily Mixes, Release Radar, and the home page recommendations?"
Interviewer: "Focus on Discover Weekly as the primary example, but explain it in a way that generalizes to other recommendation surfaces."
You: "Got it. Should I go deep on the ML models themselves (loss functions, training procedures), or focus on the system architecture that runs them at scale?"
Interviewer: "I want to understand both, but lean toward the architecture. I want to see how this runs for 600M users every Monday."
You: "And should I cover cold start (new users, new tracks) and real-time signals, or stay focused on the batch pipeline?"
Interviewer: "Cover cold start. It is one of the hardest problems."
You: "OK. I will structure my answer in four parts: the three signal sources Spotify uses to understand music and listeners, how collaborative filtering generates candidates at scale using matrix factorization, how audio analysis and NLP solve the cold start problem, and how the Discover Weekly pipeline combines everything into a personalized playlist with diversity constraints."
Scoping like this takes 30 seconds but completely changes how the interviewer perceives your answer. They hear structure, they hear domain knowledge, and they know you will not ramble.
My Approach
I break this into five parts:
- Three signal sources: Spotify combines collaborative filtering (what similar users listen to), NLP on playlist metadata (what the internet says about music), and audio analysis (what the music actually sounds like). No single source is sufficient alone.
- Collaborative filtering via matrix factorization: The core engine. Decompose the user-track interaction matrix into user vectors and track vectors using Alternating Least Squares (ALS). Users and tracks that are "close" in this latent space are a good match.
- Audio analysis for cold start: New tracks with zero listening history have no collaborative filtering signal. Convolutional neural networks extract acoustic features from the raw audio waveform, placing new tracks in the same latent space as established ones.
- NLP on playlists and metadata: Spotify crawls playlist titles, descriptions, blog posts, and music reviews. Natural language processing extracts semantic associations between artists and tracks, providing a cultural context signal that pure audio analysis misses.
- The Discover Weekly pipeline: A batch job that runs weekly for every user. It generates candidates from all three sources, ranks them, injects diversity, filters out tracks the user has already heard, and delivers a 30-track playlist by Monday morning.
The magic of Spotify's recommendations is not any single technique. It is the combination. Collaborative filtering finds tracks that similar users love but you have not heard. Audio analysis catches new releases that sound like your taste. NLP connects culturally related artists even when their audio signatures differ.
Here is a quick overview of what each signal source contributes:
| Signal Source | Strength | Blind Spot |
|---|---|---|
| Collaborative filtering | Finds tracks loved by listeners with similar taste | Cannot recommend brand-new tracks (no listening data) |
| NLP (playlist/blog text) | Captures cultural associations and genre relationships | Fails for instrumental, non-English, or niche music |
| Audio analysis (CNNs) | Works for any track regardless of popularity | Ignores cultural context (a sad song for a breakup playlist) |
The Architecture
Here is how the system works end to end:
-
Signal collection is continuous. Every stream, skip, save, repeat, and playlist addition is logged as an event. Spotify processes billions of these events daily. Playlist metadata (titles like "chill vibes for studying" or "summer road trip bangers") is crawled and indexed. Audio features are extracted once per track when it is first ingested.
-
Model training happens offline on a schedule. The collaborative filtering model (ALS) is retrained weekly on the full user-track interaction matrix. NLP embeddings are updated as new playlists accumulate. Audio CNNs are retrained less frequently (the acoustic features of a song do not change, only the training data grows).
-
Vectors are stored in an embedding store. Each user gets a 128-dimensional vector representing their taste. Each track gets a 128-dimensional vector representing its "personality" in the same latent space. These vectors are the lingua franca that enables comparison across signal sources.
-
Candidate generation uses approximate nearest neighbor search. For each user, the pipeline queries the ANN index to find the 1,000 tracks whose vectors are closest to the user's vector. This is a sub-second operation per user using algorithms like HNSW (Hierarchical Navigable Small World) or Annoy. At 600M users, this step still requires massive parallelism.
-
Ranking scores the candidates. A supervised model (gradient-boosted decision tree or deep neural network) predicts the probability that the user will listen to each candidate for more than 30 seconds. Features include the vector distance, genre match, artist familiarity, release recency, and time-of-day patterns.
-
Diversity injection prevents monoculture. Without diversity constraints, the playlist would be 30 very similar tracks. The diversity layer enforces rules: no more than 3 tracks from the same artist, at least 4 different genres, tempo variation across the playlist, and a mix of familiar-adjacent and exploratory picks.
-
Filtering removes already-heard tracks and respects user settings. The final 30 tracks are committed to the playlist and delivered to the user's library at midnight Monday UTC.
Discover Weekly serves 600M+ personalized playlists every Monday. At 30 tracks per playlist, that is 18 billion track selections per week. The pipeline must complete within a weekend's worth of batch compute, which is why ANN search plus simple ranking models dominate over expensive per-query inference.
Collaborative Filtering at Scale
Collaborative filtering is the backbone of Spotify's recommendations. The core idea is simple: if you and another user share 80% of your listening history, you will probably enjoy the 20% they listen to that you have not heard yet.
Think of it like a bookstore where the staff keeps notes on every customer's purchases. When you walk in, they check which other customers have similar buying patterns and recommend the books those customers bought that you have not. The more customers and purchases the store tracks, the better the recommendations get.
The challenge is scale. The user-track interaction matrix has 600M rows (users) times 100M+ columns (tracks). That is 60 quadrillion cells. But it is incredibly sparse: each user has interacted with maybe 5,000-50,000 tracks, which is less than 0.05% of the catalog. Matrix factorization compresses this enormous sparse matrix into dense, manageable vectors.
How ALS (Alternating Least Squares) works:
The algorithm decomposes the interaction matrix $R$ into two matrices: $U$ (users, shape $m \times k$) and $T$ (tracks, shape $n \times k$), where $k$ is the latent dimension (128). The goal is to minimize:
$$\sum_{(u,i) \in \text{observed}} c_{ui} \cdot (r_{ui} - \mathbf{u}_u^T \mathbf{t}_i)^2 + \lambda(|\mathbf{u}_u|^2 + |\mathbf{t}_i|^2)$$
Where $c_{ui}$ is a confidence weight (more streams = higher confidence), $r_{ui}$ is the implicit feedback (1 if interacted, 0 otherwise), and $\lambda$ is the regularization term.
The "alternating" part: fix the track vectors and solve for optimal user vectors (a least squares problem per user). Then fix user vectors and solve for optimal track vectors. Repeat for 15-25 iterations. Each iteration is embarrassingly parallel because each user's (or track's) vector can be computed independently.
The implicit feedback distinction matters. Unlike Netflix ratings (explicit 1-5 stars), Spotify has only implicit signals: you either streamed a track or you did not. But the absence of a stream does not mean dislike. Maybe you just have not heard it yet. This is why the confidence weight $c_{ui}$ is crucial: 50 streams of a track means strong positive signal, while 0 streams is ambiguous (not necessarily negative).
Continue Reading with Premium
Unlock this article and every other in-depth system design guide on the platform with NotesFromSDE Premium.