Candidate generation and the ranking funnel
A recommendation pipeline that narrows a huge catalog in stages: cheap retrieval nominates thousands of candidates, heavier models score fewer of them, and rules set the final order. The design question is where each stage runs and what it costs.
What it is
A ranking funnel splits one unaffordable question (which of millions of items should this person see right now?) into stages that each handle a smaller set with a more expensive model. Google's recommendation course describes three: candidate generation, which cuts a corpus of billions down to hundreds or thousands and has to answer fast because of that size; scoring, where a more precise model ranks the survivors to pick roughly ten; and re-ranking, which applies constraints to the final list. The published YouTube paper follows the same split, with one deep model for candidate generation and a separate one for ranking.
Candidate generation is usually several sources, not one model. Each source nominates a few hundred items it expects the heavier stages to rate highly: a trending list, items similar to what the user interacted with recently, a set generated offline from long-term interests. A learned source worth knowing is a two-tower network: one tower turns the user into a vector, the other turns an item into a vector, and training pulls the pair together when there was engagement. Because the towers are independent after training, item vectors can be computed by a daily job and loaded into an approximate nearest-neighbor index such as FAISS or HNSW. At request time the user tower runs once on fresh features and the index returns the closest items without scanning the catalog. The price is that a two-tower model gives up features that describe the user-item pair, since those depend on both sides and would break the caching.
Ranking often has two stages of its own. Instagram Explore runs a lightweight first-stage ranker over thousands of candidates and a heavy second-stage model over the best hundred. The light model is trained to predict whether the heavy model would place an item in its top K, which makes it a distilled stand-in rather than a separate opinion. The heavy model predicts several engagement probabilities (click, like, see less) and combines them with tuned weights into one score. It is also the stage where pair features become affordable: with a hundred or so items left, the model can take in features about this user's interactions with this item.
Re-ranking adjusts the scored list with rules the models don't learn well: remove items the user explicitly disliked, that a separate classifier flags as click-bait or that fail integrity checks; avoid showing the same author twice in a row; and transform scores as a function of item age so fresher content moves up. Freshness also reaches back into the models. Google's course suggests retraining often with a warm start, adding an item's age as a feature, and using several candidate generators so the results don't all cluster around one near-duplicate theme.
| Work | When it runs | Where the result lives |
|---|---|---|
Item embeddings | Offline, on a daily pipeline | The nearest-neighbor index |
Pre-generated candidate sets (locally popular items) | Offline, in off-peak hours | A pre-generated source the request reads |
Fully precomputed recommendations for some users | Off-peak, so the heavy model isn't needed at peak | A store keyed by user |
User embedding, nearest-neighbor lookup, both rankers | Per request, from the freshest user features | The response to that request |
When to use it
Reach for a funnel when scoring the whole catalog with your best model would blow the latency or compute budget. Instagram's engineers put it plainly: with unlimited compute and no latency requirement you could rank all content, and the multi-stage design exists because you have neither. The same post notes that most large recommenders combine several candidate sources, so a funnel is also the natural fit when you want to blend signals of different kinds (recent actions, long-term interests, what is trending nearby) without one model having to express all of them.
It also fits when freshness and responsiveness matter. A nightly batch can't react to what the user did a minute ago, but a funnel can: the user embedding is built per request from current features, and some retrieval sources are real-time and capture the most recent interactions. Offline work is reserved for what changes slowly (item vectors, popularity lists), and per-request work for what changes fast.
When not to
Skip the retrieval stage when the set is already defined. A "continue watching" row, a creator's own posts in date order or a list of items the user saved needs sorting, not nomination; a generator would add latency and could drop items the user expects to find. The same goes for anything the product promises to be complete, such as a filtered search over a category: approximate nearest-neighbor retrieval may miss items, which is acceptable for a suggestion and not for a result count.
Don't add a light-ranking stage until the candidate count forces it. In the Explore design above, the heavy model handles about a hundred items per request; if your sources together produce a few hundred candidates, the heavy model can score them directly and you avoid training and maintaining a second model that has to stay aligned with the first. And with a catalog in the low thousands and a cheap scoring model, a single stage over the whole catalog, or scores precomputed offline, can be simpler than any funnel.
Compared
| Option | What runs per request | Pick it when | What you give up |
|---|---|---|---|
One model over the whole catalog | The scorer, once per item | The catalog is small, the model is cheap, or the scores are computed offline | Cost grows with the catalog; no room for a heavier model |
Retrieve, then rank | A nearest-neighbor lookup, then the heavy model on hundreds | The corpus is millions of items and the response has a tight latency budget | Items no source nominates don't reach the ranker |
Retrieve, light rank, heavy rank | Adds a cacheable light model that trims thousands to about a hundred | Several sources produce thousands of candidates the heavy model can't afford | A second model to train and keep in step with the heavy one |
Precomputed pages | A read from a store filled off-peak | Peak load exceeds what the rankers can serve, or for users who rarely return | The page can't reflect the last few minutes of activity |