KatInterview

Build a Low-Latency Autocomplete System

System DesignModel answer
HardModel answerSystem Designautocompletecachingranking

Last updated

Design an autocomplete service that returns ranked suggestions in under 100ms, handling scale, personalization, and freshness.

You need to design an autocomplete system that delivers suggestions as users type into a search box. The system should support multiple entity types (such as stock symbols, product names, help documentation, and common search queries), return results quickly enough to feel instant, and incorporate both popularity signals and user-specific context.

Your design should address:

  • API contract: How clients request suggestions and what the response looks like
  • Data structures and indexing: How you store and retrieve prefix matches efficiently
  • Ranking approach: How you order results using popularity, relevance, and personalization
  • Latency requirements: Achieving sub-100ms P95 end-to-end latency
  • Caching strategy: Where and how you cache to reduce load and improve speed
  • Freshness: Getting newly created entities into the index quickly
  • Scale: Supporting thousands of queries per second with millions of searchable items
  • Failure modes: How the system degrades when dependencies are slow or unavailable
  • Privacy and compliance: Ensuring user data is handled appropriately

State your assumptions about traffic volume, corpus size, and acceptable trade-offs. Explain the reasoning behind your choices and identify the most critical bottlenecks.

Hints

Hint 1

An in-memory prefix structure that precomputes top candidates at each node eliminates expensive traversals at query time.

Hint 2

Separate the global ranking from the personalization layer so you can cache aggressively at the edge while still tailoring results per user.

Hint 3

Use timeouts and fallback paths: personalization should enhance results, not block them when the user service is slow.