The interview question

Return useful suggestions as a user types into a search box.

Serve fresh prefix suggestions with predictable latency, careful normalization, and bounded personalization.

01. Define the prefix contract

Clarify languages, typo tolerance, minimum prefix length, personalization, and the number of suggestions. Start with popular eligible queries or catalog entities. A prefix data structure with precomputed top candidates can provide a straightforward baseline.

Normalization must match the product’s language requirements. Case folding and accent handling may improve matching but can merge terms users consider different. Preserve display forms separately from normalized lookup keys, and avoid assuming bytes, code points, and visible characters are interchangeable.

02. Design offline and online paths

Typed prefix
Candidate lookup
Eligible suggestions

An offline pipeline aggregates eligible query statistics, removes unsuitable suggestions, and builds a versioned prefix index. The online service retrieves candidates, applies current eligibility rules, optionally reranks for context, and returns a small response. Publish snapshots atomically so workers never load a half-built index.

Recent trends can live in a smaller update layer, merged with stable candidates. Define score normalization across layers; otherwise a raw count from one time window can overwhelm a rate from another. Keep a fallback snapshot if the update layer fails.

03. Estimate traffic and caching

Assume 100,000 active typists each generate one request every 500 ms. That is 200,000 requests per second before debouncing or caching. A short debounce and cancellation of superseded requests reduce wasted work, but the server must still bound work already in progress.

Popular short prefixes are hot keys. Cache shared candidates by locale and prefix, then apply limited personalization afterward. Do not cache private user history in a shared entry. Responses should include the queried prefix or request sequence so clients can ignore late results for older input.

04. Evaluate speed and usefulness

Measure end-to-end response latency, suggestion acceptance, successful subsequent searches, and coverage across languages and rare prefixes. Raw click-through can favor misleading popular terms. Review sensitive or harmful suggestions through an explicit content policy and maintain fast removal capability.

Follow-up: a term must disappear immediately but snapshots refresh hourly. Add an authoritative suppression layer checked at serving time, with its own freshness contract. General ranking freshness and urgent removal do not need the same mechanism.

Practice the follow-up

Self-review

Explain how the client prevents a slow response for “ca” from replacing a newer response for “camera.”

Connect this to search ranking.

Sources & further reading

Elasticsearch: search-as-you-type. The interview scenario, calculations, and proposed design choices are illustrative.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.