</> MAANG.io
system design · 301

Advanced

Master system design interviews with scalable architecture patterns, distributed systems, and real-world design challenges.

0/480 solved 0% complete

Section 8: Four Miles, Not Forty Million - Deep Dive: Local Search & Ranking

Executive Summary: Search is where this marketplace spends its compute: 10,500 queries a second at peak against 40 million active listings. We build Daniel's query, route it by region so it reaches one shard instead of all of them (roughly 28 search nodes instead of 126), rank the results, handle near-empty rural queries, paginate without offsets, and split a 300 ms p99 budget.

The interviewer turns back to the whiteboard: "It's 7:52 pm on Sunday. Daniel types 'road bike', 10 miles, under $500. Walk me through what happens."

"Two problems: which shards should see this query, and in what order do matches come back? Routing decides cost; ranking decides whether Daniel finds Maya's Trek."

The Query: Filters Narrow, Scoring Ranks

{
  "query": { "bool": {
    "must":   [{ "multi_match": { "query": "road bike", "fields": ["title^3", "description"] } }],
    "filter": [
      { "geo_distance": { "distance": "16km", "location": { "lat": 30.2560, "lon": -97.7500 } } },
      { "range": { "price_cents": { "lte": 50000 } } },
      { "term":  { "category_id": 412 } }
    ]
  }},
  "size": 20
}

Only the text match is scored, in must. Everything else goes in filter context: filters are yes/no, so scoring them is wasted work; they can be cached per segment once they recur (category terms and price presets do; free-form caps and fresh small segments don't); and they shrink the candidate set before scoring. The limit: the geo circle is centered on each buyer, so it rarely repeats and caches poorly.

There's no status filter. The index holds active listings only, so pending, sold and removed items are absent rather than hidden. When Maya marks the bike sold, the indexer deletes the document.

Sign in to continue reading

The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.

Sign in to read the full lesson

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.