LeetDesign
← All problems
Easy

Design Search Autocomplete

Suggest completions on every keystroke with a 12ms budget. The database physically cannot answer that fast — this is the problem that forces an absorbing layer.

Design the typeahead service behind a search box. Every keystroke asks for the top completions of the current prefix; a background pipeline occasionally rewrites a prefix's suggestion list as popularity shifts.

The tyrant here is the latency budget. Suggestions race the user's next keystroke, so the p99 budget is 12 milliseconds — and a quorum-acked database read alone costs most of that before queueing even starts. No amount of horizontal scaling fixes arithmetic: some layer near the edge has to answer almost every request without touching the database at all. The saving grace is the traffic's shape — a tiny set of popular prefixes dominates, and nobody cares if a suggestion list is a few minutes behind the trend.