How would you design a search ranking system for a large e-commerce site?

ML system design, Case studies
Level L4 Advanced. Length Long. Nature Th+Mat Both.

What's being asked

Whether you can design an end-to-end multi-stage search pipeline combining lexical and semantic retrieval, learning-to-rank models, debiased click labels and strict latency budgets.

Key idea

E-commerce search must balance exact-match precision (SKU, or stock-keeping unit, codes, brands and attributes) with semantic recall (synonyms and intent) inside a tight latency budget. A production system pairs hybrid lexical BM25 (Best Matching 25) plus dense vector retrieval with a staged ranker culminating in LambdaMART (gradient-boosted trees trained on LambdaRank gradients) or a neural re-ranker, trained on human judgements and debiased clicks and validated via offline NDCG (normalised discounted cumulative gain) and online interleaving.

Steps

  1. Clarify requirements and scale: confirm query volume, catalogue size, personalisation scope and strict filters (in-stock, price, delivery location). Back-of-envelope latency and throughput budget: for a 2×107-item catalogue at 10,000 QPS (queries per second) peak with a 150 ms end-to-end SLA (service-level agreement), allocate 15 ms to query understanding, 35 ms to parallel hybrid retrieval (top 1,000 items), 40 ms to L1 (first-stage) fast ranking (1,000→100), 40 ms to L2 (second-stage) LambdaMART/deep re-ranking (top 100) and 20 ms to business rules and network overhead (15+35+40+40+20=150 ms). Stage L2 scores 10,000×100=106 query–product pairs/s instead of 10,000×2×107=2×1011.
  2. Define the ML objective and metrics: in e-commerce, relevance alone is not enough—a result must match query intent and convert (add-to-cart, purchase) without causing returns. Assign graded relevance labels y∈{0,1,2,3,4} combining relevance and purchase/click utility. Offline, optimise and evaluate NDCG@k (normalised discounted cumulative gain at rank k) and MRR (mean reciprocal rank), plus zero-result rate. Online, track query reformulation rate, add-to-cart rate, conversion rate, GMV (gross merchandise value) per search and p99 (99th-percentile) latency.
  3. Construct labels from human judgements and debiased clicks: expert human judgements provide clean relevance grades on head, torso and tail queries, but are too small and static to cover every product or conversion signal. User click and purchase logs give massive coverage, yet suffer from position bias (top ranks get clicked regardless of relevance) and presentation bias. As worked through in the position-bias entry (`position-bias-inverse-propensity-weighting`), correct position bias using IPW (inverse propensity weighting), which reweights observed clicks by the inverse examination probability estimated via result randomisation or click models, and avoid trusting raw clicks without controlling for rank.
  4. Design query understanding and features: query understanding handles spelling correction, tokenisation, synonym expansion, attribute extraction (brand, size, price range) and intent/category classification. Features span four groups: (1) query–document text match: BM25 scores across title, brand and description, exact phrase match and cosine similarity of dense query–product bi-encoder embeddings; (2) product quality and popularity: historical CTR (click-through rate), conversion rate, rating, review count, return rate and price competitiveness; (3) context and personalisation: user category affinity, location and price sensitivity; (4) query-level aggregates, such as category match confidence. Check point-in-time feature logging so conversion rates do not leak future orders.
  5. Build hybrid retrieval and learning-to-rank models: retrieve candidates in parallel using lexical BM25 on an inverted index (essential for exact model numbers, brands and rare tokens) and dense bi-encoder embeddings indexed with HNSW (Hierarchical Navigable Small World) ANN (approximate nearest neighbours) for synonyms and long-tail queries, fusing lists via reciprocal rank fusion or a learned pre-ranker. For ranking, contrast the three LTR (learning-to-rank) paradigms: pointwise (predicts relevance/conversion independently), pairwise (RankNet, which minimises inversions between item pairs) and listwise/metric-aware (LambdaRank and LambdaMART, Burges 2010). LambdaMART scales pairwise gradients by ∣ΔNDCG∣ from swapping two items and fits GBDT (gradient-boosted decision trees) to those gradients, directly targeting top-rank quality on tabular match and popularity features.
  6. Design serving architecture and latency trade-offs: execute query understanding once, fan out BM25 and ANN retrieval shards in parallel with hard inventory/eligibility filters, score 1,000 candidates with a fast linear/shallow L1 model, hydrate dense item/seller features for the top 100 only, and run L2 LambdaMART (or a compact neural cross-encoder on the top 20–30) plus business-rule re-ranking (brand diversity, sponsored-slot separation, stock guards). Interviewers will probe exact lexical vs semantic recall trade-offs (e.g. dense embeddings retrieving wrong sizes/part numbers) and when to trigger expensive cross-encoders.
  7. Evaluate and launch via interleaving and A/B tests: evaluate offline on stratified query buckets (head, torso, tail, attribute-heavy) using NDCG@10 and zero-result rate. Before a full A/B test, run team-draft interleaving on a small live slice: interleave results from the production ranker and candidate ranker in one list and see which gets more clicks—interleaving needs far fewer queries than an A/B test to detect ranking differences. Follow with a user-randomised A/B test to measure downstream conversion, GMV and query-abandonment guardrails.
  8. Monitor and iterate: track zero-result queries, long-tail query latency, BM25-vs-dense recall overlap, click-position distributions and seasonal shifts (holidays, new product launches). Periodically refresh human judgement sets and propensity models, retrain embeddings on hard negatives mined from impressed-but-unclicked items, and be ready to discuss relevance-vs-revenue trade-offs when an interviewer asks how to balance conversion optimisation against pure topical match.

Common mistakes

How long your answer should be

8–10 minutes; walk cleanly through hybrid retrieval, RankNet/LambdaMART intuition, debiasing and latency split.

Read this

Previous in ML system design: How would you design an ad click-through rate (CTR) prediction system?
Next in ML system design: How would you design a real-time payment fraud detection system?