Design StreamHub's search bar: as a user types "fort", suggest "fortnite", "fortnite ranked", "fortnite clips" ranked by popularity — under 100 ms p99 at 50K concurrent typists.
Requirements
Functional requirements
- Return top 5–10 autocomplete suggestions for a prefix (1–20 characters).
- Rank suggestions by popularity (search frequency), recency, and personalisation.
- Support fuzzy matching for typos (optional v2).
- Update suggestions as trending topics change (within minutes).
- Language-aware suggestions based on user locale.
Non-functional requirements
- Latency: p99 under 100 ms; p50 under 30 ms.
- Scale: 50K concurrent users typing; 500M autocomplete requests/day.
- Corpus size: 10M unique query strings; growing with user searches.
- Freshness: Trending queries reflected within 5 minutes.
- Availability: 99.9% — search bar is on every page.
Out of scope: Full search results page, image search, semantic/vector search.
Estimation
- 500M requests/day ÷ 86400 ≈ 5.8K QPS average, ~20K peak.
- 10M unique queries × 30 bytes avg ≈ 300 MB raw corpus — fits in memory.
- Trie with 10M strings: ~500 MB–1 GB in memory with frequency scores.
- Personalisation adds ~100 bytes × 50M users = 5 GB — store top-10 per user in Redis, not in trie.
Search & autocomplete
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 5 sections
- API design
- High-level architecture
- Deep dive: trie-based lookup
- Deep dive: ranking signals
- Deep dive: scaling and freshness
Test yourself
Answer these before moving on — recall is what makes it stick.