Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Typeahead Suggestion Service

Design a low-latency service that returns deterministic prefix suggestions from a large, frequently refreshed phrase catalog.

Problem statement

Design a typeahead suggestion service. For this exercise, assume phrases and prefixes are normalized with Unicode NFKC plus locale-independent case folding, leading and trailing spaces are trimmed, and internal spaces are retained.

A client sends the normalized query prefix after each keystroke and receives up to 10 approved phrases that begin with that prefix. Requests with fewer than two normalized characters return no suggestions.

Rank matching phrases by the count of accepted selection events in the trailing 24 hours, descending, and then by normalized phrase text, ascending.

Assume one billion users issue up to 10 searches per day, or 10 billion searches per day, and provision for 500,000 query requests per second at peak with a highly skewed prefix distribution. The service maintains 50 million active phrases, targets query latency below 100 milliseconds at p99, and targets 99.99% successful-query availability. For this exercise, measure these objectives at the service edge over a rolling 30-day window: latency covers successful valid queries, while availability is the fraction of all valid query requests that receive a response satisfying the query contract. Timeouts, server errors, and overload rejection count as unavailable; invalid requests are outside this denominator. A coherent, explicitly marked fallback may count as available while still missing the separate trend-freshness target. A reproducible batch build publishes a complete popularity baseline at least every five minutes, while a deduplicated streaming overlay makes an accepted breaking trend eligible within five seconds at p95. Each response combines one immutable baseline whose scores end at baseline watermark B with one explicit overlay watermark W. W is the response's effective ranking watermark: for each phrase, the overlay adds accepted events in (B, W] and subtracts events in (B minus 24 hours, W minus 24 hours] as they leave the window. The final score therefore covers exactly (W minus 24 hours, W], and retries against the same baseline and exact W produce the same order.

Selection events carry stable event IDs, duplicate delivery counts only once, and phrase activation and deactivation come from an approved catalog feed.

Design the query path, trie or equivalent prefix index, popularity batch and stream processing, hot-prefix partitioning, caches, replica synchronization, new-node warming and route cutover, version publication, observability, and recovery.

The serving path may fall back to the last healthy baseline and a bounded overlay watermark during an update or dependency failure. Personalization, fuzzy matching, spell correction, advertisements, corpus moderation, and retrieval of full search results are outside scope.

What to build

  1. Return up to 10 active phrases that begin with a normalized prefix of at least two characters.
  2. Order matches by descending accepted-selection count over the trailing 24 hours ending at the response's exact effective overlay watermark, then ascending normalized phrase text, using one compatible published baseline and signed overlay.
  3. Accept deduplicated phrase-selection events and incorporate them into both a reproducible batch baseline and a bounded low-latency trend overlay.
  4. Make an accepted newly breaking phrase eligible within five seconds at p95 without mixing incompatible baseline versions, overlay watermarks, or replica state.
  5. Activate and deactivate approved phrases through coherent version publication, never expose a partial build, and continue serving the last healthy version when an update or dependency fails.

At scale

  • For this exercise, assume 50 million active approved phrases in the serving corpus.
  • For this exercise, assume one billion users issue up to 10 searches per day, or 10 billion searches per day, and provision for 500,000 typeahead requests per second at peak with a highly skewed prefix distribution.
  • Target query latency below 100 milliseconds at p99 and 99.99% successful-query availability. For this exercise, measure at the service edge over a rolling 30-day window; a coherent marked fallback may satisfy availability without satisfying trend freshness.
  • For this exercise, assume a complete popularity baseline is published within five minutes and an accepted breaking-trend signal becomes eligible within five seconds at p95 through a bounded streaming overlay.