KatInterview

Building a Type-Ahead Suggestion Service for a Large Search Box

System DesignModel answer
HardModel answerSystem Designsystem-designautocompletetrie

Last updated

Design a low-latency type-ahead service that returns ranked, personalized, typo-tolerant, multilingual query suggestions while filtering abusive content and protecting user privacy.

Problem

You are asked to design the type-ahead feature of a large consumer search product. As a user types into the search box, the system should show a short list of likely full queries.

Requirements

  • The round trip for each keystroke must stay under 100 ms.
  • Suggestions should be personalized to the user and should surface currently trending queries.
  • The system must tolerate misspellings and work across multiple languages and scripts.
  • It must prevent abuse (spam, offensive or harmful completions) and respect user privacy.

What to cover

  1. Overall architecture: how query data is collected, how the index is built, and how requests are served.
  2. The ranking approach, including how global, trending, and personal signals are combined.
  3. Caching at each layer.
  4. How you would measure quality, both offline and online.

State your assumptions about scale, and call out the trade-offs you make.

Hints

Hint 1

Work backwards from the latency budget: after network and rendering time, only a small slice remains for the server, which pushes you toward in-memory lookups with precomputed results per prefix.

Hint 2

Separate the slow-moving part (a large immutable index rebuilt in batch) from the fast-moving part (a small streaming overlay for trending queries), and merge them at request time.

Hint 3

Treat safety and privacy as pipeline stages rather than afterthoughts: require a minimum number of distinct users per query before it can be suggested, and filter both when building the index and when serving.