Design a recommender

Candidate generation → ranking → re-ranking, embeddings vs collaborative filtering, cold start, offline (NDCG) vs online (CTR) metrics. The most-asked ML design question.

About 21 min read3-question knowledge check

The mental model

A recommender is a two-stage funnel: a cheap net, then an expensive scale. You cannot score ten million items with a heavy model for every user in 100 ms, so you do not try. First a candidate generation stage casts a cheap, wide net to pull ~500 plausible items from millions. Then a ranking stage runs an expensive, precise model over just those 500 to order them. Finally a re-ranking stage applies business rules and diversity so the top of the list is not ten near-identical videos. The whole architecture exists to resolve one tension: relevance wants an expensive model, latency forbids running it on everything, so you shrink the set before you spend the compute.

The reason this is the single most-asked ML design question is that it forces every core tradeoff into one problem: recall vs precision (the funnel), offline vs online metrics (NDCG in a notebook vs CTR in the world), cold start (a new user or item with no history), and feedback loops (the model trains on clicks it caused). A candidate who jumps straight to "train a deep model on user-item interactions" has missed the point — the design is the funnel, and the model is a component inside stage two.

The load-bearing insight interviewers reward: your training labels are biased by the system that generated them. Users can only click what you showed them, and they click the top of the list more regardless of relevance (position bias). So a recommender trained naively on its own logs learns to recommend what it already recommended — a feedback loop that looks like improvement offline and stagnates online. Every serious design has an answer for how it breaks that loop.

The full lesson continues with 15 more sections
  • Deep dive — a full worked design
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision
Design a recommender — AI/ML lesson · PrepAtlas Tech