Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 08

Design search autocomplete

Advanced · 40 min · Search & ranking

As someone types into a search box, a short list of suggested queries appears under it and updates with every keystroke. Good suggestions save typing and steer people toward queries that return useful results; slow or stale ones are ignored, and offensive ones make the news.

Requirements

  • Return up to 10 suggested completions for the text typed so far, ordered by likelihood.
  • Suggestions come from what other people have searched, weighted toward recent popularity.
  • A query that suddenly becomes popular (breaking news) starts appearing as a suggestion quickly.
  • Blocked terms (offensive, illegal, personal data) never appear as suggestions.

Constraints and assumptions

  • 5 billion searches a day; with typing debounce the client sends about 5 suggestion requests per search.
  • Server-side p99 under 30 ms per suggestion request; the whole keystroke-to-render budget is about 100 ms.
  • About 1 billion distinct queries in the last 30 days, but only queries typed by at least 50 distinct users may be suggested.
  • A newly trending query should be suggestible within 15 minutes; a newly blocked term must disappear within 5 minutes.
  • One language and market for the first design.

Out of scope for the first sketch

Spelling correction and fuzzy matching · The search results page itself · Multiple languages and scripts

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches