KatInterview

Build a Real-Time Query Suggestion Platform

System DesignModel answer
HardModel answerSystem Designautocompletelow-latencycaching

Last updated

Design a scalable service that returns ranked autocomplete suggestions as users type search queries, handling billions of requests per day with sub-100ms latency.

You're tasked with building a query suggestion platform that powers autocomplete for a high-traffic search application. When users type into the search box, your system must return relevant completions instantly.

Design a solution that addresses:

  1. Requirements and scope: What core features must the system support? Consider completion matching, how results should be ordered, whether suggestions should adapt to individual users, and how quickly new popular queries should appear.

  2. API contracts: What endpoints would you expose? Consider both the user-facing query interface and any administrative or ingestion APIs needed.

  3. Data architecture: How would you organize and persist the suggestion corpus? What about auxiliary data like user activity or popularity metrics?

  4. Lookup performance: How do you achieve millisecond-scale prefix matching across millions of possible completions? What data structures and indexing strategies work at this scale?

  5. Result ordering: How would you incorporate signals like query frequency, current trends, geographic relevance, and personal search history into a scoring function?

  6. Operations at scale: How does the system handle continuous updates from user activity, maintain fresh indexes, invalidate stale cache entries, and serve hundreds of thousands of queries per second?

  7. Design trade-offs: What compromises would you make between response speed, memory footprint, result freshness, and engineering complexity?

Walk through your design choices, justify architectural decisions with concrete numbers, and discuss failure modes and mitigation strategies.

Hints

Hint 1

Think about immutable index snapshots vs. streaming updates—which signals need real-time processing?

Hint 2

Consider the memory footprint of storing precomputed results per prefix vs. computing them on demand.

Hint 3

Edge caching works well for short prefixes that generate most traffic but contain least user-specific signal.