Data & analytics
Recommendation engine - retrieve a thousand, rank twenty
Why the feed is computed in a hundred milliseconds by a model that is a day out of date.
The first act plays here. Owned once with credits, never a subscription.
What this board gets wrong on purpose
The tension
THE OFFLINE EVALUATION AND THE ONLINE RESULT ARE MEASURING DIFFERENT SYSTEMS AND THE BOARD DOES NOT FIX IT. Training features come from a warehouse query; serving features come from a key-value store filled by a stream, written by different people in a different language - so a model that scored better offline routinely does nothing or does harm online, and the usual gap is a few percent of feature values, which is enough. The second unresolved thing is the FEEDBACK LOOP: the model is trained on clicks that the previous model chose to show, so an item that was never shown can never be learned from, and popularity compounds into a monoculture that every offline metric will happily call an improvement. And cold start has no good answer here - a new item falls back to trending, which is exactly the signal that buries new items, so the system is structurally biased against the content it most needs to evaluate.
Practise this as an interview
Take Recommendation engine - retrieve a thousand, rank twenty as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
"Design a recommendation feed" is the standard question for ML-adjacent system design because it cannot be answered with one model or one database. Ten million items cannot be scored inside a 100 ms request, so the answer is always a funnel - cheap recall, expensive ranking, rules on top - fed by a training loop that runs on a clock measured in hours. Interviewers use it to see whether you size the funnel from the latency budget and whether you know where these systems actually fail in production: training/serving skew and a feedback loop that trains on its own output.
What you will learn
- Why the work is split into retrieval (10,000,000 -> 1,000 in about 5 ms) and ranking (1,000 -> 20 in about 25 ms): scoring the whole catalogue with the ranker would take 250 seconds.
- How to build a 100 ms p95 budget line by line - candidate sources in parallel, 400,000 feature values in 8 batched reads, ranking, blending - and where the tail goes.
- Why at least three independent candidate sources (ANN, co-visitation, trending) make a failure degrade quality instead of emptying the feed.
- Why eligibility rules (blocked, region-locked, already bought) belong before the model, and editorial overrides after it.
- Why features must be logged as served, how training/serving skew silently invalidates offline wins, and how the nightly loop turns clicks into the next model.
How to read this board
- Press Play and follow the walkthrough left to right across the diagram: THE REQUEST (100 ms, starting now), RETRIEVE, RANK, then BLEND.
- Then THE LOOP on the right - the nineteen-hour path from a logged impression back to a promoted model.
- 1 · Requirements - what is being optimised, and what must never be recommended.
- 2 · Capacity estimation - the latency budget is the real capacity constraint - then 3 · Storage estimation.
- 4 · Availability - why the feed must never be empty and what every failure degrades to.
- 5 · How it works, then 6 · Deployment plan.
- Finally the DATA MODEL at the bottom, then argue with what the board leaves unresolved on purpose: offline and online computing the same feature twice, a model trained on what the last model chose to show, and a cold start that falls back to the signal that buries new items.
1 · Requirements
Ask these before drawing anything
- What is being optimised, in one sentence, and who agreed to it? Clicks, watch time, purchases and long-term retention give four different systems, and optimising the easy one usually damages the important one.
- How big is the catalogue and how fast does it change? Ten thousand items that change monthly needs none of this. Ten million that change hourly needs all of it, and the difference is entirely in candidate generation.
- How fresh must a recommendation be? If a purchase must change the next page, that is a session-level requirement and needs real-time features. If tomorrow is fine, the whole right-hand side of this board can be a nightly batch and cost a tenth as much.
- What must NEVER be recommended? Age-restricted, region-locked, out of stock, already bought, blocked by the viewer. These are correctness rules and they belong before the model, not inside it.
- Is there an editorial or commercial override? There always is eventually, and building it in from the start is much cheaper than retrofitting a rules engine around a model.
- How will this be evaluated? If the answer is offline AUC only, the system will ship regressions confidently. If there is no experiment framework, there is no recommendation system - only a model.
Functional
- Return 30 ranked items for any viewer within 100 ms at p95, including a viewer seen for the first time.
- Retrieve candidates from at least three independent sources so that the failure of one degrades quality rather than emptying the feed.
- Exclude what the viewer has already seen in this session and what they have interacted with recently, unless the item type says otherwise.
- Log every impression with its position, the model version that produced it and the feature values used - without this the training data is unusable and every experiment is unattributable.
- Retrain nightly and promote a model only after an offline evaluation and a shadow run on real traffic.
- Support holding a percentage of traffic on the previous model, sticky per viewer, for as long as an experiment runs.
Non-functional
- p95 end-to-end 100 ms, p99 150 ms. Past that the app shows a fallback, because a slow feed is worse than a generic one.
- The feed must never be empty. Every failure mode degrades to trending, and trending is served from a cache that is refreshed independently of everything else on this board.
- Feature skew between offline and online computation must be measured continuously and kept under 1 percent per feature. Unmeasured skew is the default state and it silently invalidates every offline result.
- Model rollback must take under one minute and must not require a deploy.
- No viewer-level data crosses a region boundary on the serving path.
Out of scope
- Search. A query is an explicit intent and deserves a different retrieval path, even though it shares this index.
- Ads. The auction has a different objective and a hard budget constraint, and mixing the two objectives into one score is how both get worse.
- Explanations. Worth having, and honest ones are much harder than they look once the ranker is a gradient-boosted ensemble of four hundred features.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages, a 9-step narrated walkthrough and a 5-table schema — is the board itself, and it opens in Tierslate.
- 5written pages
- 9walkthrough steps
- 5tables41 columns
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan