KatInterview

Building a Click-Optimized Search Suggestion Engine

Machine LearningModel answer
HardModel answerMachine Learningml-system-designsearch-suggestionsctr-prediction

Last updated

Design a production ML system that proposes search suggestions as users type, ranking them for clicks while controlling bias, safety, latency, and long-term search quality.

Task

You are asked to design a system that generates and ranks suggested search queries for a large consumer product. Suggestions appear in three places: as-you-type autocomplete, related-search chips on a results page, and zero-prefix suggestions on an empty search box. The system should maximize the click-through rate (CTR) on suggestions without hurting the quality of the search experience.

Walk through an end-to-end design and cover each of the following areas:

  1. Objectives and constraints. Precisely define how CTR is measured, plus latency and throughput targets, availability, language and locale coverage, and guardrail metrics (search success, abandonment, safety, privacy).
  2. Architecture. The online request path and the offline/streaming data platform that supports it.
  3. Logging and labels. Impression and click event schema, attribution windows, how positives and negatives are defined, position and propensity logging, and data-quality handling.
  4. Features. Text, embedding, popularity and recency, personalization, context, and presentation features, and how you keep online and offline values consistent.
  5. Candidate generation. Several complementary sources, such as prefix matching, trending queries, embedding-based nearest neighbors, co-click graphs, and a generative model.
  6. Ranking. Multi-stage ranking, loss choices (pointwise, pairwise, listwise), calibration, and a final re-ranking step for diversity and safety.
  7. Training and serving. Retraining cadence, and a serving stack that fits the latency budget.
  8. Exploration and debiasing. Bandit approaches, propensity logging, and correcting for position, selection, and popularity bias, including feedback loops.
  9. Evaluation. Offline metrics, counterfactual estimators (IPS, SNIPS, doubly robust), and online experiment design (randomization, power, guardrails, ramp-up).
  10. Personalization and cold start. Signals used, new users, new queries, new markets, and diversity or coverage controls.
  11. Safety and privacy. Blocklists, classifiers, PII handling, regional policy, and compliance.
  12. Scale, reliability, and iteration. Sharding, graceful degradation, and what you would do after launch.

State your assumptions (traffic, latency, languages) up front, and call out the trade-offs you are making.

Hints

Hint 1

Start by separating the three surfaces and defining an impression as 'actually rendered and visible'. Then treat the system as recall, then rank, then re-rank, and note that raw CTR can be gamed unless you pair it with a search-success guardrail.

Hint 2

Because users only click what they see, and top positions get clicked more regardless of quality, log the position, the candidate set, and the probability with which each item was shown. Those propensities power both debiased training and counterfactual evaluation.

Hint 3

Work backwards from the latency budget: allocate milliseconds to features, parallel recall, a light ranker, a heavy ranker, and re-ranking, then decide what must be precomputed or cached (hot prefixes, user embeddings, generative outputs).

Hint 4

Keep a calibrated pointwise click head even if you use a listwise loss, since bandits and score blending need real probabilities. Reserve a small exploration slot so new candidates can collect unbiased feedback.