Section 7: Eleventh Everywhere, First Overall - Exact Sliding-Window Top-10 (Candidate-Driven)
Executive Summary: Handed the wheel, the candidate dives into the speed path first, because a wrong Top-10 still looks plausible. Five dives follow. Keying by productId turns "merge the local Top-10s" from a classic bug into an exact algorithm. Minute buckets plus running counters give exact 1h, 4h and 24h sliding windows that can go down as well as up. Event time, a fast minute clock and a 2-minute settle watermark absorb stragglers and cancellations without delaying the list. Checkpoints, dedup and version-checked writes make each list exactly-once. A top-20 cushion lets serve-time filtering run without leaving gaps. The lesson: an exact streaming Top-K is cheap once the partitioning makes it exact by construction.
Choosing Where to Dig
Section 6's diagram is up on the board. The interviewer hands you the floor: "Where do you want to go deeper?"
You: "The speed path first. When the rank path is wrong you can see it: two #13s on a page. When the speed path is wrong, you get a confident Top-10 with the wrong products on it. It has four quiet failure modes: the merge across partitions, windows that must forget, late or cancelled events, and failures that double-count. Section 8 can have '#1,056'."
Picking the dive where errors are invisible tells the interviewer you know where production bugs hide.
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