Crawl, index and rank billions of pages, and answer a query in milliseconds.
“Design a web search engine, like Google. Someone types a few words, and we show the ten best pages in a fraction of a second.”
It is short on purpose. Your first job is to make it specific.
| What they check | Why it matters |
|---|---|
| Splitting offline from online | Building the index (slow, huge, batch) and answering a query (fast, small, live) are two different systems. Strong candidates draw the line first and say what crosses it. |
| Sharding an index | The index is far too big for one machine. Document partitioning versus term partitioning, and the cost of asking every shard, is the heart of the question. |
| Tail latency | A query that waits for 1,000 shards is as slow as the slowest one. This is the follow-up that separates senior candidates from the rest. |
| Ranking in stages | You cannot run an expensive model on billions of pages. Cheap retrieval first, expensive reranking on a few hundred candidates second. |
| Freshness, quality and honesty | News must appear in minutes, spam must be demoted, and every shortcut has a cost. The interviewer wants the costs said out loud. |
A search engine is two systems joined by an index. Offline, a pipeline crawls pages, cleans them, scores them and builds an inverted index cut into about 1,000 shards, each held by many replicas. Online, a query is understood, sent to every shard, and the best few hundred hits are merged, reranked and shown with snippets.
| Step | Minutes | What to get done |
|---|---|---|
| 1. Clarify | 4 | Web scale or one site, how fresh, how fast, what the results page looks like, what is out of scope. |
| 2. Estimate | 3 | Corpus size, index size, shard count, queries a second, and the fan-out cost of asking every shard. |
| 3. API and data | 4 | One search call, the shard RPC, and the forward index, inverted index and per-page signals. |
| 4. High-level design | 8 | Offline pipeline, online serving tree, and where the index is stored and swapped. |
| 5. Deep dives | 16 | Index partitioning, tail latency, ranking, freshness, and quality and spam. |
| 6. Scale and failures | 7 | Shard loss, bad index builds, hot queries, cost, and multi-region. |
| 7. Wrap up | 3 | Recap, trade-offs, what you would build first and what you would leave for later. |
| Ask | Why you ask it | Typical answer | How it changes the design |
|---|---|---|---|
| Is this web-scale search over billions of pages, or search inside one website? | One site fits on a few machines and a single Elasticsearch cluster. The web does not. | Web scale: about 50 billion pages. | The index must be sharded across thousands of machines. This is the whole problem. |
| What does a result page show? | Ten links with a title and a snippet needs the text of the page at query time, not just the index. | Ten results, each with a title, a link and a snippet of text around the matching words. | We need a document store for snippets, separate from the index. |
| How many queries a second, and how fast must the answer be? | The query rate decides the number of replicas. The latency target decides how we handle slow shards. | About 100,000 queries a second at peak. Under 200 ms typically, 99% under 500 ms. | Fan-out to every shard at that rate is huge, so we need replicas, caching and tail-latency controls. |
| How fresh must results be? | A new news story in 5 minutes needs a streaming path. A new blog post in a week does not. | Most pages within days. News and trending topics within minutes. | Two index tiers: a large main index rebuilt in batches, and a small real-time tier for fresh content. |
| How good must ranking be, and who judges it? | Ranking is the product. It decides whether to run an expensive model, and how. | Very good. Relevance is measured by human raters and click data. | Two-stage ranking, and an evaluation and A/B testing setup. |
| Do we need to handle many languages? | Languages change tokenizing, stemming and which shards can answer. | Yes, but start with one language and design for more. | A language field per document, and per-language analysis in the index and the query. |
| Is personalization in scope? | Personalization needs user data and a different cache strategy, since results are no longer shared. | No. Use location and language only. | Result caching stays simple: the same query gives the same page for everyone nearby. |
| What about spam, adult content and legal removals? | These are part of the product, and they shape the index and the ranker. | Yes: demote spam, support safe search, and honour removal requests. | Quality and spam scores per page, a removal list applied at serving time. |
| Do we build the crawler here? | Crawling is a large problem of its own. | No. Assume a crawler delivers pages. We build indexing, serving and ranking. | We start from a stream of fetched pages and link data. See Design a Web Crawler. |
| What availability do we need, and is a slightly incomplete answer acceptable? | If partial results are allowed, a slow or dead shard does not have to fail the whole query. | 99.99% available. A good answer from 99% of the index beats no answer. | Per-shard deadlines and partial results are allowed, but must be measured. |
| Assumption | Value |
|---|---|
| Pages in the index | 50 billion |
| Raw page size (HTML), as crawled | 100 KB |
| Extracted text per page | 10 KB |
| Index size compared with extracted text | 20% (after compression) |
| Shard size | 100 GB of index, about 50 million documents |
| Replicas per shard | 10 (for throughput and availability) |
| Queries at peak | 100,000 per second |
| Share of queries answered from the result cache | 40% |
| CPU time per shard call (local top 20) | 3 ms |
| Cores per machine | 32 (so about 10,000 shard calls a second at full load) |
| Pages that change and are re-indexed each day | 1% (500 million) |
| What | Maths | Result |
|---|---|---|
| Raw crawled data | 50B × 100 KB | 5 PB |
| Extracted text | 50B × 10 KB | 500 TB |
| Index size (one copy) | 500 TB × 20% | 100 TB |
| Shards | 100 TB ÷ 100 GB | 1,000 shards, about 50M documents each |
| Machines for the index | 1,000 shards × 10 replicas | 10,000 machines, about 1 PB of index in total |
| Queries that reach the shards | 100,000 × (1 − 40%) | 60,000 per second |
| Shard calls per second (fan-out to all shards) | 60,000 × 1,000 | 60 million per second (100 million with no cache) |
| Load per machine | 60M ÷ 10,000 machines = 6,000 calls/s; capacity 32 ÷ 3 ms ≈ 10,700 calls/s | about 56% busy at peak (94% with no cache) |
| Pages re-indexed per day | 50B × 1%; ÷ 86,400 s | 500 million a day, about 5,800 per second |
| Text to process per day | 500M × 10 KB | 5 TB of new text a day |
| Link graph for PageRank | 50B pages × 50 links each | 2.5 trillion links, about 40 TB at 16 bytes a link |
| Full rebuild of the index, at 10 GB/s | 500 TB of text ÷ 10 GB/s | 50,000 s, about 14 hours |
| Method | Path | Request | Response | Notes |
|---|---|---|---|---|
| GET | /search?q=&lang=®ion=&page= | none | 200 { results: [{ url, title, snippet, score }], partial, tookMs, spell } | page is limited (for example, 10 pages) since deep pages are costly. partial=true when some shards did not answer in time. |
| POST | /internal/shard/query | { terms[], filters, topK: 20, deadlineMs } | { hits: [{ docId, score }], docsScanned } | Root or mid-level aggregator to a leaf. Returns only IDs and scores, not text, so replies are small. |
| POST | /internal/docs/snippets | { docIds[], terms[] } | { items: [{ docId, url, title, snippet }] } | Called only for the final ten. Reads the document store, not the index. |
| POST | /internal/index/segments | { shardId, segmentId, manifest } | 204 | The indexer publishes a built segment. Replicas download and load it, then switch. |
| Store | Key and value | Notes |
|---|---|---|
| Inverted index | term → postings: sorted docIds, term frequency, positions | Per shard, in immutable segments, compressed (delta + variable-length). The main data structure. |
| Forward index / document store | docId → { url, title, extracted text, language, fetchedAt } | Used for snippets and reranking features. Sharded by docId. About 500 TB. |
| Per-page signals | docId → { pageRank, quality, spam, freshness, language } | Computed offline. Small numbers per page, loaded into memory on each shard. |
| URL to docId map | hash(url) → docId | Used by the indexer for updates, dedup and removals. |
| Link graph | docId → outgoing docIds (and anchor text) | Input for PageRank and anchor-text signals. About 40 TB. |
| Result cache | hash(normalised query, lang, region) → top results | Short TTL. Absorbs the head of the query distribution. |
"nearby" -> docIds: [12, 40, 41, 97, 410, ...] (sorted, stored as gaps: 12, 28, 1, 56, 313 ...)
term freq: [ 3, 1, 2, 1, 5, ...]
positions: [[4,19,77], [8], [2,30], [60], [1,5,9,22,40], ...] (for phrase queries)
skip list: every 128 docIds, so an AND can jump ahead| Component | What it does |
|---|---|
| Parse and dedup | Extracts text, links and anchor text from each fetched page, drops exact and near-duplicates (with MinHash or SimHash), and assigns a stable document ID. |
| Link graph and PageRank | A batch job over the link graph computes an importance score per page. It runs offline, a few times a day, and writes one number per page. |
| Indexer | Builds immutable index segments for each shard from the cleaned pages. Publishes a manifest. Replicas download and switch to the new segments. |
| Real-time tier | A small index fed by a stream, holding pages from the last hours. Queried alongside the main index so news appears in minutes. |
| Query understanding | Tokenizes, lowercases, corrects spelling, expands synonyms, and detects language. Output is a structured query. |
| Result cache | Stores the finished top results for popular queries for a short time. The cheapest query is one we do not run. |
| Root and mid-level aggregators | Fan the query out in a tree, collect each shard's top 20, merge them into a global top list, and enforce deadlines. |
| Leaf shards and replicas | Each holds 50M documents' inverted index and signals. Scores locally with a cheap formula and returns IDs and scores. Replicas share the load. |
| Reranker and snippet builder | Rerank the top few hundred with an expensive model and many features. Fetch text for the final ten and cut the snippet. |
The problem: The index is 100 TB, far too big for one machine, and 100,000 queries a second is far too much for one copy. We must decide what each machine holds, and how many machines every query has to touch.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Document partitioning | Each shard holds a subset of documents, with all terms for those documents. A query goes to every shard. | Each shard can answer alone. Adding documents touches one shard. Balanced by construction. A failed shard loses a slice, not a word. | Every query touches every shard (60 million calls a second). The slowest shard decides the latency. |
| Term partitioning | Each shard holds the full postings for some terms. A query goes only to the shards that own its terms. | Fewer shards per query. Less total work for rare words. | A common word has a huge posting list that must be sent across the network to be intersected. Hot terms create hot shards. Adding a document touches many shards. |
| Document partitioning with tiers | Put high-quality, frequently clicked pages in a small, fast first tier. Query the big second tier only if the first does not give enough good answers. | Most queries are answered by a small slice of the index. Saves a lot of machines. | Complex. A page in the wrong tier is hidden. Needs a rule for when to go to the next tier. |
| Hybrid: document-partitioned groups | Group shards into clusters, each a complete index of a slice of the web. A query goes to every shard inside one cluster, and clusters are copies for load. | Natural way to organise replicas and rolling swaps. | Same fan-out inside a cluster. Needs routing and capacity planning per cluster. |
The key advantage is that a shard is self-contained: it can find, score and return its best 20 without talking to anyone. Term partitioning looks cheaper because fewer machines are touched, but the cost moves to the network: the posting list for a common word is tens of millions of entries, and intersecting two of them across machines means shipping megabytes per query.
The price of document partitioning is the fan-out, and we pay it with replicas and a result cache. Ten replicas per shard handle the throughput, and the tail-latency tools in the next deep dive handle the slowest shard. A first tier of the best pages lets most queries stop early.
| Document partitioning | Term partitioning | |
|---|---|---|
| Shards per query | All 1,000 | Only the shards that own the query terms |
| Data sent for one query | 20 hits from each shard (about 320 KB in all) | Long posting lists, megabytes for common words |
| Adding one document | One shard | Every shard that owns one of its terms |
| Hot spots | Rare (a hot document is just one document) | Common: one popular word is one hot shard |
| A shard fails | Lose a slice of the pages (about 0.1%) | Lose all pages that contain those words |
The problem: A query waits for all 1,000 shards. Even if each shard is slow only 1% of the time (a garbage collection pause, a merge, a bad disk), almost every query will meet at least one slow shard.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Wait for everyone | The root waits for every shard to reply. | Complete answers. Simplest. | The slowest shard sets the latency. With 1,000 shards and 1% slow calls, 1 - 0.99^1000 is more than 99.99% of queries. |
| Backup (hedged) requests | If a shard has not replied after a short time (about the 95th percentile of a healthy call), send the same request to another replica and use whichever answers first. | A query is slow only if both tries are slow, about 1% × 1% = 0.01% per shard. Cheap: about 5% extra calls if you hedge at p95. | More load. Only helps when slowness is independent between replicas. Requests must be safe to repeat. |
| Deadline and partial results | Stop waiting at a fixed time and answer with the shards that replied. Mark the answer partial. | A hard upper bound on latency. Often invisible, since the top results rarely come from the one slow shard. | A small share of the index is missing in that answer. Must be measured, and queried for rare pages carefully. |
| Cut the work and the variance | Early termination (stop after enough candidates), caches for posting lists and results, smaller and evenly sized shards, rate limits between GC pauses, and removing noisy neighbours. | Fewer slow calls in the first place. | Ongoing engineering. Never reaches zero. |
The maths is what makes this hard. If one call is slow with probability p, a query over N shards is slow with probability 1 - (1 - p)^N. For p = 1% and N = 1,000, that is 1 - 0.99^1000 = 1 - 0.00004 = 99.996%. For p = 0.1% it is still 63%. Nothing about the average latency shows this. It lives entirely in the tail.
A backup request turns the failure into two independent bad events: the query is slow only if the first try and the backup are both slow, about p × p. For p = 1% that is 0.01% per shard, and over 1,000 shards 1 - (1 - 0.0001)^1000 is about 9.5%. Better, not solved. So we add a deadline as the last safety net: stop waiting, return what we have and flag the answer partial. Together they bring almost every query inside the budget.
| Slow calls per shard (p) | 1 - (1 - p)^1,000: some shard is slow | With a backup: 1 - (1 - p²)^1,000 |
|---|---|---|
| 0.1% | 63.2% | 0.1% |
| 1% | 99.996% | 9.5% |
| 5% | about 100% | 91.8% |
The problem: Billions of pages match a loose query. We cannot run a heavy model on all of them, and relevance is the product: ten wrong links is a failed search.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Text match only (BM25 or TF-IDF) | Score each page by how often and how rarely the query words appear in it, with length normalisation. | Fast and cheap. Works inside the shard on the postings alone. | Easy to spam. Ignores importance, freshness and intent. Many pages match equally well. |
| Text match + link analysis (PageRank) | Add a static importance score per page, from how many important pages link to it. | A strong, query-independent quality signal, computed offline, free at query time. | Can be gamed by link farms. Slow to react to new pages. Says nothing about this query. |
| Two-stage ranking | Stage 1, on each shard: a cheap score (text match + static signals) picks the local top 20. Stage 2, at the root: a learned model with hundreds of features reranks the merged top few hundred. | The expensive model runs on about 300 pages, not billions. The model can change without rebuilding the index. | Stage 1 can drop a page that stage 2 would love. Two systems to tune and evaluate. |
| Heavy model on all matches | Score every page that matches with the learned model. | Best possible ranking. | Impossible at 100,000 queries a second over billions of pages. |
The first stage must be so cheap that it can score every match on a shard, so it uses only the postings and a few stored numbers: a text score such as BM25 (which rewards a rare query word appearing often in a short field, and weights title and anchor text more than body text), plus the static page signals (PageRank, quality, spam, freshness). Its only job is to make sure the best pages are in the top 20 of their shard.
The second stage sees only about 300 candidates, so it can afford a learned model with many features: term proximity, the query's language and region, click history for this query, how fresh the page is, and more. Because it runs after the index, a new model can be tested and rolled out without rebuilding anything.
| Signal | What it measures | Computed |
|---|---|---|
| BM25 on body, title, anchor text | How well the words match, rare words count more, fields are weighted | At query time, from postings |
| Proximity and phrase match | Are the words close together, in order? | At query time, from positions |
| PageRank | How important the page is, from the link graph | Offline, a few times a day |
| Quality and spam score | Is it useful, original and safe? | Offline, with a model |
| Freshness | How recent is it, and does this query want recent pages? | Offline and at query time |
| Click and satisfaction data | Did people click and stay on this result for this query? | Aggregated offline, used by the reranker |
The problem: A full rebuild takes about 14 hours, but a breaking news story must be searchable in minutes. Pages also change and disappear, and replicas must keep serving while the index changes under them.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Rebuild everything on a schedule | Rebuild the whole index every day or week and swap it in. | Simple. Clean, well-compressed index. | Days of staleness. A huge amount of repeated work for the 99% that did not change. |
| Update the index in place | Add and change postings directly in the live index. | Fresh at once. | Needs locks or complex structures, hurts read speed and caching, and is hard to recover after a crash. |
| Immutable segments plus merges | New and changed pages go into small, new, read-only segments. Queries search all live segments. A background job merges small ones into big ones, and deleted pages are marked in a bitmap. | Reads are never blocked. New data is searchable as soon as its segment loads. Crash-safe: a segment is complete or absent. | Queries search several segments. Merging costs disk and CPU. Deletes are logical until a merge. |
| A separate real-time tier | A small, fast index fed by a stream holds only the last few hours of changes. Queries ask both tiers and merge. | Minutes of freshness for the content that needs it, without touching the big index. | Two indexes to operate, and results from both tiers need compatible scoring. |
This is the same idea as an LSM tree, applied to an index: never change a file, only add new ones, and clean up later. A shard has a few large old segments and many small new ones. A query searches them all and merges. A deleted page is marked in a per-segment bitmap and filtered out of results, and its space is reclaimed when the segment is next merged.
For new batches, the indexer builds segments off to the side. Each replica downloads, checks and loads them, and then switches its list of live segments in one step. Replicas are updated a few at a time, so the shard always has healthy copies serving. The real-time tier covers the gap: pages from a news feed or a recrawl of a trending page go straight into it, and fall out of it once the main index has caught up.
| Event | What happens | Visible after |
|---|---|---|
| Breaking news page | Stream to the real-time tier | A few minutes |
| Ordinary page changed | Next batch builds a new small segment | Hours to a day |
| Page removed (legal or spam) | Added to a removal list checked at serving, bit cleared in the segment | Minutes (filtered); space freed at the next merge |
| Ranking signals updated (new PageRank) | Signals file replaced, loaded into memory | Hours |
| New index version | Replicas load it a few at a time, then switch | Rolled out over hours with no downtime |
The problem: The web is full of copies, thin pages and people trying to rank higher than they deserve. If we index everything equally, results fill with duplicates and spam, and ranking signals such as links get gamed.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Index everything, rank later | Keep every fetched page and rely on ranking to push the bad ones down. | Simple, never throws away something useful. | Wastes storage and shard capacity on duplicates and junk. Spam still reaches the top-K of a shard and can crowd out good pages. |
| Dedup before indexing | Drop exact copies (hash of the text) and near-duplicates (MinHash or SimHash fingerprints), and keep one canonical page. | A smaller index and cleaner results. Cheap to do in the batch pipeline. | A wrong near-duplicate match hides a real page. Needs a canonical-page rule. |
| Quality and spam models | Score each page offline for quality and spam (thin content, keyword stuffing, hidden text, link-farm patterns) and store the score as a signal. | Demotes or excludes the worst. Reused by the ranker. | An arms race. Needs training data and review. False positives hurt honest sites. |
| Link-spam resistance | Discount links from suspected farms, ignore marked links (nofollow), and compute trust from known good seed pages. | Protects the strongest signal, PageRank. | More graph computation. Honest links can be discounted by mistake. |
Doing it in the batch pipeline is cheap and shrinks everything downstream: fewer pages to index means fewer shards and cheaper replicas. Exact duplicates are found by hashing the cleaned text. Near-duplicates (the same article with a different header) are found by comparing small fingerprints: MinHash estimates how much two sets of word groups overlap, and pages above a threshold are grouped, with one chosen as the canonical page.
Spam and quality are stored as numbers per page, so the shard score and the reranker can use them. Legal removals and safe-search flags are checked at serving time against a small, fast list, because they must apply in minutes, long before the next index build.
A simplified model with made-up numbers and no random values: each call's time comes from a fixed formula. A healthy shard takes 8 to 14 ms. A slow one (a garbage collection, a merge, a bad disk) takes 150 to 800 ms. The backup goes to a second replica with its own fixed times. The deadline applies to the shard stage only; a query that hits it returns the shards that answered and reports the rest as missing.
| Bottleneck | Fix |
|---|---|
| Fan-out cost (60M shard calls a second) | More replicas, a result cache, a first tier of the best pages that answers many queries early, and posting-list caches. Smaller replies from each shard. |
| Tail latency from one slow shard | Backup requests at about p95, a deadline with partial results, and fewer causes of slowness (GC tuning, throttled merges, spreading maintenance). |
| Aggregator fan-in (about 19 GB/s) | A tree of mid-level aggregators, so no one machine receives 1,000 replies, and shard replies stay as small as IDs and scores. |
| Hot, popular queries | Result cache with a short TTL, and request coalescing so many identical queries trigger only one search. |
| Expensive reranker at peak | Rerank fewer candidates under load, use a smaller model, and degrade to the first-stage order when overloaded. |
| Index growth and cost | Tiering (best pages in a small fast tier, the long tail on cheaper storage), compression, dropping duplicates and junk before indexing. |
| Snippet generation | Fetch document text only for the final ten, cache snippets for popular results, and store text compressed and in sorted blocks. |
| Failure | How the design copes |
|---|---|
| One replica of a shard dies | Other replicas serve. The load balancer stops sending calls to it, and a new replica downloads the segments. |
| All replicas of a shard are down | Return a partial answer missing about 0.1% of the index, flagged partial, and page an engineer. Rebuild from the segment store. |
| A bad index version is rolled out | Roll out to a few replicas first, compare quality and error metrics, and roll back to the previous segments. Keep the last two versions. |
| A query of death crashes shards | Run each query with limits (time, memory, postings scanned), quarantine the query pattern, and isolate crashes so retries do not take down every replica. |
| The result cache is lost | Capacity drops for a while (the fleet would run at about 94% busy). Shed load with rate limits and warm the cache from popular queries. |
| A region goes down | Route to another region, which holds a complete index copy. Capacity planning must allow for losing a region, and results may be slightly staler. |
Offline, pages are parsed, deduplicated, scored with PageRank and quality signals and built into immutable segments for about 1,000 document-partitioned shards, each with 10 replicas, plus a small real-time tier for news. Online, a query is understood, checked against a result cache, fanned out through aggregators to one replica of every shard, merged, reranked by a learned model and given snippets. Backup requests and deadlines protect the tail, and rolling swaps keep the index fresh without downtime.
| Decision | What we gain | What it costs |
|---|---|---|
| Document partitioning | Self-contained shards, easy updates and balanced load. | Every query touches every shard: 60 million shard calls a second. |
| Backup requests and deadlines | A bounded tail, with almost every query inside the budget. | About 1 to 5% extra load, and a small share of partial answers. |
| Two-stage ranking | A strong model runs on 300 pages instead of billions, and can change without a rebuild. | Stage 1 may drop a page that stage 2 would have liked. |
| Immutable segments and a real-time tier | Crash-safe updates, no read locks, and minutes of freshness for news. | Queries search several segments, and merges cost disk and CPU. |
| A result cache | About 40% fewer shard calls and a faster typical answer. | Stale results for a short time, and a capacity hole if the cache is lost. |
| Dedup and quality scoring up front | A smaller index, cleaner results and a harder-to-game ranker. | False positives can hide real pages, and spam is an arms race. |
The part interviewers start with. Say the numbers, and say what the fan-out costs.
The senior-level follow-ups: what is slow, what is broken, and how you know.
Where the product lives. Know what each signal is for, and how you would prove a change is better.
Operating the thing: updates, spam, money, regions, and what you would cut.
A change in requirements is a test of whether you understand why your design looks the way it does.
| New requirement | What changes in the design |
|---|---|
| The corpus is one company's documents (10 million), not the web | A single Elasticsearch or OpenSearch cluster with a few shards is enough. Drop the aggregator tree, tiers and hedging. Spend the effort on relevance and permissions. |
| Results must respect per-user access rules (enterprise search) | Store an access list per document and filter at query time, or shard by tenant. Result caching becomes per user or per group, and ranking cannot leak titles of hidden documents. |
| Freshness must be seconds, for all pages | The real-time tier becomes the main path: a streaming indexer writing small segments continuously, with more frequent merges and higher cost per page. Fewer pages can qualify. |
| Add semantic (vector) search | A second approximate nearest-neighbour index and fan-out, with candidates merged before the reranker. Needs an embedding pipeline and more memory. |
| Ten times the query rate | More replicas and a bigger cache, plus more aggressive early termination and a smaller first tier. Fan-out grows linearly, so the number of shards needs a second look. |
| Add personalization | The same query no longer gives the same page, so the result cache key must include a user segment, or personalise in the reranker only. Needs privacy controls and a feature store. |
| Add image search | A separate index with image features and embeddings, text from surrounding page, and thumbnails in object storage. Same serving pattern, different retrieval. |
| Strict latency of 50 ms at p99 | Fewer, bigger shards and a tiered index with in-memory first tier, a smaller reranker, no second fan-out, and tighter hedging. Quality is traded for speed. |
| Area | Weak | Good | Great |
|---|---|---|---|
| Requirements | Starts drawing boxes, or says 'use Elasticsearch'. | Asks scale, freshness, latency and scope, and states them. | Separates indexing from serving, sets a latency budget and a partial-results policy, and names what is out of scope. |
| Estimation | Skips it, or only sizes storage. | Index size and shard count. | Computes shard calls a second (the fan-out), per-machine load, and uses the cache hit rate to justify the replica count. |
| Index design | A database table with a text column. | An inverted index split across shards. | Document partitioning with reasons against term partitioning, immutable segments, compressed postings and tiers. |
| Tail latency | Not mentioned. | Mentions timeouts and replicas. | Does the 1 − (1 − p)^N maths, uses backup requests and a deadline with partial results, and measures partial answers per shard. |
| Ranking | Sort by keyword count. | TF-IDF or BM25 plus PageRank. | Two-stage retrieval and rerank, offline evaluation, A/B tests, and a safe rollout path. |
| Operations | Says add more servers. | Mentions replicas and monitoring. | Rolling index swaps with canaries and rollback, queries of death, region loss, cost levers, and a phased plan. |
| Mistake | Do this instead |
|---|---|
| Answering with a single database and a LIKE query | Say the inverted index is the answer, then split it into shards and replicas. |
| Ignoring the fan-out cost | Compute shard calls a second. 60,000 queries times 1,000 shards is 60 million, and it explains replicas, caching and tiers. |
| Only discussing average latency | Do the 1 − (1 − p)^N maths and add backup requests and a deadline. |
| Running the heavy ranking model on every match | Cheap local scoring first, then a learned reranker on the top few hundred. |
| Rebuilding the whole index to be fresh | Immutable segments, background merges and a small real-time tier. |
| Treating crawling and typeahead as part of this problem | State the boundary, link to those designs, and focus on indexing, serving and ranking. |
| Swapping the index on every replica at once | Roll out a few replicas at a time with quality checks and a one-step rollback. |
| Never saying what a choice costs | For each choice name what you gain and pay: fan-out, extra load, partial answers, staleness. |
The core data structure: postings, intersection, compression and segments.
How engines like Elasticsearch analyse text and rank results on one cluster.
Where the pages come from: the frontier, politeness and freshness.
The suggestions shown while the user is still typing.
Splitting data across machines, and what it costs to ask every shard.
Finding near-duplicate pages with small fingerprints.
The batch model behind PageRank and index building.
The result cache and posting-list caches that make the fleet affordable.