Full answer
Requirements
Functional:
- Personalised rows on the home page ("Continue learning", "Recommended for you", "Because you watched Python basics").
- Similar items on a course page.
- React within minutes to what the user just did.
Non-functional:
- Server latency under about 200 ms at p99 for a recommendation call.
- High availability with graceful fallback to popular items.
- Measurable: every change is A/B tested on engagement and completion, not just clicks.
Capacity estimates
Assumptions: 100M users, 50M DAU; 10M items (courses, lessons, videos); 2B recommendation requests per day (several surfaces per session); 50 interaction events per active user per day at 200 bytes each; 256-dimensional float32 embeddings; 500 candidates ranked per request; peak factor 2.
- Requests: 2B / 86,400 = about 23,000 per second; about 46,000 at peak.
- Ranking load: 23,000 x 500 = 11.5M scored items per second on average; 23M at peak. This sets the size of the ranking fleet and is why the ranking model must be cheap or batched on accelerators.
- Embeddings: items 10M x 256 x 4 B = 10.24 GB; users 100M x 256 x 4 B = 102.4 GB. Item embeddings fit in memory for an approximate nearest neighbour (ANN) index on each candidate server.
- Events: 50M x 50 x 200 B = 500 GB per day into the log.
API
GET /v1/recommendations?user_id=77&surface=home&limit=20&context=mobile
200 {"items": [{"item_id": "c-310", "reason": "because_you_watched", "score": 0.82}],
"request_id": "r-5a1", "model_version": "rank-2026-12-01"}
POST /v1/events {"user_id": 77, "item_id": "v-88", "type": "completed", "ts": "..."}
request_id links later clicks back to what was shown, which training needs.
Data model
- Interaction log (Kafka, then a data lake): user, item, event type, timestamp, surface, request ID.
- Feature store: offline tables for training, plus an online key-value store for serving (user: recent topics, skill level, language; item: popularity, completion rate, freshness; cross features).
- Item catalogue: metadata, topics, difficulty, language, availability.
- Model registry: versioned models and embedding tables.
High-level design
flowchart LR
APP[App] --> RS[Recommendation service]
RS --> CG1[ANN over item embeddings]
RS --> CG2[Co-view / co-enrol lists]
RS --> CG3[Popular in segment]
RS --> FS[(Online feature store)]
RS --> RK[Ranking model servers]
RS --> RR[Re-rank: diversity, rules]
APP --> EV[Event API] --> K[Kafka]
K --> STR[Stream features] --> FS
K --> DL[(Data lake)] --> TR[Daily training] --> MR[(Model registry)]
MR --> RK
MR --> CG1Request path
- Candidate generation (about 30 ms budget): look up the user's embedding (or compute it from recent activity), query the ANN index for the nearest few hundred items, add co-viewed items for the last few things watched, add popular items for the user's language and level. Deduplicate; remove items already completed.
- Ranking (about 50 ms): fetch features in one batched call, score all candidates with a model that predicts, for example, probability of starting and completing.
- Re-ranking (about 10 ms): enforce diversity (not ten Python videos), freshness, and rules (do not recommend paid content to users in regions where it is unavailable).
- Log what was shown with the request ID.
Cold start
New users: use onboarding choices, language and device to choose segment-popular items, then adapt quickly from first clicks via streaming features. New items: use content embeddings from title, description and transcript, and give them controlled exploration traffic.
Bottlenecks and trade-offs
- Ranking cost grows with candidates x requests; reduce candidates, distil the model, or precompute recommendations for less active users in a nightly batch and serve from a cache.
- Freshness vs stability: streaming features react within minutes; full retraining daily keeps models stable. Real-time retraining adds complexity for modest gains in most products.
- Feedback loops: recommending only what is already popular hides new content; reserve a share of slots for exploration.
- Fallbacks: if the ranking service times out, return candidate-stage results or precomputed popular lists rather than an error.
- Metrics: optimise for long-term value (course completion, return visits), since pure click-through optimisation tends to favour clickbait titles.
By level
Fresher: Explain recommending items based on what similar users watched, and the idea of first finding candidates then sorting them. A fresher can describe the funnel from many items to a short list.
Mid: Design candidate generation, feature store and ranking with latency budgets, estimate load and embedding size, and handle cold start. Expect latency budgets per stage.
Senior: Cover training-serving skew, feedback loops and exploration, model rollout and A/B testing, cost of ranking at scale, fallbacks and long-term metric choice. The senior answer explains how impressions are logged for unbiased training.
Key points
- Multi-stage: candidate generation, ranking, re-ranking
- Several candidate sources including ANN over embeddings and co-occurrence
- Online feature store for serving, offline tables for training
- Ranking load = requests x candidates, about 11.5M scores per second here
- Handle cold start, feedback loops and fallbacks explicitly
Common mistakes
- Scoring the entire catalogue for every request
- Ignoring cold start for new users and items
- Not logging impressions with a request ID, so training data is biased
- Optimising only for clicks
Follow-ups
- How would you evaluate a new ranking model offline and online?
- How would you make recommendations react to a video the user finished a minute ago?
- How would you avoid recommending content the user cannot access?
Tips
- Draw the funnel with candidate counts at each stage
- Give latency budgets per stage
- Mention cold start and exploration unprompted
Evaluation rubric
- Requirements include latency, fallback and measurement
- Capacity math for requests, ranking load and embeddings
- Multi-stage architecture with offline and online parts
- Trade-offs on cost, freshness, feedback loops and metrics