Scope
Functional
- As the user types, return the top 10 suggestions for the current prefix.
- Ranked by popularity (and freshness); filtered for offensive content; multiple languages (incl. transliterated Hindi, "Hinglish").
Non-functional
- p99 < 50 ms server time. Highly available (degrade to no suggestions, never to errors).
- Suggestions reflect trends within ~15 minutes.
Size
- 100M searches/day, average 8 keystrokes → 800M suggestion requests/day ≈ 10k/s, peak ~30k/s (less with client debouncing).
- Unique queries: ~100M; the useful head is ~10M queries.
The data structure
A trie maps prefixes to nodes; each node stores the precomputed top-K completions beneath it, so a lookup is just "walk the prefix, return the stored list". No subtree traversal at query time.
Space-saving variants: compressed tries (radix trees), or FSTs (finite state transducers, used by Lucene) which are very compact. A simpler practical option: a key-value map from every prefix (up to ~20 chars) → top-K list, which shards trivially.
The architecture
The 30-second summary
"Suggestions come from an in-memory prefix index where each prefix stores its precomputed top-K, built offline from time-decayed query logs with safety filtering, plus a trending delta from a 15-minute streaming job. Short prefixes are cached at the CDN, clients debounce and filter locally, and personal history is blended in at request time."
Follow-up questions the interviewer may ask
- How fast must suggestions be?
- How do trending queries appear quickly?
- How do you personalise?
- How do you filter offensive suggestions?
Model answers to each of these are in the book.