Skip to main content

Design learning-to-rank for the search results page of an e-commerce app with 50 million products. Results must be returned within 200 milliseconds.

System design · Pro 2

Short answer

Clarify what success means: clicks, add to cart, purchases, and how to handle queries with no results. Then: query understanding, retrieval that combines keyword and embedding search to get about a thousand candidates, a learning-to-rank model on query, product and user features, business rules, labels from click logs corrected for position bias, then offline NDCG and an A/B test.

Deeper answer

Clarify the goal first. Purchases per search is a better target than clicks, with guardrails such as the rate of searches with no results and latency. Ask about languages, spelling mistakes and mixed Hindi and English queries, because these shape query understanding.

Data flow: the query is normalised, spell-corrected and classified into a category. Retrieval combines an inverted index for exact terms with embedding search for meaning, and returns about a thousand candidates after filters such as stock and delivery area. A learning-to-rank model, often gradient-boosted trees with a pairwise or listwise loss, scores candidates on text match, product quality, price, popularity and user signals.

Labels come from click logs, but users click higher positions more, so raw clicks carry position bias. Correct for this with position as a training feature that is fixed at serving time, or with a small share of randomised results.

Trade-offs: a neural reranker on the top 50 improves relevance but adds latency and cost. Evaluate offline with NDCG, then an A/B test. At scale, the long tail of rare queries and the freshness of price and stock break first.

What a strong answer covers

Answer it out loud in the mock interview about 2.5 min

Follow-ups to expect

Common mistakes

Learn it

ML interviews

Practice System design questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.