SimuVedaSystem Design Lab Open in the lab

Design interviews / Intermediate / 6 min / Updated

Design search autocomplete: tries, top-K and debouncing

Type into a search box backed by a trie. Stored top-5 lists answer in microseconds but miss trending queries; debouncing cuts requests by half.

Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.

In short

How do you design search autocomplete?

Autocomplete stores queries in a trie and keeps the top K completions at each node, so each keystroke is one cheap read.

Why does it matter?

Suggestions must come back in under 100 ms for every key, for millions of people typing at once.

What is the trade-off?

Precomputed lists are fast but stale; rebuild them in batches and merge a small trending list. Debounce in the client.

How do you explain it in an interview?

"Trie with top-K per node, sharded by prefix, CDN-cached for short prefixes, rebuilt hourly plus a live trending list, 200 ms debounce."

Check yourself

Why store the top 5 completions at every trie node?

Answer: A lookup then costs only the prefix length instead of walking every completion under it. Short prefixes like "s" have millions of completions below them; precomputing turns that walk into one read.

What is the downside of precomputed top-K lists?

Answer: They are a snapshot, so a newly trending query is missing until the next rebuild. Rebuild often, or merge a small fast-changing trending list with the stored one.

What does debouncing in the browser do?

Answer: Waits for a short pause in typing before sending a request. Most keys are typed faster than 150-300 ms, so only pauses and the last key send a request.

See it happen in the simulation →

autocompletetypeaheadsearch suggestionstrietop kdebouncegoogle searchsystem design interview

More in design interviews