Skip to content

Search autocomplete system design interview: a worked guide

Design typeahead suggestions for a search box. The central choices are what counts as a match, how to rank a small candidate set, how often to refresh it, and what query data is safe to retain. This is an interview proposal with illustrative assumptions, not a description of a search company's private architecture.

Updated October 13, 2026

Clarify what autocomplete must return

Ask whether the box completes a prefix, searches for terms that contain the input, or suggests full queries. Prefix completion is a narrower problem than general search. For this design, assume a public product-search box that returns up to eight query suggestions after the user types two characters. Results are scoped to a locale, with no personal history or account-specific ranking.

  • Return useful suggestions before the user submits a search.
  • Keep the response within an agreed interactive latency target, such as 100 ms at p95.
  • Reflect new, removed, or blocked suggestions within a stated freshness window.
  • Do not expose a rare or sensitive query because one person typed it.

Treat the latency and freshness numbers as interview assumptions. Ask the interviewer to change them before choosing a storage or update strategy.

Estimate requests from typing

Suppose 10 million people search each day, each makes eight searches, and the client sends five eligible prefixes per search. That gives 400 million suggestion requests per day, or about 4,600 requests per second on average. If peak traffic is five times the average, size the read path for about 23,000 requests per second. These are round interview inputs, not measured product traffic.

The result explains why the client should debounce keystrokes and stop requests for prefixes that are too short. It also gives a starting point for cache sizing. Next, ask how many distinct suggestions exist, how many are active in each locale, and how quickly popularity changes. Those answers drive index size and refresh work.

Separate query serving from suggestion building

Keep typing requests off the pipeline that learns which suggestions are useful. The online path reads a versioned index. A separate batch or streaming pipeline validates candidate phrases, updates scores, and publishes a new index snapshot.

  1. The browser normalizes the prefix, waits briefly for typing to pause, and sends the locale.
  2. An edge or API layer checks request size, rate limits callers, and checks a cache for the prefix.
  3. A suggestion service reads matching candidates from the locale's prefix index.
  4. The ranker filters blocked candidates, orders the remaining suggestions, and returns at most eight.
  5. A separate pipeline aggregates approved query activity and publishes index versions.

Cache by normalized prefix and locale. A short expiration keeps common prefixes cheap to serve, while index versioning lets every region switch to a complete snapshot instead of seeing a half-written update.

Choose the index for the matching rules

A trie or finite-state transducer fits exact prefix completion. It can keep a compact, read-optimized map from a prefix to likely completions. The serving path is predictable, but ranking, frequent updates, and multi-locale data need a deliberate design.

An inverted search index with edge n-grams or a search-as-you-type field fits richer matching, such as matching a prefix at the start of each word. It shifts more work to indexing and uses more index space. OpenSearch documents prefix matching, edge n-grams, search-as-you-type, and completion suggesters as separate approaches. Its completion suggester stores suggestions in a finite-state structure for prefix lookup. Read the OpenSearch autocomplete guide.

Redis sorted sets can also support a lexicographic prefix range when members share the same score. That gives a simple index for a bounded suggestion set, but returning candidates in popularity order requires a second ranking step. See the Redis lexicographical index pattern.

Start with a completion structure if the requirement is prefix-only and the candidate set is curated. Add an inverted index only if the prompt needs infix matching, typo tolerance, or richer filters. Do not choose a search cluster just because the feature contains the word search.

Rank candidates without hiding the trade-off

A simple score can combine recent query count and longer-term count. For example, use a weighted sum of the logarithms of each count, then apply explicit boosts for freshness and penalties for stale or low-quality phrases. The logarithm prevents a single extremely popular phrase from crowding out every alternative.

Normalize accents and case for matching, but keep the display text users expect. Filter by locale, policy, and product availability before ranking. If you add personalization, define its data source and deletion behavior separately. The base design should still work without it.

A daily batch update is simpler and makes the index easy to publish atomically. A streaming update reflects new trends sooner, but it adds ordering, deduplication, and rollback concerns. Choose the freshness target first. Keep a previous index snapshot available so a bad update can be rolled back.

Keep private and abusive queries out

A query typed by one person is not automatically a good suggestion for everyone. Aggregate counts before building the shared index, apply a minimum-volume threshold, and suppress phrases that may expose personal or sensitive information. Keep raw query retention short and separate it from account identity. The product's privacy policy should say what the pipeline stores.

Add a moderation path for slurs, spam, impersonation, and queries that point to unavailable products. A removal should invalidate cached results as well as the source index. Rate limits and a maximum prefix length also limit abuse and prevent large range scans.

Explain what happens when the index fails

The latest index is malformed
Keep serving the previous verified snapshot and stop promotion.
A region loses its index
Use a local cached snapshot or route to a healthy region. Search still works without suggestions.
A prefix is unusually popular
Serve it from cache, enforce request limits, and bound the number of candidates examined.
A suggestion must be removed
Publish a tombstone or denylist update, purge matching cache entries, and verify each region applied it.
Popularity data is delayed
Keep serving the last good ranking. Do not block typing on the aggregation pipeline.

Practice the connected interview skills

Use the caching guide to reason about hot prefixes and stale results. Use the rate limiting guide to protect the API. Then run a timed system design mock interview and explain why the matching method fits the prompt.

This walkthrough is original practice material. Its example targets and architecture choices are assumptions to discuss in an interview, not claims about a named company's production system.

Common follow-up questions

How do you design search autocomplete in a system design interview?
Clarify whether suggestions complete a prefix or search across terms, set latency and freshness targets, then estimate requests from users and keystrokes. Build a bounded prefix index, rank candidates using recent and long-term popularity, cache common prefixes, and state how you suppress sensitive or abusive suggestions.
Should autocomplete use a trie or a search engine?
It depends on the query and update needs. A trie or finite-state transducer can serve prefix lookups from a compact in-memory structure. A search engine with edge n-grams or a search-as-you-type field supports richer matching at the cost of more index work and storage. Compare these choices against the required matching, ranking, and freshness behavior.
How should autocomplete rank suggestions?
Use a small, explainable score based on recent and long-term popularity, with freshness or editorial adjustments only where the product needs them. Apply locale and policy filters before returning results. Keep the score components measurable so the team can change them without rebuilding the query path.
How do you protect privacy in autocomplete?
Avoid storing a person's typed prefix with their identity unless personalization is a stated requirement. Aggregate query counts, suppress low-volume or sensitive phrases, limit retention of raw queries, and filter unsafe or abusive suggestions before they reach the index.