Phase 1 — Clarify & Scope
Interviewer: Design a system that finds the top K most frequently occurring items in a data stream — think "top 10 trending hashtags on Twitter" or "top 100 most-searched queries on Google." What do you want to clarify?
Candidate: A few questions:
- What's the data volume — events per second?
- What's K? Top-10, top-100, or top-1000?
- How large is the item space — how many unique items (hashtags, queries)?
- What freshness is required — last 1 minute, last 1 hour, last 24 hours?
- Exactness — can we tolerate approximate results, or does every item need an exact count?
Interviewer: Twitter-scale trending: 100,000 tweets/sec, each tweet has up to 5 hashtags → ~500,000 hashtag events/sec. Find top-100 trending hashtags. Item space: 100 million unique hashtags. Freshness: last 1 hour, updated every 1 minute. Approximate results are acceptable (within 0.1% error).
Candidate: Let me size the problem:
With exact counting (HashMap: hashtag → count):
With Count-Min Sketch (ε=0.001, δ=0.001):
That's a ~53,000×…
In the full tutorial
- Phase 2 — High-Level Architecture
- Phase 3 — Deep Dive & Evolution
- Phase 4 — Robustness & Operations