ML SYSTEM DESIGN (DEEP DIVES) ยท INTERVIEW QUESTION
Design a YouTube-scale video recommendation system serving billions of users.
๐ด advanced ยท End-to-End System Design
Hint: Two-stage funnel: candidate generation -> ranking. Discuss latency budget, multi-task ranking, calibration, and feedback loops.
Answer
1. Problem Formulation
Start by interrogating the problem instead of jumping to models. "Design YouTube recommendations" actually spans three different surfaces (home feed, up-next, search) with very different objectives. Pick one: assume we're designing the home feed for logged-in mobile users.
Clarifying questions to ask aloud:
- Scale? ~2B DAU, ~500 hours uploaded per minute, ~50 recommendations per session, p99 end-to-end under 200 ms.
- Objective? Not "maximize clicks" โ clickbait wins that game. The real business goal is long-term user satisfaction, proxied by valued watch time (watch time discounted by skips, dislikes, "not interested") plus explicit positives (likes, shares, subscriptions).
- Personalization vs cold-start? Both. ~10% of sessions are new-user or new-video, so we can't rely purely on collaborative signals.
- Constraints? Fairness across creators, no amplification of borderline content, kids-content rules, regional law, bandwidth on low-end devices.
Why this is an ML problem: the candidate space is ~10โน videos and user preferences are non-stationary. Heuristics (popularity, recency) work as a baseline but cap out because they ignore the long tail where most engagement actually lives.
ML framing: learning-to-rank on top of retrieval. Model it as multi-task: predict P(click), P(watch โฅ 30s), P(like), P(dislike), P(share) per (user, video, context) triple.
2. Metrics
The trap is conflating offline and online metrics.
Offline (what we measure during training):
- Retrieval quality: Recall@1000 against held-out "next videos actually watched". Recall over precision because the ranker fixes precision downstream.
- Ranking quality: NDCG@10 weighted by watch-time, plus calibration (predicted CTR should match empirical CTR in each decile โ uncalibrated rankers break downstream bidding/exploration).
Online (what we move in A/B tests):
- North star: valued watch-time per DAU.
- Engagement: like rate, share rate, sessions per week.
- Guardrails: "not interested" rate, reported content rate, first-30-second abandonment (clickbait proxy), creator-side diversity (Gini coefficient of impressions).
The trade-off: a model that boosts NDCG offline can tank online by over-fitting to historical clicks (which were themselves shaped by the old ranker โ feedback loop). Always pair NDCG with a diversity metric and run A/Bs โฅ2 weeks to capture habituation.
This is the opening of a longer walkthrough. Read the full answer in the topic explorer, free.
Likely follow-up: How would you handle catastrophic forgetting when retraining the ranker daily?
Related questions
- Design a production RAG system for an enterprise knowledge assistant (10TB docs, 50k employees, ACL-aware).
- Design a real-time payment fraud detection system (10k+ TPS, 100ms decision budget, delayed labels).
- Design X (Twitter) home timeline ranking โ including in-network and out-of-network candidate sources.
- Design an ads CTR prediction and auction system for a major web property (100k QPS, 50ms budget).
- Design a visual search system (Pinterest-style) over 5B+ images with sub-500ms p95 latency.