Design search autocomplete (Google)
Design search suggestions that appear as the user types. Every keystroke should produce updated suggestions, ranked by what people actually search for.
About this problem
“Design search autocomplete (Google)” is a core-level problem in the search and ranking family. The user gives you a fragment and expects the right answer ranked first.
The key challenge: A hundred milliseconds per keystroke, because a person types the next character in about 200. And hours of slack on how fresh the suggestions are.
Time budgets: Per keystroke: ~100 ms. Index freshness: hours.
The worked solution for Typeahead goes through why those budgets shape the design, stage by stage.
Before you start
You will work this in five timed stages. Here is what each one asks you to think about. None of it is the answer; the answers unlock in the workspace below once you have written your own.
- Stage 1 · Requirements · 5 min
- Where do the suggestions come from? The answer changes the design.
- Personalised or global? It changes whether you can cache.
- How many requests does one search generate?
- Stage 2 · Actors and lifecycle · 6 min
- A suggestion has a life: it gets born from queries and eventually dies. Trace it.
- What does the system decide, without anyone asking, about which suggestions to show?
- What happens when someone types faster than your responses arrive?
- Stage 3 · Numbers · 6 min
- Requests per second: remember the keystroke multiplier.
- How many distinct queries are worth suggesting? Be realistic.
- How big is the precomputed answer for every prefix?
- Stage 4 · High-level design · 12 min
- What structure answers "top 10 completions of this prefix" in microseconds?
- Where is the ranking computed — at build time or at request time?
- How does the index get updated without downtime?
- Stage 5 · Deep dive and tradeoffs · 14 min
- How do you handle typos without abandoning the trie?
- A breaking news term explodes. Walk through what happens.
- What does a rebuild cost you in memory?
Work it through
Five stages, gated. You write your answer for each stage before its model answer unlocks. That is the core of the method.
Done all five? The diagrams, numbers, trade-offs and follow-ups for this problem are on the worked solution page, to check your own design against.
How it is really built
Write your own answer first. Then read how teams who run this at scale describe it. Their constraints were real, and the write-ups often say what their choices cost.
- Elasticsearch — Suggesters ↗Prefix completion as an actual implementation, with its memory cost.