Design YouTube Video Recommendations
On this page
Problem Description
In this interview, we're going to design the recommendations on a video site's home page, similar to the YouTube home page or the TikTok For You feed. Creators upload videos all day, and the library holds far more videos than anyone could browse. When a viewer opens the app, the system picks videos from the whole library that this viewer will enjoy watching, puts the best ones first, and shows more as they scroll. Videos they've already watched or marked "not interested" stay out. Viewers click, watch for a while, like, dislike or skip the videos they're shown, and the system keeps learning from what they do. You can use an existing building block: a video service that stores every video with its title, channel, category and length, and knows which channels each viewer subscribes to. This interview is about choosing and ordering videos, not about storing or streaming them.
Out of Scope
- The "Up next" list beside a playing video – it starts from the video being watched rather than from the viewer; a good follow-up question.
- Search results – another product with its own ranking.
- Ads – placed by the ads system in slots we leave for it.
- Uploading, storing, encoding and streaming videos – the video service already does this.
- Removing videos that break the rules – a separate review system; removed videos never reach us.
Good Clarifying Questions
- How many viewers and videos are there? – About 500 million daily viewers who open the home page about 6 times a day. About 800 million videos can be recommended, and about 2 million new ones are uploaded every day.
- What does "enjoy" mean for the business? – Time spent watching videos viewers are glad they watched, so they come back. Clicks on a misleading thumbnail followed by leaving at once don't count, and dislikes and "not interested" count against.
- How fast must the home page load? – Within 200 ms at p99, of which about 80 ms can go to the models. Later pages, as the viewer scrolls, within 150 ms.
- How fresh must it be? – A new video should be able to reach viewers within an hour of upload, not only its channel's subscribers. What a viewer just watched should shape their next home page. The model should be retrained at least daily.
- What if recommendations fail? – The home page must still show videos, even if they're less personal; an empty page or an error is not acceptable.
Requirements
Functional Requirements
- Show a Home Page of Videos – When a viewer opens the app, the home page shows videos from the whole library that they'll enjoy, best first, and more as they scroll; videos they've watched or marked "not interested" stay out.
- Record What Viewers Do – The system records which videos each viewer was shown and where, and what they did: click, minutes watched, like, dislike or "not interested".
- Keep Learning – The system trains a new model from these records at least daily and gives it to viewers only after it proves at least as good as the current one.
Non-Functional Requirements
- Scale – 500M daily viewers × 6 opens = 3B home pages a day: about 35K/s on average, 100K/s at peak, each choosing from about 800M videos.
- Latency – Home page under 200 ms at p99, with about 80 ms for the models; later pages under 150 ms.
- Freshness – A new video can be recommended within 1 hour of upload; what a viewer just watched shapes their next home page; a new model at least daily.
- Availability – 99.9%. If the models or the feature store are down, the home page still shows popular videos for the viewer's country and language; never an error.
Problem Framing
ML objective – The business goal is that viewers spend their time on videos they're glad they watched, and come back. The model takes one (viewer, video) pair at the moment of the request and predicts four things: the probability of a click, the minutes watched if clicked, the probability of a like, and the probability of a dislike or "not interested". The home page is sorted by one value score, the expected minutes of satisfied watching: the click probability times (the minutes plus a bonus for a likely like), minus a penalty for a likely dislike (for example 5 minutes × like probability as the bonus and 10 minutes × dislike probability as the penalty). Predicting the bad reactions too is what keeps a misleading thumbnail from winning on clicks alone.
Label – Each label comes from the viewer's own actions on a video they were shown, taken from the app's events within 24 hours: a click (with at least 10 seconds watched, so an instant exit isn't a click), the minutes watched, a like, and a dislike or "not interested". Labels therefore arrive up to a day late. Their known biases: viewers only react to videos we chose to show, the first row gets more clicks just for being first (position bias), and long videos collect more minutes just for being long.
Offline metrics – NDCG@20 with minutes watched as the relevance, on the most recent day of home pages, which the model never trained on. NDCG rewards putting the videos viewers actually watched longest near the top of the first 20, which is exactly what the home page is sorted for. Candidate generation, once it has its own model, is checked separately with recall: the share of the next day's watched videos that were among its candidates.
Online metrics – An A/B test decides each launch on satisfied watch time per daily viewer (minutes on videos the viewer didn't dislike or mark "not interested"). Guardrails: dislikes and "not interested" per 1,000 videos shown must not rise, and daily active viewers must not fall.
Data and Features
Training data – One row per video a viewer saw on the home page: about 20 per open, so about 60B rows a day. The row's labels come from joining that viewer's actions on that video within 24 hours. Events come from two places: the Home Service records which videos it served and where, and the app reports what the viewer did.
Features, grouped by what they describe:
| Group | Features | Computed |
|---|---|---|
| Viewer | Top channels and categories watched in the last 30 days, average minutes per video, languages, country, videos watched (last 90 days) | Daily |
| Video | Channel, category, language, length, title words | When the video is uploaded |
| Video engagement | Views, click rate, average share of the video watched, like rate, over the last 7 days | Daily |
| Viewer × channel | Subscribed or not, minutes watched from this channel in the last 30 days, days since the last watch | Daily |
| Context | Time of day, day of week, device (TV, phone, computer), the video's age | At request time |
Viewer × channel minutes are usually the strongest signal: people come back for the channels they already watch.
API Design
REST over HTTPS with JSON.
Get the Home Page
The first call ranks a new home page; calls with a cursor return the next page of the same ranking.
GET /v1/home?limit=20
GET /v1/home?cursor=c_31a&limit=20 # next page
→ Response:
{
"requestId": "r_5120", # ties later events to this ranking
"videos": [
{ "videoId": "v_88213", "position": 1 },
{ "videoId": "v_10477", "position": 2 }
],
"nextCursor": "c_31a"
}
Record Actions
The app sends what the viewer did, in batches every few seconds.
POST /v1/events
{
"requestId": "r_5120",
"events": [
{ "videoId": "v_88213", "action": "shown" },
{ "videoId": "v_88213", "action": "click", "at": "2026-11-16T19:02:11Z" },
{ "videoId": "v_88213", "action": "watch", "minutes": 12.5 },
{ "videoId": "v_10477", "action": "not_interested", "at": "2026-11-16T19:03:40Z" }
]
}
→ Response: 202 Accepted
- The viewer is identified by the login token in the
Authorizationheader, never by the body. - The app loads each video's title and thumbnail with the video service's existing call; the home page only decides which videos and in what order.
- Keep Learning has no endpoint: it is background work, and its only visible effect is a better order in Get the Home Page.
High-Level Design
One requirement at a time, in the simplest way that works; the deep dives then make it meet the numbers.
1. Show a Home Page of Videos
Path: App → API Gateway → Home Service → Candidate Generator → Ranking Service → Feature Store → back to the App
- The app calls
GET /v1/home. The API Gateway checks the login token, routes the call to the Home Service and spreads calls across its servers, skipping one that fails its health check. Home Service servers keep nothing in memory, so any server can handle any call. - The Home Service reads the videos it already served this viewer in the last 24 hours from the Home Cache, Redis (
served:{userId}), and asks the Candidate Generator for candidates. - The Candidate Generator collects about 1,000 videos from three lists kept in the Feature Store, Redis, which holds the candidate lists next to the features: the last week's uploads from the viewer's subscribed channels (
subs:{userId}), the videos most often watched by people who watched each of the viewer's last 20 videos (cowatch:{videoId}, top 100 per video), and the most watched videos of the week in the viewer's country and language (popular:{country}:{lang}). It drops videos the viewer watched or marked "not interested" (u:{userId}) and those the Home Service already served. Redis, because one request reads about 25 lists within a few milliseconds. - The Candidate Generator passes the candidates to the Ranking Service, which reads their features from the Feature Store in one batch call (a hash per viewer
u:{userId}, per videov:{videoId}, and per viewer and channeluc:{userId}:{channelId}). - The Ranking Service scores each video with the baseline: one logistic regression that predicts a click, trained with each click weighted by the minutes watched, so its score orders videos by expected watch time rather than by clicks. It's the baseline because it trains in hours on billions of rows, scores 1,000 videos in a few milliseconds of CPU, and its weights are easy to read, so we have a working home page in week one. It then moves a video down if it would be the third from the same channel in a page of 20.
- The Home Service saves the ranked list in the Home Cache (
home:{requestId}, 30 minutes), returns the first 20 with anextCursor, and adds them toserved:{userId}. A call with a cursor reads the next 20 from that list without ranking again, well within 150 ms (NFR 2). - If the Ranking Service doesn't answer within 120 ms, or the Feature Store is down, the Home Service returns the popular videos for the viewer's country and language from its own copy, refreshed hourly, minus those already served, so the page still loads (NFR 4).

2. Record What Viewers Do
Path: Home Service → Event Log; App → API Gateway → Event Service → Event Log → Data Pipeline → Feature Store and Training Data
- When the Home Service returns a page, it writes one impression event per video to the Event Log, Kafka:
requestId,userId,videoId,position,modelVersion, time. Kafka, because the events are an append-only stream that several jobs read at their own pace; it keeps them for 7 days. - The app sends what the viewer did with
POST /v1/events. The API Gateway routes it to the Event Service, which checks the events and writes them to the Event Log. The app sendsshownonly once a thumbnail has been on screen for a second, so a video the viewer never scrolled to doesn't count as seen. - Once a day, the Data Pipeline, a Spark job, reads the day's events from the Event Log and computes the daily features in the table above. It also rebuilds the candidate lists: each viewer's subscription uploads, each video's top 100 co-watched videos, and the popular lists. It loads both into the Feature Store.
- The Data Pipeline then builds training rows: for each impression with a
shownevent, it collects that viewer's click, minutes, like and dislike on that video within 24 hours, adds the features it just computed, and writes the rows to Training Data, S3 (Parquet files, one folder per day). Files in S3, because training reads billions of rows in large scans and never updates one.

3. Keep Learning
Path: Training Data → Training Pipeline → Model Registry → Ranking Service
- Each night, the Training Pipeline trains the model on the last 14 days of rows from Training Data.
- It then tests it on the most recent day, which it didn't train on. Splitting by time makes the test look like tomorrow, the day the model will actually serve. The new model passes only if NDCG@20 is no worse than the live model's, overall and for new viewers and each country.
- A model that passes is saved in the Model Registry: its files in S3, plus a row in the Models table in PostgreSQL (
version,metrics,status: candidate, canary, live or retired). - Ranking Service servers check the Models table every minute. A canary model serves 1% of viewers, chosen by a hash of
userId; every impression already carries itsmodelVersion(flow 2), so its guardrails can be compared with the live model's within hours, and then it becomes live. A new model design (new features or a new kind of model) instead runs as a full A/B test on satisfied watch time for one to two weeks. - Rolling back is setting the previous version back to live; every server loads it within a minute.

Known Gaps So Far – this design works for a small site, but not yet for our requirements:
- Candidates come from too few places. Co-watch lists only reach videos next to the viewer's last 20, so most of the 800M videos are never considered, and a viewer's wider taste is missed; scoring the whole library instead would be 800M videos × 100K requests a second (NFR 1, NFR 2).
- New videos wait a day. A video uploaded this morning is in no co-watch or popular list and has no engagement features until the nightly job, so outside its subscribers nobody is shown it; and what a viewer watched an hour ago isn't in their features yet (NFR 3).
- The model rewards clicks, not satisfied watching. One weighted logistic regression ignores likes, dislikes and "not interested", favours long videos, and learns from the top row getting clicked just for being on top (Problem Framing, FR 1).
Deep Dives
Three deep dives, one per gap: finding candidates first because it's the bottleneck, then new videos, then the ranking model.
1. How do we find 1,000 good candidates among 800 million videos in a few milliseconds?
The problem: the co-watch lists only reach a few thousand videos close to what the viewer watched last, so the home page keeps circling the same neighbourhood. The ranker can't simply look at more: 800M videos × 100K requests a second is far past any budget, and the candidates must be found in about 20 ms (NFR 1, NFR 2).
Solution: Retrieve by embedding – a two-tower model turns the viewer and every video into vectors, the Embedding Pipeline writes all video vectors into an ANN Index each night, and the Candidate Generator asks it for the 500 videos nearest to the viewer's vector, next to the existing lists, so candidates come from the whole library within the budget.
An embedding is a list of numbers that places similar things close together. A two-tower model has one network for the viewer and one for the video, trained so that a viewer's vector lands close to the vectors of videos they watch. An ANN (approximate nearest neighbour) index finds the closest vectors among hundreds of millions in milliseconds by searching only the most promising part of the space.
- The towers: the viewer tower takes the viewer's last 50 watched videos (each video's own embedding, weighted by minutes watched), country, language and device. The video tower takes the video's ID, channel, category, language, length and title words. Each outputs 128 numbers; the score of a pair is the dot product of their vectors.
- Training: the Training Pipeline trains both towers on pairs of (viewer, video they watched at least half of). Other videos in the same training batch act as the "not watched" examples; because popular videos appear in batches far more often, their scores are corrected for how often they appear, or the towers would learn mostly popularity.
- Embedding Pipeline: after the nightly training, it runs the video tower on all 800M videos and builds a new ANN Index. Compressed to about 64 bytes per video, the index is about 50 GB, so each index server holds all of it in memory. At about 2,000 lookups a second per server, 100K requests a second need about 50 servers, plus spares.
- Version pairing: the viewer tower only makes sense with the video vectors it was trained with, so the Embedding Pipeline publishes the viewer tower together with each new index, and the Candidate Generator always loads the tower that came with the index it queries.
- At request time: the Candidate Generator reads the viewer's last 50 watches from the Feature Store, runs the viewer tower on CPU (about 5 ms), and asks the ANN Index for the 500 nearest videos in the viewer's languages (about 10 ms).
- Merging: 500 from the ANN Index, about 300 co-watch, 100 subscription and 100 popular videos, deduplicated and minus watched ones, give about 1,000 candidates. Each keeps its source and its ANN score, which the Ranking Service uses as features.
- Checking it: every day, recall over the newest day's watches is computed per source, so a drop in the ANN list shows up before viewers feel it.

Other options:
- Longer co-watch lists, from the last 200 watches – a wider net, but still only neighbours of what was already watched, and no use for videos nobody has co-watched yet.
- Matrix factorization of the viewer × video watch matrix – learns a vector only for viewers and videos that already have history; the two-tower model also uses the video's channel, category and title, so a video with few views still gets a vector.
- Exact nearest-neighbour search – comparing the viewer's vector with all 800M videos is about 100 billion multiplications per request, far past 20 ms.
Trade-off: a 50 GB index rebuilt every night and kept in step with its viewer tower, and approximate search occasionally misses a good video that exact search would have found.
What changed: step 3 of flow 1 now also queries the ANN Index; the Embedding Pipeline and ANN Index are new, and the Training Pipeline trains the two towers. NFR 1 and NFR 2 are met for candidates.
2. How does a video uploaded an hour ago reach viewers?
The problem: the ANN Index is rebuilt nightly, and engagement features and candidate lists come from the daily Data Pipeline, so a new video waits up to a day before any non-subscriber can be shown it. With no views yet, the ranker also has no click rate or watch share for it, and the viewer's own recent watches are a day old too (NFR 3: 1 hour; about 2M uploads a day).
Solution: Index new videos and count early views as they happen – a Video Indexer adds each new video's vector to the ANN Index within minutes, a Stream Counter (Flink) counts views and minutes from the Event Log into the Feature Store, and a small share of home page slots goes to new videos that match the viewer, so a new video can be recommended within an hour and quickly earns real engagement.
Flink is a stream processing framework: it runs continuously, reads events from Kafka, keeps running counts per key over time windows, and recovers its counts from checkpoints if a server fails.
Feature Store (Redis), written by the Stream Counter
key: v:{videoId}:rt hash
fields: shown1h, clicks1h, minutes1h, shown24h, clicks24h, minutes24h, updatedAt
expires: 3 days after the last update
key: u:{userId}:recent list, newest first, trimmed to 50
values: videoId, minutes, action, time
expires: 90 days
- Video Indexer: it asks the video service for videos that went public in the last minute (about 25 a second), runs the video tower that came with the current index on each one's channel, category, language, length and title (a new video has no learned ID vector yet, so it uses a shared "new video" one), and inserts the vector into the ANN Index. The index takes inserts between nightly rebuilds, so the video can be retrieved within minutes.
- Stream Counter: it reads every
shown,clickandwatchevent from the Event Log and keeps 1-hour and 24-hour counts per video, writingv:{videoId}:rtevery 30 seconds for videos whose counts changed. Load: about 60B shown events a day is about 700K a second on average and 2M at peak, which a few dozen Flink servers handle because each adds up its own events for a few seconds before writing. - It also pushes each watch onto the viewer's
u:{userId}:recentlist, which the Candidate Generator already reads for the viewer tower (deep dive 1), so what a viewer just watched shapes their next home page. - Cold start in the ranker: for a video with fewer than 1,000 views, the Ranking Service blends its own early click rate and watch share with its channel's average, giving the channel more weight the fewer views the video has.
- Exploration: one slot in every 20 goes to a fresh candidate: a video less than 48 hours old with fewer than 1,000 views, taken from the viewer's ANN results. Math: 3B home pages × 20 videos × 5% is about 3B exploration impressions a day, so each of the 2M new videos gets around 1,500, enough to measure its click rate and watch share.
- A video that does well in exploration enters the co-watch and popular lists at the next nightly run; one that does badly stops being explored after its 1,000 views.

Other options:
- Rebuild the whole index every hour – 800M vectors re-embedded for about 80K new ones each hour, and still up to an hour late.
- Boost every new video by a fixed amount – floods home pages with the many uploads few people want; exploration picks the new videos that match each viewer and stops when they don't do well.
- Wait for subscribers to watch – most new videos come from channels with few subscribers, so they would never get the views that put them in co-watch lists.
Trade-off: exploration slots cost a little watch time today in exchange for knowing about tomorrow's good videos, and a second pipeline now counts engagement, so it must use the same event definitions as the daily one.
What changed: the Video Indexer and Stream Counter are new; the ANN Index takes inserts; the Feature Store gets v:{videoId}:rt and u:{userId}:recent; the Ranking Service blends channel averages for new videos and fills 1 slot in 20 by exploration. NFR 3 is met.
3. How do we rank for watching people are glad about, not for clicks?
The problem: the baseline is one logistic regression on clicks weighted by minutes, so a misleading thumbnail still gets clicks, a two-hour video wins on minutes, and dislikes and "not interested" don't count at all. It also learns that the top row gets clicked, then keeps putting its old choices there. A model that can learn all this costs about 100 times more per video; on all 1,000 candidates that is 100M videos a second at peak, past the 80 ms for models (Problem Framing, NFR 1, NFR 2).
Solution: Rank in two stages with a multi-task model – the Ranking Service's Light Ranker keeps the baseline to cut 1,000 candidates to 300, then a Heavy Ranker on GPU servers predicts click, minutes, like and dislike for those 300 in one batch, while a small position input learns how much the slot itself adds and is switched off at serving, so the home page orders by satisfied watch time instead of clicks.
A multi-task model is one neural network with shared layers and one small output ("head") per prediction. Rare reactions such as likes and dislikes learn from the plentiful clicks through the shared layers, and one call returns all four predictions.
- Light Ranker: the Ranking Service keeps flow 1's logistic regression on about 20 cheap features, scores all 1,000 candidates in about 2 ms of CPU, and keeps the 300 with the highest score.
- Heavy Ranker: a separate service on GPU servers, called once per request with all 300 videos and their features, plus the viewer's last 50 watches and each candidate's source and ANN score. Its heads predict the click probability, the minutes watched if clicked (capped at 60, so a two-hour video can't win on length alone), the like probability and the dislike-or-"not interested" probability. Cost: 100K requests a second × 300 videos = 30M videos a second; at about 100K a second per GPU server, that's about 300 servers. Scoring all 1,000 would need about 1,000.
- Value score: the Ranking Service combines the heads into Problem Framing's expected satisfied minutes. The weights stay fixed in the Models table and change only through an A/B test on satisfied watch time, never with each nightly model.
- Clickbait: a click followed by less than 10 seconds of watching is labelled "no click" (Problem Framing), so a thumbnail that disappoints learns a low click probability, and the minutes head pulls it down further.
- Position: during training, the slot and device go into a small extra input whose output is added to the click prediction, so it learns how much being in the top row adds on its own. At serving, that input is left out, so videos are compared as if each were shown in the same slot.
- Surveys: 1 in 1,000 watches ends with "Was this video worth your time?". The answers aren't training rows; they check offline that the value weights rank the videos people call worth it higher.
- Budget: Candidate Generator about 25 ms, features and Light Ranker about 15 ms, Heavy Ranker about 35 ms, the rest about 10 ms: about 85 ms typical, within the 200 ms p99. If the Heavy Ranker doesn't answer within 60 ms, the Ranking Service returns the Light Ranker's order.

Other options:
- Predict minutes watched only – simpler, but long videos win and dislikes still don't count.
- Weight each training row by how often its slot gets noticed – removes position bias in theory, but the weights must be measured with shuffled pages and are noisy for low slots; the position input learns them from normal traffic.
- The Heavy Ranker on all 1,000 – about 1,000 GPU servers instead of 300, and batches three times longer in the budget.
Trade-off: two models to train and keep in step, a post-Light-Ranker cut that some good videos never get past, and value weights that are a product choice needing long A/B tests.
What changed: step 5 of flow 1 now runs the Light Ranker and then the Heavy Ranker; the GPU servers are new; training labels treat quick exits as no click and learn position separately; Model Registry rows get a kind (two-tower, light or heavy). FR 1 now orders by Problem Framing's objective, and NFR 2 holds.
What's Expected at Each Level
Mid
- Makes all three flows work end to end: candidates from a few lists, a baseline model on features from the Feature Store, cached pages, events in a log, a nightly model with an offline check.
- Frames the objective as watch time rather than clicks, and names a fallback when ranking fails.
- Reaches deep dive 1 with hints, and suggests embeddings for candidates once told the co-watch lists only reach a small corner of the library.
Senior
- Does the math without hints: 800M videos can't be scored per request, so candidates need an ANN lookup, and the heavy model only fits after a cheap first stage.
- Designs the two-tower model with its negatives and popularity correction, and keeps the viewer tower and index versions together.
- Spots that new videos are invisible for a day and adds indexing on upload, streaming counts and exploration.
- Reaches deep dive 3: multi-task heads, quick exits as no click, and position learned separately.
Staff
- Names the objective as the core decision early: what the value score rewards changes what creators make, so weights change only through long A/B tests with dislikes and daily viewers as guardrails, checked against surveys.
- Raises failures before being asked: Heavy Ranker timeout falls back to the Light Ranker, a stale index still serves, a failed nightly model never reaches viewers, and the popular-list fallback keeps the page up.
- Handles the feedback loop: exploration for new videos, position learned and switched off, and recall tracked per candidate source.
- Owns the cost: about 50 index servers and 300 GPU servers instead of 1,000, with the math for each.