System design interview: design a recommendation system
A recommendation system picks, for each user and moment, a short list of items they are likely to want from a catalog far too large to score in full. The standard design is a funnel: cheap candidate generation narrows millions of items to about a thousand, a heavier model ranks those, and a final pass applies diversity and business rules. The interview tests whether you can explain that funnel, the data that feeds it, and how you would know a change made things better.
By Evin JohnPublished 7 min read
1. Clarify the requirements
Ask what is being recommended and where. Videos on a home screen, products under a product page and songs in an autoplay queue share the funnel but differ in signals, freshness and what counts as success.
- Functional: a personalized home feed; "more like this" under an item; recommendations update as the user interacts in a session; hide items the user dismissed or already bought.
- Non-functional: a feed request returns in roughly 100 to 200 ms; new items become recommendable within hours; new users get reasonable results from the first visit; the system keeps serving (with simpler results) if a model service fails.
- Define success: agree on the main metric (watch time, purchases, long-term retention) and guardrails (complaints, diversity, latency). This choice shapes the training labels.
2. Estimate the scale
| Quantity | Assumption | Result |
|---|---|---|
| Users | 100 million daily active | the base for the lines below |
| Feed requests | 20 per user a day | 2 billion a day, about 23,000 a second on average |
| Catalog | 10 million items | far too many to score per request |
| Ranking work | 1,000 candidates per request | about 23 million item scores a second |
| Item embeddings | 10 million x 256 floats x 4 bytes | about 10 GB, fits in memory on retrieval servers |
| User embeddings | 100 million x 256 x 4 bytes | about 100 GB, kept in a key-value store |
The 23 million scores a second is what forces the funnel. A heavy model can afford a thousand items per request; it cannot afford ten million. The method behind figures like these is in capacity estimation.
3. Define the API
GET /v1/feed?surface=home&cursor=...&context=mobile -> 200 { items: [{ itemId, reason, requestId }], nextCursor }
GET /v1/items/{id}/similar?limit=20 -> 200 { items[] }
POST /v1/events [{ requestId, itemId, type: impression|click|watch|purchase|dismiss, value, ts }] -> 202The requestId returned with each feed is logged with every later event, so training data can join what was shown with what happened, including items that were shown and ignored.
4. Sketch the data model
| Data | Store | Use |
|---|---|---|
| Interaction events | Durable log, then a data lake partitioned by day | Training labels and features; impressions as well as clicks |
| Item metadata | Catalog database | Category, creator, price, age, availability, content embeddings |
| Features | Feature store: offline tables plus an online key-value store | Per user (recent categories, activity), per item (click rate last 24 h), per pair |
| Embeddings | Item vectors in an approximate nearest neighbor (ANN) index; user vectors in a key-value store | Candidate retrieval |
| Served lists | Log of what was shown per request | Debugging, training and offline replay |
5. Candidate generation: from millions to a thousand
Several cheap sources each propose a few hundred items, and their union becomes the candidate set. Mixing sources keeps results relevant even when one source is weak.
| Source | How it works | Strength |
|---|---|---|
| Two-tower embeddings | One network maps users to vectors, another maps items; retrieve the items nearest to the user vector with an ANN index (HNSW or similar) | Personal and fast; covers the whole catalog |
| Item-to-item | Items often consumed together with what the user just viewed (co-occurrence) | Strong for "more like this" and in-session |
| Follows and subscriptions | New items from creators, artists or shops the user follows | Explicit intent |
| Popular and trending | Top items by region and category in the last hours | Cold start and freshness |
| Fresh items | A small reserved slice of new uploads | Gives new items a chance to collect signals |
Exact nearest neighbor search over ten million vectors per request is too slow, so ANN indexes trade a little recall for a large speed-up. Rebuild or update the index as new items arrive, and filter unavailable items after retrieval.
6. Ranking and re-ranking
- Fetch featuresFor each of the thousand candidates, fetch item features and user-item features from the online feature store in one batched call.
- ScoreA ranking model (gradient-boosted trees or a neural network) predicts the probability of each outcome you care about: click, long watch, purchase, dismiss. Combine them into one score with weights that reflect the business goal.
- Re-rankApply rules the model does not know: remove already-purchased items, limit items per creator, mix categories, insert a few fresh items, respect policy filters.
- LogRecord the final list, scores and features used, keyed by request ID, so the next model trains on exactly what served.
request ............................................ 150 ms budget
load user vector + recent history ................ 10 ms
candidate sources in parallel (ANN, co-views, ...) 30 ms -> ~1,000 items
batch feature fetch .............................. 20 ms
ranking model on 1,000 items ..................... 40 ms -> scored list
re-rank: filters, diversity, fresh slots ......... 5 ms -> top 50
network and margin ............................... 45 ms7. The architecture
- Clients
- Apps and web
- Event logging
- Online
- Recommendation service
- Candidate sources (ANN, co-views, trending)
- Model server
- Re-ranker
- Features
- Online feature store
- Stream feature jobs
- Offline
- Event log and data lake
- Training pipelines
- Embedding builds
- Release
- Model registry and validation
- Experiment assignment
8. Hard parts worth raising
- Cold start. New users get popular and regional items plus a short interest picker; their vector updates after a few interactions. New items get content-based embeddings (from text, images or audio) and a reserved exploration slot until they collect signals.
- Training-serving skew. If "clicks in the last 24 hours" is computed one way in the training pipeline and another way in serving, the model sees different inputs live than it learned from. Define features once in a feature store and log served features.
- Feedback loops and position bias. Items shown at the top get clicked more because they were at the top. Log positions, correct for them in training, and keep some exploration so the model can learn about items it rarely shows.
- Fallbacks. If the model server times out, return a cached or popularity-based list rather than an error. A plain feed is better than an empty one.
- Evaluation. Offline metrics (recall at k, NDCG) screen candidates, but only an online A/B test on the agreed metric decides. Roll out through a feature flag service so the share of traffic per variant is controlled and reversible.
9. What breaks, and trade-offs to discuss
| Failure | Effect | Mitigation |
|---|---|---|
| Bad model version shipped | Engagement drops for everyone | Shadow-score and canary new models; automatic rollback on guardrail metrics |
| Feature store lag | Recommendations ignore the last hour of behavior | Monitor freshness per feature; fall back to session history from the request |
| ANN index stale | New items never appear | Incremental updates plus a fresh-items source that bypasses the index |
| Popular item goes out of stock | Users see things they cannot buy | Availability filter at re-rank time, reading current stock |
- Precompute or compute per request. Nightly lists per user are cheap and fast to serve but ignore what the user just did; per-request scoring reacts to the session at a higher cost. Many systems blend a precomputed base with live re-ranking.
- One model or several. Separate models per surface fit each better but multiply training and monitoring work.
- Short-term clicks or long-term value. Optimizing for clicks can promote clickbait; weighting completions or return visits aligns better with satisfaction.
- Relevance or diversity. A list of near-identical items scores well per item but feels repetitive; re-ranking for variety costs a little predicted relevance.
10. How to talk through it in the interview
Fictional example
- Interviewer
- A new user signs up. What do they see?
- Candidate
- First, popular items in their region and language, plus a quick picker of a few interests. As soon as they interact, item-to-item candidates from what they touched start to dominate, and after a few dozen events their user vector from the two-tower model is good enough to drive retrieval.
- Interviewer
- And a brand-new item nobody has seen?
- Candidate
- It gets an embedding from its content, so retrieval can find it for users who like similar items, and a small exploration slot shows it to some users so it can collect clicks quickly.
- Draw the funnel and the offline loop as two separate pictures.
- Put a number on each funnel stage, using your estimate.
- Mention how you would measure success before the interviewer asks.
Recommendations also power personal sections in other prompts, such as the "for you" area of a news aggregator, and query understanding overlaps with a search engine, where ranking takes a query instead of a user as input.
Practicing this design with Natively
This prompt mixes infrastructure and machine learning, and interviewers often pull you toward whichever side you know less. Practice with a partner who switches between the two. Natively, running on your computer during the call, writes a live transcript of both voices and can offer talking points for the current question when you press the shortcut, for example position bias or training-serving skew. Ask it for a diagram of the funnel to check your structure. The saved notes show which follow-ups you answered with a mechanism and which with a buzzword.
Questions people ask
How do you design a recommendation system in an interview?
Describe a funnel. Several cheap candidate sources, such as embedding search, co-viewed items and trending items, narrow millions of items to about a thousand. A ranking model scores those with fresh features, and a re-ranking step applies diversity and business rules. An offline loop trains models from logged impressions and interactions.
What is candidate generation in a recommender system?
It is the first, cheap stage that picks a few hundred to a few thousand plausible items out of the whole catalog. Common sources are nearest-neighbor search over user and item embeddings, items often consumed together, new items from followed creators, and popular items in the user's region.
How do you handle cold start for new users and new items?
New users start with popular and regional items plus a short interest picker, and their profile updates after a few interactions. New items get embeddings from their content so retrieval can find them, plus a small exploration slot that shows them to some users until they gather signals.
How do you know a new recommendation model is better?
Offline metrics such as recall at k or NDCG on held-out data screen candidates, but the decision comes from an online A/B test on the agreed business metric with guardrails such as complaints and latency. Roll the new model out to a small share of traffic first and roll back automatically if guardrails slip.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
