Ch.28: System Design: How Recommendations Find Your Next Video
Outline
- 0:00 Why the useful video never appears
- 0:41 The request and feedback architecture
- 1:39 Functional and non-functional requirements
- 2:30 Why ranking cannot scan the catalog
- 3:20 Four candidate sources
- 4:29 New creators and candidate recall
- 5:27 Batch scoring and feature lookup
- 6:36 Sharing the request deadline
- 7:21 Fresh session interests
- 8:19 Dismissals and retry-safe feedback
- 9:08 Training labels without future leakage
- 10:07 Compatible models and candidate indexes
- 11:08 When the ranker is unavailable
- 12:05 Building a useful page from good scores
- 13:01 Following the repaired request
- 13:52 Diagnosing the next recommendation failure
Transcript
0:00 Maya's sink leaks, so she watches a repair tutorial, dismisses an old clip and refreshes. Her feed still offers yesterday's music and that dismissed clip, but no promising repair creator. I would immediately blame the model. Apparently it thinks plumbing is a musical genre. I'd blame it too, but suppose that creator's video never reached the model. It can't recommend something nobody handed it. Ah, so three bad outcomes might be three different failures, even with every server showing green. Yes. Our fictional app, Lantern Video, turns 10 million videos into 20 useful choices within a 200-millisecond server deadline. We'll find candidates, rank them, and remember Maya's actions.
0:40 Let's sketch Maya's request before we take it apart. A coordinator asks several services for possible videos, merges their answers, checks eligibility, and sends a bounded list to the ranker. Which is the model that scores and orders that list. Then there's another check before the cards go back to Maya? Yep, for restrictions, repeats, and variety. We record which cards actually appeared, and Maya's actions come back through a feedback stream. That stream splits here. The session path remembers Maya's actions quickly.
1:09 The other path builds durable history and later training examples. Exactly. Model updates return to serving with their matching parts kept together. Google's recommendation course lays out retrieval, scoring, and re-ranking; its 2016 YouTube paper described separate candidate and ranking models. We're designing our own version, with source links in the description. Yeah, a card can go wrong before scoring, during scoring, or after scoring. That's a much more useful map than one enormous box labeled AI.
1:39 Before we implement that map, let's pin down the product contract. Our functional requirements are a personalized list, new videos getting a chance, quick reaction to session actions, and a record of what was shown. Plus no duplicates or dismissed clips, and no unavailable or restricted videos. If Maya isn't allowed to see a video, a high score doesn't make it eligible. Agreed. Our non-functional requirements are bounded cost, that deadline for 99% of requests, and fresh enough inputs. A fast page of yesterday's music still fails Maya.
2:11 I think “fresh enough” hides the hard choice. Her long-term interests can lag. A dismissal should affect her next refresh, even if the durable pipeline is behind. Fair. And 20 cards is the desired count, not permission to fill empty slots with something we couldn't verify. We can return fewer. Let's stress-test that deadline. Could enough parallel hardware score every video, then take the best 20? Suppose each score took 1 millisecond, sequentially. 10 million scores would take almost 3 hours. Parallel hardware helps, but repeating that whole job for every refresh is a spectacular way to buy a very expensive loading spinner.
2:51 It's like reading every book in the library before choosing a small reading pile. Right. Candidate generation is our librarian's shortlist. Let's give the expensive ranker 500 candidates, so it spends richer computation on those rather than millions of irrelevant items. Okay, that tutorial maker must be somewhere in the 500, or no amount of careful ranking puts her on Maya's screen. That's the first debugging question: did the video even enter the shortlist? So let's give that creator several ways in.
3:22 One candidate source follows Maya's longer-term interests, another finds videos related to this session, another supplies contextual popular picks, and a small exploration source tries eligible fresh uploads. How does the recent-watch source find matches without scanning every video? One option is an embedding: a list of numbers placing a video on a learned similarity map. Maya's watched repair tutorial becomes the search point. An index finds nearby videos without scoring the whole catalog. So another sink tutorial gets considered while yesterday's music sits farther away.
3:57 What places a brand-new creator on that map before anybody watches her? In our design, we use the video's topic and other content information to give it a starting representation. Nearby means learned similarity, not guaranteed enjoyment. Fresh-item exploration provides another route in. Yeah, for a new viewer, context can get the first page started. Merge the sources and remove repeated IDs, but keep their origins. Otherwise we'll never know which door stopped working. Then how do we test retrieval separately from ranking?
4:29 Those source records open up a test for the missing creator. Imagine the ranker keeps improving, but retrieval supplies only popular videos. A new repair video still gets zero chances. Wait, so ranking scores could improve on their own test while the homepage doesn't improve for Maya? They could. For example, take 10 videos Maya found useful on Tuesday. All were available and eligible on Monday. Keep Tuesday's watches out of training and replay Monday's request. If six reach its shortlist, candidate recall is six out of 10.
5:02 Ah, but that known set comes from videos viewers were shown. It can't tell us about every unseen video they might have loved. Correct. It's an incomplete test, so pair it with measured exploration and source-contribution checks. We give some eligible new items exposure rather than making them prove popularity before anyone can see them. Nice. Our repair creator finally gets a chance to earn feedback. Once the candidates survive retrieval, what exactly do we pass into ranking? Ranking needs facts about Maya, this request, and each video.
5:35 We call those facts features, and fetch them before asking the model for scores. I used to mentally put those inside “the model.” Picture 500 candidate rows in a worksheet: features fill the cells, while weights are learned settings in its scoring formula. New inputs change scores without changing those settings. Exactly. Fetch Maya's shared inputs once and the item inputs in a batch. 500 separate remote lookups give 500 opportunities for one slow dependency to hold the page hostage. Yep. Then one bounded ranking call scores the batch.
6:08 We can log how old each input was, and whether a missing feature used a defined default. A default the model actually understands, though. Quietly replacing missing watch history with zero might tell it “new viewer” when the feature service is merely broken. Right. If you've debugged a missing field that quietly became zero, this is that trap with a more convincing answer. Missingness gets its own meaning, and we track when defaults take over. Now those feature calls share the deadline with retrieval.
6:39 Suppose our fresh-item source keeps missing the cutoff. Maya gets fast pages, but the new repair creator never enters them. How do we keep that timeout from silently changing the recommendations? Give parallel retrieval 100 milliseconds, feature fetching and scoring 60, and filtering and assembly 40, as an initial budget. Each source gets a cutoff within that shared retrieval window. So we accept the sources that finish in time and cancel work that no longer helps. But if fresh items always lose, “degraded” has quietly become normal.
7:12 Yeah. Measure source losses alongside end-to-end latency under production load. Adding those budget numbers doesn't prove we meet the 99th percentile. But yesterday's music points to a different failure: Maya's durable profile says music, but her current session says sink repair. Which input should win on this request? We don't have to overwrite her whole identity. Keep a recent session layer alongside the durable profile, and let the ranker use both with timestamps. So one repair watch can matter immediately without erasing years of music.
7:45 I wouldn't want fixing a tap to become my permanent personality. Me neither. Netflix's November 2025 article described daily embedding refreshes, then investment in updates reacting during a session. That faster update path still couldn't handle very large models. Then freshness is a budget per input, not one giant “real time” label on the diagram. Exactly. For our design, a stale long-term profile may be tolerable. A session layer that forgot her recent dismissal isn't, because it breaks a promise she can test on the very next refresh.
8:19 Let's enforce that dismissal directly. The next request carries the clip ID in Maya's recent-dismissal set, so we suppress it before waiting for the feedback stream to update her durable history. Does dismissing it also tell us she hates plumbing videos? No. Maybe she already watched this one, dislikes this presenter, or just wants something else now. The event says what happened; a broad preference is an inference. Fair enough. Her older watch now arrives after the dismissal. Apply arrival order blindly, and the clip comes back.
8:48 A retried dismissal mustn't count as a second dislike, either. Yep. Store a stable event ID and the observation time. Deduplicate retries, and keep that older watch from undoing the newer dismissal. Delivery timing shouldn't change what Maya meant. Maya's next refresh obeys the dismissal while the training pipeline catches up. And when that feedback reaches training, how do we connect a watch to the exact recommendation that produced it? Join the event to a display record. Suppose Maya watches the repair card we showed her.
9:20 Log the impression, meaning the actual displayed card, and connect her later feedback to its ID. Along with the model version and the input values used to select it. Otherwise, when we build the training row tomorrow, we might fetch her new profile instead. Oh, so we'd teach the model that Maya already liked repairs before the watch that taught us she liked repairs. Yes. That's future information leaking into a historical example. The offline test looks smarter because it gets an answer the live request never had.
9:51 Right. And videos she wasn't shown don't become dislikes just because there's no click. We never gave her that choice. Yep. Use serving-time inputs, distinguish unknown feedback, and test on later time windows. The model has to predict with what existed then. Those historical inputs raise a rollout problem too. Imagine a new query encoder, which converts Maya's interests into numbers, starts using a different representation. But the video index still uses the old map. It's like sending north, east coordinates to a map that reads east, north. Both numbers are valid; the destination is wrong.
10:27 Ah, so you roll that out, see green health checks, and send Maya to the wrong neighborhood. That's nasty. How do we keep those parts matched? Keep each pair together: the query encoder and matching video index, the ranker and its expected input definitions. Try that bundle on a small traffic share. Keep the previous compatible bundle ready for rollback. Yeah. Netflix described stabilizing embeddings because retraining and daily updates can shift the map. Meta's 2024 reliability article makes the consequence clear: predictions can be available and still wrong.
11:00 For Maya, “all requests succeeded” is a weak celebration. Her videos can get worse while every server says it's healthy. Now suppose the compatible ranker times out. We've got candidates, but no expensive scores. I'd rather return a cheaper ordering than an empty spinner. Sure, we can use a bounded saved order or cheaper scores, but it still goes through the current eligibility check and Maya's dismissal set. A cached homepage might otherwise bring back that rejected clip, or a video that's been removed since we saved it.
11:31 That would be a reliability incident hiding inside a successful response. Yes. Cache age limits help freshness, but they don't replace checking whether each item is allowed now. If the eligibility service itself is unavailable, our design refuses the list. Our product owner says, “The homepage is down. We have a cached page. Ship it.” That's a real availability cost we're choosing, isn't it? It is. If we can't verify eligibility, we return an error. That refresh counts as a failure, even though a cached list was sitting there.
12:05 Once eligibility is settled, the final page still needs judgment beyond sorting scores. 20 near-identical sink videos could all score highly and still be a miserable set of choices. Yeah, final re-ranking can remove repeats, spread creators or topics, and make room for freshness. Google's course explicitly treats diversity and freshness as separate concerns at that stage. We can retrieve extra candidates before filtering. If 12 eligible choices survive, we return 12. Oversampling can't produce videos that aren't in the available inventory.
12:36 Once those cards appear, what if clicks rise but viewers abandon the videos immediately? Did our better-looking dashboard actually mean a better page? So compare later watching and explicit feedback, alongside latency and exposure. Pick the satisfaction goal deliberately rather than quietly treating clicks as the whole product. Maya came for a working sink. A page that earns her next watch should help her get there. Let's follow one successful refresh across the full map. Maya's recent repair watch reaches the session layer.
13:08 This time the related-video source finds that new upload before its cutoff. So the repair video is in contention. We merge IDs, verify eligibility, and read timestamped features together. The compatible ranking bundle gets the remaining budget. Then policy suppresses the rejected clip and unavailable items. If our new creator ranks well and survives the final variety pass, her video reaches Maya. Retrieval gave her a chance, not a guaranteed slot. Each displayed card gets an impression ID. New actions update the recent session promptly and durable history later.
13:42 The inputs saved for the earlier request stay as they were. If ranking fails, the cheaper path still respects those filters. Each part changes something Maya actually sees. And if her repair creator disappears again, we can locate the loss: retrieval, stale inputs, incompatible scoring, or final filtering. We don't have to blame “the algorithm” as one unknowable thing. So the bigger model earns its place only after the rest of the request gives it a fair shot. Better scores can't rescue a video we never considered.
14:13 Yeah, and a fresh session matters only if the right inputs reach a compatible model before the deadline. The serving system is part of recommendation quality, all the way to the cards Maya sees. Thanks for listening to Learning Podcasts.