Skip to content
We areTOP 1%

Design a typeahead (search autocomplete) system

MediumConceptSocial Platforms
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

Requirements: return the top five or so suggestions for a typed prefix within about 100 ms, ranked by popularity, at a very high query volume.

  • Data structure: a trie in which each node stores its precomputed top-k completions, so a lookup is just a walk down the prefix, independent of how many queries match it.
  • Data pipeline: query logs are aggregated offline (for example, hourly or daily) into frequency counts, and a new trie is built and swapped in; serving nodes do not update it on every keystroke.
  • Serving: shard the trie by prefix and replicate it; cache popular prefixes in Redis and in the browser; clients debounce keystrokes to cut request volume.
  • Trade-off: offline rebuilding keeps lookups fast and simple but makes suggestions slightly stale; trending terms need a separate real-time path.

More in Social Platforms

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account