Layer 3 · Go deeper · 12 min
Go deeper
Size it, build it, then make the calls an interviewer will push you on.
Back of the envelope
Size it up
Tap through each step of the arithmetic.
How much memory does exact counting need for one 24-hour window?
How small can a summary be, and how wrong can it get?
How big are all the lists together, and how often are they read?
How many counting tasks, and how much state does each hold?
Build-up · 5 steps
Build the high-level design
One functional requirement at a time, ending with a design that works for a mid-sized app.
Step 1 of 5
Top K for a window
Kafka absorbs the post-match spike and lets the counter restart where it stopped. Every 10 s the counter sums minute buckets and picks the top K with a min-heap; reads only fetch finished lists.
6 interview moments
You’re the candidate
The interviewer pushes on the hard parts. Pick an approach and see how it holds up.
Deep dive 1 of 6
Interviewer
“A billion items a day, almost all seen only a handful of times. How do you count them for top-K lists?”
Your move. Pick an approach:
Deep dive 2 of 6
Interviewer
“3M increments a second need about 64 counting tasks. How do you route events so the top K stays right?”
Your move. Pick an approach:
Deep dive 3 of 6
Interviewer
“The product promises “last 5 minutes”, “last hour” and “last 24 hours”. How do you slide those windows from one stream?”
Your move. Pick an approach:
Deep dive 4 of 6
Interviewer
“Product wants a “trending now” tab, not another most-viewed list. How do you score items?”
Your move. Pick an approach:
Deep dive 5 of 6
Interviewer
“75k list reads a second at peak, with p99 under 50 ms. How do you serve them?”
Your move. Pick an approach:
Deep dive 6 of 6
Interviewer
“The charts team will publish “#1 video in India on 24 May”. Where does that number come from?”
Your move. Pick an approach:
Build-up · 8 steps
Follow one event and one read
The hot path is Kafka, two Flink stages and a merger; reads never wait for counting. Object storage and Spark keep the truth.
Step 1 of 8
Ingest
Apps batch events, each with an event_id so retries can be de-duplicated. The ingest API adds country and region itself instead of trusting the client, and writes to a 64-partition Kafka topic.