Recommender Systems
A textbook for people preparing for an interview who would rather not memorise definitions. Formulas are derived here, numbers are computed, and every technique is examined not only for how it works but for where it breaks.
- Everything is checked. Every number is computed by a script from this same repository or verified against the source it describes. The maths inside the widgets is reproduced independently in Python — agreement to 1e-9.
- Widgets, not pictures. Twenty-six interactive demonstrations where you move a parameter and watch what happens to the metric. These are not illustrations: there are real computations inside.
- A living system, read closely. A separate part reads the open-sourced code of a real feed — along the request path, with the actual weights from its configs.
What it is made of
Nineteen chapters along the request path. Each part answers its own question, and inside a part every chapter builds on the one before it. You can read straight through or take a single section — the «what to take away» and «one-screen cheat sheet» boxes exist for exactly that.
Part I · Statement and measurement
Where any system starts: what it actually optimises, where the data comes from and why measuring quality is harder than getting it.
Chapter 1
The problem and the funnel
Almost the entire design follows from two facts: demand is extremely uneven, and there are tens of milliseconds to answer in. Personalisation, cold start and multi-stage architecture all come from there.
Chapter 2
Data and biases
The system learns not from preferences but from logs filtered by a previous version of itself. Four consequences, and the catalogue of biases you are always asked about.
Chapter 3
Metrics
Candidate generation and ranking have different jobs, so they have different metrics: recall against order. Plus the fine points people get caught on — recall at a fixed K, AUC without calibration, averaging over queries.
Chapter 4
Validation and experiment
A metric is easy to compute and hard to trust. A random split inflates quality, offline drifts systematically from online, and the habit of peeking turns five percent of false positives into twenty.
Part II · Candidate generation
How to pull a hundred candidates out of millions in milliseconds without losing the right ones on the way.
Chapter 5
Collaborative filtering
The first approach that worked, and still the basis of half the candidate generators in production. The whole construction rests on the choice of similarity measure — and that choice changes the output more than most architectural decisions.
Chapter 6
Matrix factorisation
The same collaborative signal, but generalised by compression into a few coordinates: factorisation sees connections where neighbours see emptiness, and breaks where neighbours work.
Chapter 7
Two-tower models
A ranking loss that is excellent at the second stage is fatal for a candidate generator — and the reason is not model quality but a degenerate task. Hence softmax over the catalogue and three engineering corrections.
Chapter 8
Encoding objects
A free embedding table is the most powerful model of an object, and this whole chapter is about how nearly impossible that power is to use. There is one way out: make the rare inherit knowledge from the frequent.
Chapter 9
ANN and semantic IDs
The vectors are trained — now they have to be searched. Why exact search does not fit the budget, how HNSW is built and which knob in it trades recall for speed.
Part III · Ranking
A hundred candidates are in hand — now they have to be ordered: what to train the model on, what to feed it, and how to serve several goals at once.
Chapter 10
Learning to rank
«Which loss to take» looks like a choice from a catalogue; in fact it is a choice of what exactly you declare to be the truth — relevance, the observed order, or the structure of the shown list.
Chapter 11
Features
Here the feature space itself dictates the architecture. Why boosting loses exactly here, how an embedding layer works from the inside, and what is done to real-valued features before they reach the network.
Chapter 12
Feature interactions
A story in six steps where each one repairs the breakage of the previous — from cross features to DCN-v2. And the central claim of the chapter: an MLP does not learn a product on its own.
Chapter 13
Multi-task and distillation
There is more than one goal, the data is biased by display position, and the best model does not fit the budget. Three stories about the gap between what a model is trained for and what it is used for.
Part IV · Sequences and the slate
User history as an input and the slate as a whole: what to show together, and what to show for the first time.
Chapter 14
Transformers over history
A variable-length sequence has to be folded into a vector. What averaging loses, why attention should depend on the candidate, and why production ends up with two loops instead of one model.
Chapter 15
Re-ranking
An item's value depends on what stands next to it, so «pick the best k» and «assemble the best list» are different problems. The second is harder, and is solved greedily but not blindly.
Chapter 16
Exploration and bandits
The model learns from what the previous model showed, so a good item that was never shown stays unknown. How to break the loop, and why a stochastic slate is needed for more than exploration alone.
Part V · Engineering
What everything above stands on: where features come from at request time, and how the system behaves under load.
Chapter 17
Data and logging
The layer that papers do not show and that breaks more deployments than the choice of architecture does. Why the offline metric can be excellent while the online one is not.
Chapter 18
Runtime
Where to cut the services, where to put the filters, what to cache and what to show when half the stack is unavailable. A system should degrade predictably rather than die heroically.
Part VI · System design
Everything above assembled into one procedure — the one you answer the system-design question with.
Every chapter ends with interview questions and full answers; all of them are
collected on the review page. The
numbers in the boxes are computed by a script in _tools/, and you can
run it yourself.
Reading the open-sourced code of a real feed
The open-sourced «For You» feed at X
X released the source of its main feed: 2028 files in Rust, Python, Scala and Java. Eleven chapters read the system along the request path: real action weights from the code, derivations, diagrams and four widgets on the actual numbers. Every number is verified against the sources automatically. The theory explains why it is done this way; here you see what it looks like when written in earnest.
Глава x00
Обзор
Что именно выложили, чем две дорожки ленты отличаются друг от друга и как устроен репозиторий на 2028 файлов.
Глава x01
Пайплайн
Путь запроса по стадиям: что происходит между нажатием на вкладку и готовым списком постов.
Глава x02
Источники
Откуда берутся кандидаты: несколько независимых источников разной природы и квоты, которыми их смешивают.
Глава x03
Retrieval
Двухбашенная модель в рабочем виде: как в коде устроены башни и чем там оказываются semantic IDs.
Глава x04
Ранжирование
Ранжирующий трансформер и приём, ради которого он так устроен: кандидаты изолированы друг от друга внутри батча.
Глава x05
Скоринг
Реальные веса действий из конфигов, поправки к ним и то, как из отдельных вероятностей собирается один скор.
Глава x06
Фильтры
Двадцать девять фильтров, их порядок — и что этот порядок говорит о стоимости каждого.
Глава x07
Видимость
Разметка контента, правила видимости и репутация автора: слой, который решает не «что выше», а «показывать ли вообще».
Глава x08
Блендинг
Как в ленту подмешивают рекламу и не-посты и какими долями это управляется.
Глава x09
Конфигурация
Параметры, вынесенные в конфиги, и что по ним видно об устройстве экспериментов.
Глава x10
Чему учит
Что этот код говорит о теории из первой части — и пять мест, где он с ней расходится.
The X code is distributed under Apache 2.0. Every quoted fragment names its file and commit; the reading around it is ours.
What to use along the way
Sixteen problem types with answer checking and a worked solution: precision, recall, MRR, MAP, NDCG, AUC, the confusion matrix, smoothed CTR, IPS, the Bloom filter. Per-type statistics push you towards your weak spots. → open
Every interview question in one place: cards, «known / repeat» marks, filtering by chapter, a random question. → open
The full list of interactive demonstrations, with a note on what each one shows, is in the widget catalogue.