Section 9: Seven Pushes on the Hybrid - Interviewer Deep-Dive Challenges
Executive Summary: The hybrid fan-out survived Section 8. Now the interviewer pushes on every choice around it: pull for everyone, Cassandra instead of an in-memory cache, a user who scrolls past the cap, a blocked user who saw a post, an "arbitrary" threshold, a demand for real-time, and a ranking outage. For each you get what's really being tested, a model answer tied to the numbers, the alternative you turned down, what would flip it, and one sentence worth saying out loud.
Every challenge has a cheap answer ("it's faster") and a priced one ("it costs this much, and here's when I'd change it"). Give the priced one.
Challenge One: "Caches Are Fast. Why Not Just Pull for Everyone?"
"Cache every author's timeline. Each read is a millisecond. Merge at open time and skip fan-out."
What they're really asking: do you know that fan-out on read multiplies your tail, not just your average?
The average is fine. The tail isn't. Maya follows 200 accounts, so a pure-pull open is 200 timeline fetches, and at 175K opens/s peak that's 35M timeline reads/s. Now give each fetch a 1% chance of being slow, over 50 ms. The chance that at least one of 200 is slow is 1 − 0.99^200 ≈ 87%. The open waits for its slowest fetch, so most opens land in the tail.
Interviewer: "Hedge the slow ones. Send a second request after 10 ms."
You: "That trims the tail and adds load on top of 35M reads/s. I'd rather not do 200 reads at all. The hybrid does one feed-cache read plus one batched multi-get for Maya's 20 celebrity timelines. Fleet-wide that's 3.5M key reads/s against an 80 MB cache every replica holds in full, inside the ~15 ms candidate budget."
Interviewer: "Your hydration fans out too."
You: "It does. Hydration's 20 keys can land on 20 post-cache nodes, so about 1 − 0.99^20 ≈ 18% of pages touch one slow node. That's 18% instead of 87%, and it's why hydration over-fetches and hedges its last few keys. The candidate step is two calls, not 200."
Pull isn't wrong. It's right for accounts at or above 100K followers, where push is ruinous.
The senior line: "Pull multiplies your tail latency by your followee count, so we pull only from the 20 accounts where pushing would cost more."
Sign in to continue reading
The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.
Sign in to read the full lesson