The interview problem

Practice prompt

Design typo correction for a marketplace receiving 10,000 searches per second. Queries include ordinary words, new brands and exact product codes. The service must choose among preserving the query, offering a suggestion and automatically correcting it. Prevent a popular interpretation from erasing a rare but valid intent.

Original ML-design practice, not a reported interview. Workload, scores and evaluation counts are hypothetical. Sources retrieved September 28, 2026; interview date not applicable.

1. Define the decision and its cost

Correct spelling while preserving the intended entity and constraints. This differs from semantic rewriting: replacing a term with a related concept can change the request even when it produces attractive results. Keep the unmodified input and include it in every candidate set.

Use three actions. Preserve when evidence is weak or an exact identifier matches. Offer “Did you mean…” when a plausible alternative exists but intent is uncertain. Auto-correct only when held-out evidence supports a sufficiently low harmful-correction rate, with an obvious way to search the original text.

Define success as improved task completion subject to a false-correction guardrail. More result clicks alone can reward plausible but wrong replacements. Report results separately for ordinary language, catalog identifiers, new entities, languages and short queries.

2. Bound candidate generation before ranking

query → locale-aware tokenization + exact-entity lookup
      → bounded edit candidates + original query
      → candidate scoring → action policy
      → authorized retrieval → original-query fallback

Build candidate vocabularies from permitted catalog fields and carefully filtered query data. Generate likely substitutions, deletions, insertions and transpositions with language-appropriate handling. Do not blindly lowercase or strip punctuation from case-sensitive codes. Retain a protected exact-match representation alongside text-search normalization.

For a baseline, cap candidates at 20 per query and limit edit distance according to token length. One edit can completely change a two-character code. Use an index or finite-state structure rather than enumerate every possible string. Model token splits and joins separately; independent token correction can damage multiword entities.

Candidate retrieval should be scoped to the tenant and authorization boundary. An inaccessible document's vocabulary can itself leak information through a suggestion. Apply the same visibility rules to suggestions as to results; keep permission-sensitive caches scoped and invalidated.

3. Explain the noisy-channel baseline

For observed query q and intended candidate c, rank using a language prior and a typing-error likelihood: P(c) × P(q | c). In log space this becomes a sum. Phrase context can help distinguish candidates whose isolated word frequencies look similar. The classic noisy-channel formulation is a baseline, not evidence that its scores are calibrated action probabilities.

Consider this deliberately small, two-candidate model for a catalog code “axion” and common word “action”:

CandidatePriorP(q = axion | c)Product
axion, preserve0.000020.980.0000196
action, replace0.020.0020.00004

The popular word wins by about 2.04×. Normalizing these two products assigns it about 67.1% of the restricted candidate mass. That is not a real-world 67.1% probability of correct intent: the example omits other hypotheses and assumes reliable priors and error likelihoods. A confirmed exact code is strong contextual evidence that this generic prior has ignored.

Use an exact-entity guardrail and features such as query context, entity type, candidate edit pattern, recency and original-result quality. A trained ranker can combine these signals; a separately evaluated decision model controls intervention. A high score margin is useful evidence, but not automatic proof of confidence.

4. Work through an intervention threshold

Suppose p is a calibrated probability that replacing the query is appropriate. Assume for this calculation that either the proposed replacement is the intended query or the original is already correct. In this simplified binary decision model, a wrong replacement costs 20 units and leaving a real typo uncorrected costs one unit. Ignore other costs for this example:

expected loss(replace) = 20 × (1 − p)
expected loss(preserve) = p
replace only if 20(1 − p) < p
therefore p > 20/21 ≈ 95.24%

This threshold depends on the assumed costs and calibration. It must not be applied directly to the two-candidate score normalization above. Offering a suggestion has its own discovery and interaction costs and needs a separate comparison. Exact identifiers can use a stricter policy regardless of aggregate calibration.

5. Build labels that do not merely copy past behavior

Reformulations followed by a successful outcome are useful weak labels, but users also change their mind. An observed sequence is not proof of a typo. Filter obvious navigation and intent changes, then have adjudicators label a sample with catalog context and the original query available.

Keep valid, unusual queries as negative examples. Synthetic keyboard errors improve candidate coverage but do not reproduce all natural errors, speech transcription mistakes or multilingual usage. Evaluate on real, independently labeled queries as well.

Split by time, prevent near-duplicate sessions from crossing splits, and separately test newly introduced entities. Build dictionaries and popularity features using only information available before each evaluated query. A future catalog snapshot can make the cold-start problem disappear artificially.

6. Calculate quality on the right denominator

On an original labeled set of 10,000 queries, suppose 1,000 contain an intended typo. The service auto-corrects 600 queries: 570 appropriately and 30 harmfully.

auto-correction precision = 570 / 600 = 95%
typo recovery by auto-correction = 570 / 1,000 = 57%
harmful correction per all queries = 30 / 10,000 = 0.3%

If all 30 harmful changes affect the 9,000 originally valid queries, the valid-query corruption rate is 30/9,000 ≈ 0.333%. State that extra assumption; harmful changes can also send an already misspelled query to the wrong entity. These aggregate values do not establish the threshold model's calibration or performance on rare codes.

For another policy on the same set, suppose it changes 300 queries, of which 297 are appropriate and three harmful. Precision improves to 99%, while recovery falls to 29.7%. Compare this trade-off with suggestions and downstream task success. Measure candidate recall separately: a ranker cannot recover an intended entity that generation omitted.

Run a controlled rollout with original-query escape rate, exact-code success, successful sessions and latency guardrails. Preserve a holdout to avoid training only on the behavior produced by the correction policy itself.

7. Budget latency and search amplification

At 10,000 queries/s and 20 candidates, the scoring stage sees at most 200,000 candidate evaluations/s if every query invokes it. If exact matches and straightforward queries bypass correction for 80% of traffic, the remaining budget is 40,000 evaluations/s. These are counts, not measured hardware capacity.

Do not execute full document retrieval for all 20 candidates. Score cheaply, then validate at most the top two alternatives. At 2,000 correction queries/s this adds up to 4,000 retrievals/s, in addition to the 10,000 original searches if the baseline always runs. Cache public vocabulary candidates by normalized query, locale and dictionary version; keep user-specific authorization out of shared cache entries.

Use a fixed correction deadline. If the scorer or dictionary is unavailable, preserve the original search. An empty result set is not permission to invent a replacement. A candidate matching some documents is also not proof that it matches the user's intent.

Failures, follow-ups and self-review

  • New brands disappear: examine dictionary freshness and exact-entity bypasses.
  • Popular words dominate: inspect the prior and evaluate tail entities separately.
  • Suggestion reveals private content: scope vocabulary generation and caches by access rights.
  • Offline wins reverse online: examine weak-label bias, policy feedback and original-query escape behavior.
  • Latency spikes: cap candidates, phrase combinations and retrieval validation, then fail open to the original query.

Follow-ups: How would you handle transliteration, ambiguous spaces, mixed languages or voice input? Which errors should be corrected automatically? How would the decision cost change for a product code versus a general browsing query?

A strong answer separates generation, ranking and intervention. An excellent answer retains the original intent, calculates the precision–coverage trade-off, protects rare entities and measures harmful corrections. A solution that maximizes dictionary frequency or nonempty results without an abstention policy is incomplete.

Sources and attribution

Retrieved September 28, 2026. Architecture, catalog-code scenario, thresholds and evaluation counts are original. This is not evidence of a question recently asked by any named company. Continue with search ranking and time-correct evaluation.

Continue your preparation

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