An index too large for one machine is split by document into shards, each copied onto replicas; each query goes to one copy of every shard. For an illustrative billion documents, a positional index of up to 580 GB needs 10 shards of 64 GB, and 10,000 queries per second need 40 replicas plus a spare, 410 machines: size sets shards, load sets replicas. For a two-term query, document partitioning moves over a thousand times fewer bytes than term partitioning, but shard-local idf errs on rare terms (median 0.60 for terms in under ten Reuters stories, 8 shards). With 100 shards each slow 1 percent of the time independently, 63 percent of queries wait for a straggler. Caching, tiering, early termination and staged ranking cut the work per query.
In the previous article, a query left the web server and went to every index shard at once. In the illustrative latency budget, each shard had about 50 milliseconds to find and score its candidates, and the merge could not start until the slowest shard answered. In 2003, engineers at Google reported that answering a single query read hundreds of megabytes of data and consumed tens of billions of CPU cycles (Barroso, Dean, and Hölzle, 2003). A single processor of that era, running at one or two gigahertz, would have needed several seconds or more for that much work. The engine answered in a fraction of a second, thousands of times per second. How is an index divided among many machines so that every query still comes back that fast? In short, it is cut into pieces by document, each piece is copied onto many machines, and each query is sent to one copy of every piece at once.
Search at scale is the engineering that lets one logical search engine run on many machines. Each query is split across the machines, and each machine handles only its share. The ranked list the user sees must still look as if one machine had scored the whole collection, although no machine ever holds the whole collection. The web has grown by orders of magnitude since 2003, and the same principles still apply. They apply at every scale, too. A company running a search cluster with a handful of nodes makes the same decisions as a web search engine, with smaller numbers.
First we estimate how many machines an index of a billion documents needs. Then we divide the index among them, by document or by term, and measure what that costs in ranking accuracy. Next we copy the pieces for load, cache what repeats, and cut the work per query. Then we meet tail latency, where one slow machine delays most queries. Finally we keep the index fresh, and find the same design in open-source search servers. The article assumes The Architecture of a Search Engine, whose inverted index and query process are the pieces being distributed here.
Why one machine is not enough
Three quantities grow with a search service, and each strains a single machine in a different way:
- The size of the collection. The index for billions of pages is far larger than one machine's memory, and reading postings from disk is slow.
- The number of queries per second. Thousands of queries per second exceed what one machine can process.
- The work done per query. As ranking models become more expensive, the time per query grows even when the collection does not.
The solutions match these three pressures. Partitioning divides the index so that each machine holds a manageable piece. Replication copies each piece, so that many queries can be served at once and the failure of one machine does not take the service down. Caching, tiering, and staged ranking reduce the work per query.
A rough calculation puts a number on "far larger than one machine's memory": several hundred gigabytes for a billion documents.
An index on the back of an envelope
The sizes can be estimated from figures measured on a small collection. The Reuters RCV1 collection used throughout the textbook has 800,000 documents and about 100 million postings. Each document therefore contributes about 125 postings, one for each distinct term it contains. Stored as 32-bit integers, those docIDs take 400 megabytes. The compressed gaps take about 116 megabytes with variable byte codes and 101 megabytes with gamma codes (Manning, Raghavan, and Schütze, 2008, Tables 4.2 and 5.6). That is 32, 9.28, and 8.08 bits per posting.
Those rates carry over to a larger collection of similar documents. Suppose the collection grows $n$-fold with the same mix of documents. Each term's document frequency grows about $n$-fold too, so the average gap between postings, $N/\text{df}$, stays the same. Here $N$ is the number of documents and $\text{df}$ the number that contain the term. A gap code then spends about the same number of bits per posting. The argument is an approximation in one respect. A larger collection also contains terms the smaller one never used: the vocabulary keeps growing with the collection, which is Heaps' law in term statistics. Those new terms are rare, so their gaps are long and their postings cost more bits each, but they are also a small share of all postings. The estimate below ignores them. For a hypothetical collection of one billion documents (values from tools/experiments/foundations/scale_arithmetic.py, rounded to the nearest gigabyte):
| Quantity | Value |
|---|---|
| Postings, $10^9 \times 125$ | $1.25 \times 10^{11}$ |
| DocIDs as 32-bit integers | 500 GB |
| Variable byte codes on gaps | 145 GB |
| Gamma codes on gaps | 126 GB |
| With term frequencies and positions, 2 to 4 times the variable-byte figure | 290 to 580 GB |
The last row uses the textbook's estimate that a positional index is two to four times as large as a non-positional one (Manning, Raghavan, and Schütze, 2008, §2.4.2). A positional index of 580 GB does not fit in the memory of one machine. Suppose each machine devotes 64 GB of memory to the index, an illustrative figure. Then the index needs $\lceil 580 / 64 \rceil = 10$ shards.
Query load sets a second number. Suppose one copy of all ten shards can answer 250 queries per second, and the service must handle 10,000 queries per second at its peak. Then it needs $10{,}000 / 250 = 40$ replicas of the shard set, 41 with one spare, and $10 \times 41 = 410$ machines.
The number of shards came from the size of the index, the number of replicas from the query load, and the two multiply. Real engines are larger by orders of magnitude, because web documents are longer than news stories and web collections are far larger than a billion pages. But the arithmetic has the same form.
Example (traffic doubles, the collection does not). If the collection stays the same size and peak traffic doubles, the number of replicas changes and the number of shards does not. The shard count depends only on how much index must fit in memory, so it stays at 10, while twice the traffic needs about twice as many copies. Doubling the collection at constant traffic does the opposite.
Partitioning the index
Ten shards is a count. How should the index actually be cut into ten pieces? There are two natural ways to divide an inverted index among $P$ machines (Manning, Raghavan, and Schütze, 2008, §20.3).
Document partitioning assigns each machine a subset of the documents and builds a complete, independent index over that subset. Each machine, often called a shard, holds the postings for every term, but only for its own documents. A query is sent to every shard, and each shard ranks its own documents and returns its best $k$. A coordinating machine, called a broker or aggregator, merges the lists into a single ranking.
Term partitioning assigns each machine a subset of the vocabulary and stores the complete postings lists for those terms. A query is sent only to the machines that hold its terms, and their lists are combined to produce the result.
The trade-offs between them:
| Document partitioning | Term partitioning | |
|---|---|---|
| Machines involved per query | All shards | Only those holding the query's terms |
| Work per machine per query | Small: a short postings list for every query term | Large for common terms: entire postings lists |
| Data moved between machines | Only each shard's top $k$ results | Whole postings lists, or partial results passed along |
| Load balance | Even, if documents are spread randomly | Uneven: machines holding popular terms become hot spots |
| Collection statistics | Each shard sees only local document frequencies | Each term's statistics are complete on one machine |
| Adding documents | Add to one shard or add a shard | Touches the postings of many terms on many machines |
Term partitioning looks efficient, because a two-word query involves only two machines.
Example (bytes moved by a two-term query). In the billion-document collection above, take a query whose two terms occur in 1 percent and 0.1 percent of documents. Under term partitioning it involves two machines; under document partitioning into 10 shards it involves ten. Term partitioning nevertheless moves more bytes between machines, by a factor of more than a thousand.
The two postings lists hold 10 million and 1 million docIDs. Their sizes follow from how a variable byte code works: it spends whole bytes, one for a gap below 128 and two for a gap below 16,384. The first term's gaps average 100 and the second's average 1,000. Suppose the documents containing a term are scattered at random, so that each document contains it with probability $q$ independently. A gap is at least $g$ when the $g - 1$ documents after a posting all lack the term, which has probability $(1 - q)^{g - 1}$. A second byte is needed when the gap is at least 128:
$$(1 - 0.01)^{127} \approx 0.28, \qquad (1 - 0.001)^{127} \approx 0.88.$$
Gaps of 16,384 or more are too rare to matter for either term. The lists therefore take about $10^7 \times 1.28$ bytes, or 12.8 MB, and $10^6 \times 1.88$ bytes, or 1.9 MB. The collection-wide average of 9.28 bits per posting does not apply to a single list. It would give 11.6 MB and 1.2 MB, but it is an average over all terms, and most postings belong to frequent terms with short gaps. Both terms here have longer gaps than that average reflects, the second by far.
Under term partitioning, the shorter list must travel to the machine holding the longer one, or both to a third, and both lists are read in full. Under document partitioning, each shard reads only its tenth of each list. It then returns its top 10 results at 12 bytes each, for a docID and a score. The total is $10 \times 10 \times 12 = 1{,}200$ bytes. The shorter list alone is about 1,570 times that.
The general lesson is that the postings list for a common term can be enormous. It must be transferred and combined, so the machines holding popular terms become bottlenecks. Moffat, Webber, Zobel, and Baeza-Yates (2007) proposed a pipelined design, in which a partly evaluated query is passed among the machines that hold its terms, and found that it shares the computation better than plain term partitioning. It still suffered from uneven load between machines, and they concluded that document partitioning remained the preferred method. Large web engines have generally chosen document partitioning (Barroso, Dean, and Hölzle, 2003; Dean, 2009).
Document partitioning also isolates failures well. If one shard does not respond, the query can still be answered from the others. The loss in recall is, on average, about the share of the collection that shard holds. For a particular query it can be large, for example when the one page a navigational query seeks is on the missing shard.
What local statistics cost
Document partitioning has one subtle cost. Ranking functions such as TF-IDF and BM25 depend on collection-wide statistics, such as document frequency and average document length. A shard that computes them over its own documents will score slightly differently from its neighbors. The merged ranking then compares scores that are not quite comparable.
Here is the idea in one sentence: a shard is a random sample of the collection, and a sample estimates a common term's frequency well and a rare term's badly. If documents are assigned to shards at random and each shard is large, local statistics are close to the global ones for most terms, and the error is small. Rare terms are the exception. A term that occurs in a few dozen documents can have very different document frequencies on different shards.
Example (a word in a thousand stories and a word in two). On a typical shard, the idf of a word found in just two stories is far more wrong than the idf of a word found in a thousand. With eight shards, those two stories usually land on different shards (with probability $7/8$), and each of the two shards sees a document frequency of 1 among an eighth of the collection. The measurement below confirms it.
The size of the effect can be measured. We split the 10,788 stories of Reuters-21578 at random into shards. For every term on every shard where it occurs, we compare the shard's $\log_{10}(N_s/\text{df}_s)$ with the global $\log_{10}(N/\text{df})$. Here $N_s$ is the number of stories on shard $s$, and $\text{df}_s$ the number of them that contain the term. The table gives the median absolute differences (computed by tools/experiments/foundations/shard_statistics.py; median over 30 random splits, whose interquartile ranges are 0.003 or narrower; rounded to two places):
| Global df of the term | Terms | Median idf error, 8 shards | Median idf error, 64 shards |
|---|---|---|---|
| 1 to 9 | 23,559 | 0.60 | 1.33 |
| 10 to 99 | 4,476 | 0.14 | 0.37 |
| 100 to 999 | 1,055 | 0.05 | 0.14 |
| 1,000 or more | 97 | 0.01 | 0.04 |
For scale, idf on this collection runs from 4.03 for a word in a single story down to below 1 for words in more than a tenth of the stories. With eight shards, a term in a few hundred stories, with an idf near 1.5, strays by about 0.05 on a typical shard, a few percent.
The rarest band can be worked out by hand. A term in one story sits on one shard. Its local idf is about $\log_{10}(10{,}788/8)$ instead of $\log_{10}(10{,}788)$, smaller by $\log_{10} 8 \approx 0.90$. A term in two stories that land on different shards is off by $\log_{10} 4 \approx 0.60$, which is the median for the rarest band.
The error grows with the number of shards, because each shard is a smaller sample of the collection. When precision matters, the global statistics are computed periodically and distributed to every shard (Manning, Raghavan, and Schütze, 2008, §20.3). Federated search proves that with shared statistics the merged ranking is exactly that of a single index, and treats engines that share nothing.
Replication
Partitioning makes the index fit. Replication makes the service fast and reliable. Each shard is copied onto several machines, and a load balancer sends each query to one replica of each shard. Doubling the number of replicas roughly doubles the number of queries the system can serve.
Replicas also provide fault tolerance. When a machine fails, its queries go to another replica of the same shard. A large deployment can therefore be pictured as a grid, with shards in one dimension and replicas in the other. The number of shards is set mainly by the size of the index. The number of replicas is set by the query load and the level of fault tolerance required, as the envelope calculation showed.
Replication buys capacity with more machines. The next two sections skip some of the work altogether, first by remembering answers and then by not scoring documents that cannot be shown.
Caching
Query traffic is very uneven. A small number of queries are issued over and over, while a large fraction of distinct queries are seen only once. That distribution makes caching effective. Baeza-Yates and colleagues (2007) analyzed caching at two levels:
- Result caches store the final results page for a query. When the same query arrives again, the engine returns the stored page without consulting the index at all. This saves the most work per hit, but it helps only with repeated queries. The cache key must include everything else that changes the results, such as language, location, personalization, and, in enterprise search, the user's access rights.
- Postings caches store the postings lists of frequently used terms in memory. A new query made of common terms is then answered without reading those lists from disk. Hits are less valuable than result-cache hits, but much more frequent, because many distinct queries share common terms.
Example (a cached page for another country). The query jaguar arrives from a user in Brazil, and a results page for jaguar is already in the result cache, computed for a user in the United States. The engine cannot reuse it in general. The cache key includes location because location can change the results. The postings list for jaguar, by contrast, is the same for everyone, so a postings-cache hit is safe.
Two refinements matter in practice. First, a cache can be divided into a static part and a dynamic part (Fagni, Perego, Silvestri, and Orlando, 2006). The static part is filled from historical logs with queries that are always popular. The dynamic part is managed by a replacement policy that tracks what is popular now. Second, because the index changes, a cached result goes stale. Each entry needs an expiry policy, which sets the balance between saving work and showing results that no longer reflect the index. Caching in search engines derives the hit rate of a cache when query popularity follows a Zipf law, and the hits that an expiry time costs.
Memory has also replaced disk for most serving. Dean (2009) described Google moving its serving index entirely into memory in early 2001, once the combined memory of its machines could hold it. That removed disk seeks from the query path. Many large deployments now serve most or all of the index from memory or from solid-state storage. Vector indexes face the same choice: vector search on disk and with filters describes DiskANN, which keeps its graph and full vectors on a solid-state drive and only compressed vectors in memory, and is designed so that a query needs only a few dozen reads.
Doing less work per query
Even with partitioning and caching, scoring every document that matches a new query is wasteful, since most of them will never be shown. Three techniques avoid that work.
Tiered indexes. The index is divided by document quality. The first tier contains a small fraction of high-quality pages and is consulted for every query. Lower tiers are consulted only if the first tier returns too few results (Manning, Raghavan, and Schütze, 2008, §7.2.1 and §20.3; the example of §7.2.1 divides the postings by term frequency instead). Because most queries are answered well from the first tier, most of the index sits idle for most queries. The saving is approximate. A lower-tier page that would have ranked highly is never considered when the first tier suffices.
Early termination. Suppose postings are ordered so that documents likely to score highly come first. Then a query can stop reading once its top $k$ results cannot change. Algorithms such as WAND (Broder, Carmel, Herscovici, Soffer, and Zien, 2003) keep an upper bound on the score each term can contribute. They skip any document whose bounds add up to less than the current $k$-th best score.
A common misreading is that skipping documents must cost accuracy. It need not. When the bounds are valid for the full scoring function, a skipped document provably could not have entered the top $k$. The technique then produces exactly the same top $k$ as scoring everything, at a fraction of the cost. Broder and colleagues also made the pruning threshold adjustable. Raising it above the current $k$-th best score skips more documents and saves more work, at the risk of losing some true top-$k$ results. Only that deliberate setting trades accuracy for speed. Tonellotto, Macdonald, and Ounis (2018) survey these methods. Dynamic pruning with MaxScore and WAND proves the exactness, and block-max indexes keep it with a bound for every block of a postings list.
Multi-stage ranking. Ranking is organized as a cascade, as the previous article showed with its funnel:
- A cheap first stage, such as BM25 over the inverted index, selects perhaps a thousand candidates from millions of matches.
- A second stage applies a learned model over hundreds of features to those candidates.
- A final stage applies the most expensive model, such as a neural model that reads the query and the document text together, to the top few dozen.
Each stage reduces the candidate set for the next, so expensive computation is spent only on documents likely to be shown (Wang, Lin, and Metzler, 2011). This structure explains why classical models remain in production even where neural models are more accurate. The neural models are affordable only because a cheaper first stage, usually a classical model, has already discarded almost every document. A first stage can also take the passages whose vectors are nearest the query's, as a dense retriever does; finding those vectors without comparing against all of them is the subject of vector search.
None of these techniques changes the fact that the broker must wait for every shard.
Tail latency
A query on a document-partitioned index waits for the slowest shard, and that turns rare delays into common ones.
Example (one hundred shards, each on time 99 percent of the time). The query jaguar is sent to 100 shards, and each shard independently answers within its usual time 99 percent of the time. More than half of such queries are delayed by at least one slow shard. The query is on time only if all hundred shards are on time, with probability $0.99^{100} \approx 0.37$. So about 63 percent of queries wait for at least one straggler. The intuitive answer, 1 percent, is the delay rate of one shard, not of a query that needs all of them.
Dean and Barroso (2013) called this the tail at scale: at high fan-out, rare delays on individual machines become common delays for the service. Each shard beyond what the index needs is another chance for a query to wait. In practice delays are also partly correlated, through shared networks and machines. The independent model is therefore an illustration rather than a prediction.
The formal version. The general form follows from the same reasoning. Let each of $S$ shards be slow with probability $p$, independently. The query escapes delay only if every shard is fast, which happens with probability $(1 - p)^S$, so
$$P(\text{query slow}) = 1 - (1 - p)^S.$$
For small $p$ this is close to $Sp$ while $Sp$ is small. To see why, note that the query is slow exactly when at least one shard is slow. The probability of that is at most the sum of the $S$ individual probabilities, $Sp$. It is at least $Sp$ minus the sum, over all $\binom{S}{2}$ pairs of shards, of the probability that both shards of the pair are slow, which is $\binom{S}{2}p^2$. To see this, let $K$ be the number of slow shards. When $K = 0$, $K - \binom{K}{2} = 0$. When $K \ge 1$, $K - \binom{K}{2} = K(3 - K)/2 \le 1$, since it equals 1 for $K = 1$ and $K = 2$ and is at most 0 from $K = 3$ on. So the indicator of the event $K \ge 1$ is at least $K - \binom{K}{2}$, and taking expectations gives $P(K \ge 1) \ge Sp - \binom{S}{2}p^2$: the expected number of slow shards is $Sp$ and the expected number of slow pairs is $\binom{S}{2}p^2$. Finally $\binom{S}{2}p^2 = S(S-1)p^2/2 \le (Sp)^2/2$. So
$$Sp - \frac{(Sp)^2}{2} \;\le\; 1 - (1 - p)^S \;\le\; Sp.$$
With $S = 10$ and $p = 1/100$ the bounds are 0.095 and 0.100, and the exact value is 0.0956.
The probability passes one half when $(1 - p)^S = 1/2$. Taking logarithms gives $S \ln(1 - p) = -\ln 2$, so
$$S = \frac{\ln 2}{-\ln(1 - p)} \approx \frac{\ln 2}{p} \approx \frac{0.69}{p},$$
where the approximation uses $-\ln(1 - p) = p + p^2/2 + \cdots \approx p$ for small $p$. The exact values are 68.97 shards for $p = 1/100$, 692.8 for $p = 1/1{,}000$, and 6,931.1 for $p = 1/10{,}000$, that is, about 69, 693 and 6,931 (computed by tools/experiments/foundations/scale_arithmetic.py).
Dean and Barroso (2013, pp. 76–77) plot this curve for a server that usually answers in 10 ms but takes a second one time in a hundred. With 100 such servers, 63 percent of requests take more than a second, which matches the example above. Even if only one request in 10,000 is slow, a service with 2,000 servers sees almost one request in five take more than a second.
Measurements from a real service agree in shape. Dean and Barroso (2013, pp. 76–77 and Table 1) report a Google service in which a root server fans a request out to a very large number of leaf servers. At the 99th percentile, a single randomly chosen leaf finishes in 10 ms, 95 percent of the leaves finish in 70 ms, and all of them in 140 ms. Waiting for the slowest 5 percent of leaves accounts for half of that 140 ms.
Remedies that accept redundancy
A hedged request sends a query to a second replica if the first has not answered within a short delay, and uses whichever answer arrives first. Waiting before hedging keeps the cost down. If the second request is sent only after the first has been outstanding longer than the 95th-percentile latency for its class, only about 5 percent of requests are duplicated. In a Google benchmark that read 1,000 values spread over 100 servers, hedging after 10 ms cut the 99.9th-percentile latency from 1,800 ms to 74 ms. It sent only 2 percent more requests (Dean and Barroso, 2013, p. 77).
An idealized calculation shows why the gain is so large. If the two replicas were slow independently, each with probability $p$, a hedged shard would be slow only when both were, with probability $p^2$. For $p = 1/100$ that is $1/10{,}000$, and the probability that a 100-shard query is slow falls from 0.63 to 0.01. Real delays are partly correlated, so the gain is smaller, but the benchmark shows it can still be large.
A deadline lets the broker return results without a shard that is too slow. It accepts some loss in recall for that query in exchange for a predictable response time. Engines also monitor latency at high percentiles, such as the 99th, rather than at the average. The average hides exactly the delays that users notice.
Keeping the index fresh
The index is also a snapshot. Between the moment a page is crawled and the moment the index containing it goes into service, the page may change, and new pages appear that the index does not contain. How long that lag lasts depends on how the index is built.
The traditional approach rebuilt the index in large batches. The crawled collection was processed into a new index over hours or days, and the new index replaced the old one in service. Batch rebuilding is simple and efficient. But every page in the index is at least as old as the most recent rebuild, and any change after that rebuild's crawl must wait for the next one. For a news event, that is far too old.
Modern engines combine a large main index, rebuilt or merged periodically, with small indexes of recent documents that are updated continuously. A query is answered from both. The small indexes are merged into the main one in the background. The textbook calls this dynamic indexing with an auxiliary index (Manning, Raghavan, and Schütze, 2008, §4.5). Logarithmic merging is a refinement of it, in which the engine keeps a series of indexes, each twice the size of the one before, and merges two only when they have the same size. Each posting is then rewritten once per level it passes through, not once per merge of the whole main index. Index construction works both schemes through and measures them, and updating an index derives the cost of every merge strategy and of deletion. Google's move to incremental indexing in 2010 relied on a system for processing updates to individual pages as they were crawled, rather than recomputing over the whole collection (Peng and Dabek, 2010).
Freshness also depends on the crawler, since a page cannot be indexed until it has been fetched again. Deciding how often to revisit each page is a central problem in web crawling.
Different parts of the collection need different freshness. A news site's home page changes many times a day, and an academic paper hardly ever. Engines allocate crawling and indexing resources accordingly. They also use the age of the indexed copy as one of the inputs to ranking for queries that require fresh results.
The same ideas at smaller scale
Open-source search servers such as Elasticsearch and Solr, both built on the Lucene library, implement the same architecture on a small scale:
- an index is divided into shards that hold disjoint sets of documents;
- each shard has configurable replicas;
- a coordinating node scatters each query to the shards and gathers their results;
- new documents are written to small segments that are merged in the background.
Lucene's segments and background merges apply the merge-based dynamic indexing described in the textbook. A segment is not a shard. Each shard is a complete Lucene index, which usually consists of many segments. An organization indexing a few million documents may need only a few machines. It still decides how many shards to use, how many replicas to keep, how fresh the index must be, and whether to compute collection statistics per shard or globally.
What does not carry over from the web is the volume of behavioral data and the link graph. Those differences shape ranking more than infrastructure, and they are the subject of enterprise, personal, and product search.
Worked problems
These problems are posed on this article's own envelope calculation, its shard experiment and its tail-latency model, with the same illustrative hardware figures; none comes from the course text. The reference-pass block of scale_arithmetic.py recomputes every number.
Problem 1 (ten billion documents). Repeat the envelope calculation for $10^{10}$ documents of the same kind, with 64 GB of memory per machine for the index, a peak of 20,000 queries per second, and 250 queries per second per copy of the shard set. Find the number of shards, replicas and machines for a positional index at four times the variable-byte size, with one spare replica.
Solution. The index needs 91 shards and 81 replicas, which is 7,371 machines.
- Postings: $10^{10} \times 125 = 1.25 \times 10^{12}$.
- Variable byte codes on gaps: $1.25 \times 10^{12} \times 9.28 / 8 = 1.45 \times 10^{12}$ bytes, or 1,450 GB.
- Positional index at four times that: 5,800 GB.
- Shards: $5{,}800 / 64 = 90.6$, so 91.
- Replicas: $20{,}000 / 250 = 80$, and 81 with the spare.
- Machines: $91 \times 81 = 7{,}371$.
The collection grew tenfold and the traffic twofold, and the machine count grew by a factor of $7{,}371 / 410 \approx 18$, close to the product of the two, 20. It falls short of 20 because of rounding: 580 GB needed 10 shards where 9.06 would have filled exactly, and the spare replica is one in both cases. The assumption that a copy of the shard set still answers 250 queries per second when it has 91 shards and not 10 is the weakest part of the estimate. More shards mean more results to merge and more chances of a slow shard, which Problem 5 computes.
Problem 2 (how many spares). In the article's 410-machine design, find the share of capacity in use at peak, the capacity left after two replicas of the shard set fail, and the number of machines needed to survive two such failures at peak.
Solution. At peak the design runs at 97.6 percent of capacity; two failures leave it 250 queries per second short; surviving them takes 42 replicas, 420 machines.
- Capacity with 41 replicas: $41 \times 250 = 10{,}250$ queries per second. The peak of 10,000 is $10{,}000 / 10{,}250 = 97.6$ percent of it.
- With one replica down: $40 \times 250 = 10{,}000$, exactly the peak. That is what "one spare" buys.
- With two down: $39 \times 250 = 9{,}750$, short by 250.
- To serve the peak with two down, $r - 2 \ge 40$, so $r = 42$ replicas and $10 \times 42 = 420$ machines.
A replica of the shard set here means one machine for each of the 10 shards. A single machine failing removes one shard's copy, and the load balancer can still use the other nine machines of that replica for their own shards. The count above is therefore the worst case, in which the failures are counted against one shard: every shard needs 40 working copies, so every shard needs 42 machines to survive two failures among its own.
Problem 3 (the size of one postings list). In the billion-document collection, a term occurs in 5 percent of the documents, scattered at random. Find the size of its docID list under a variable byte code, and compare it with the size the collection-wide average of 9.28 bits per posting would predict.
Solution. The list takes about 50.1 MB, against 58 MB predicted by the average, because nearly all of its gaps fit in one byte.
- Postings: $0.05 \times 10^{9} = 5 \times 10^{7}$. The mean gap is $1/0.05 = 20$.
- A second byte is needed for a gap of at least 128, which has probability $(1 - 0.05)^{127} = 0.95^{127} \approx 0.0015$. Longer codes are negligible.
- Bytes per posting: $1 + 0.0015 = 1.0015$. The list takes $5 \times 10^{7} \times 1.0015 \approx 5.01 \times 10^{7}$ bytes, 50.1 MB.
- At the average rate: $5 \times 10^{7} \times 9.28/8 = 5.8 \times 10^{7}$ bytes, 58 MB.
With the article's example this gives one term below the average of 1.16 bytes per posting and two above it: 1.0015 bytes for a term in 5 percent of documents, 1.28 for a term in 1 percent, and 1.88 for a term in 0.1 percent. A variable byte code cannot go below one byte per posting, however short the gaps. Bit-level codes such as the gamma code, described in index compression, do not have that floor.
Problem 4 (the idf error of a shard, in general). A term occurs in $\text{df}$ of the $N$ documents, and $\text{df}_s$ of them are on a shard that holds $N/S$ documents. Derive the difference between the shard's idf and the global idf. Evaluate it for a term in four stories with eight shards when the shard holds one, two or all four of them, and for a term in 800 stories when the shard holds 110 or 90.
Solution. The difference is $\log_{10}\dfrac{\text{df}}{S \cdot \text{df}_s}$, which does not depend on $N$ and is zero exactly when the shard holds its fair share, $\text{df}_s = \text{df}/S$.
The shard computes $\log_{10}\dfrac{N/S}{\text{df}_s}$ and the whole collection gives $\log_{10}\dfrac{N}{\text{df}}$. Subtracting,
$$\log_{10}\frac{N}{S \cdot \text{df}_s} - \log_{10}\frac{N}{\text{df}} = \log_{10}\left(\frac{N}{S \cdot \text{df}_s} \cdot \frac{\text{df}}{N}\right) = \log_{10}\frac{\text{df}}{S \cdot \text{df}_s}.$$
| $\text{df}$ | $S$ | $\text{df}_s$ | Fair share $\text{df}/S$ | Error |
|---|---|---|---|---|
| 1 | 8 | 1 | 0.125 | $\log_{10}(1/8) = -0.903$ |
| 2 | 8 | 1 | 0.25 | $\log_{10}(2/8) = -0.602$ |
| 4 | 8 | 1 | 0.5 | $\log_{10}(4/8) = -0.301$ |
| 4 | 8 | 2 | 0.5 | $\log_{10}(4/16) = -0.602$ |
| 4 | 8 | 4 | 0.5 | $\log_{10}(4/32) = -0.903$ |
| 800 | 8 | 110 | 100 | $\log_{10}(800/880) = -0.041$ |
| 800 | 8 | 90 | 100 | $\log_{10}(800/720) = +0.046$ |
The first two rows are the two cases the article worked by hand, 0.90 and 0.60 in size. The formula explains the table of measurements. A shard that contains a rare term at all holds at least one document with it, which is already more than the fair share when $\text{df} < S$. So on every shard where a rare term occurs, the local idf is too small, by at least $\log_{10}(S/\text{df})$. For a frequent term the count on a shard varies around the fair share by a small fraction of it, and the error is the logarithm of a ratio near 1. A shard where the term does not occur at all has no idf for it. The experiment accordingly compares only shards where the term occurs.
Problem 5 (fan-out for the two designs). Each shard is slow one time in a hundred, independently. Find the share of queries delayed in the 10-shard design of the article and in the 91-shard design of Problem 1, the share in the 91-shard design with ideal hedging, and the largest number of shards for which fewer than one query in ten is delayed.
Solution. The shares are 9.6 percent with 10 shards and 59.9 percent with 91; ideal hedging brings the 91-shard figure to 0.9 percent; and 10 is the largest shard count that keeps the share under one in ten.
- 10 shards: $1 - 0.99^{10} = 0.0956$.
- 91 shards: $1 - 0.99^{91} = 0.599$.
- Hedged, 91 shards: a shard is slow only if both of its replicas are, with probability $0.01^2 = 10^{-4}$, so the share is $1 - 0.9999^{91} = 0.0091$. As the article says of its own hedging calculation, this assumes the two replicas are slow independently.
- One in ten: $1 - 0.99^{S} < 0.1$ means $0.99^{S} > 0.9$, so $S < \ln 0.9 / \ln 0.99 = 10.48$. Ten shards give 0.0956 and eleven give 0.1047.
The tenfold collection of Problem 1 therefore changes the character of the service, not only its size. With the same machines, six queries in ten now wait for a straggler, and a remedy such as hedging stops being optional.
What we have learned
Scale changes the engineering of retrieval but not its logic. Partitioning makes the index fit, and the envelope calculation showed that size sets the shard count while load sets the replicas. Replication handles query load and failure. Caching exploits the repetition in query traffic. Tiering, early termination, and staged ranking reduce the work per query. Each technique trades something for speed:
- memory for disk reads;
- redundant computation for predictable latency;
- a little recall for a guaranteed response time;
- absolute freshness for efficient rebuilding.
The architecture article described a single pipeline. A production engine runs thousands of copies of pieces of that pipeline in parallel, organized so that the user still sees a single, consistent ranked list.
So far the task has been one kind of search: a query typed into a box, answered with a ranked list of web pages. The same machinery serves many other tasks, from filtering a news stream to answering a question directly. The next article, Search Applications, surveys those tasks and says what each changes about the engine.
References
- Baeza-Yates, R., Gionis, A., Junqueira, F., Murdock, V., Plachouras, V., and Silvestri, F. (2007). The impact of caching on search engines. In Proceedings of SIGIR 2007, 183–190. record · 2 pages
- Barroso, L. A., Dean, J., and Hölzle, U. (2003). Web search for a planet: The Google cluster architecture. IEEE Micro, 23(2), 22–28. record · 2 pages
- Broder, A. Z., Carmel, D., Herscovici, M., Soffer, A., and Zien, J. (2003). Efficient query evaluation using a two-level retrieval process. In Proceedings of CIKM 2003, 426–434. record · 3 pages
- Dean, J. (2009). Challenges in building large-scale information retrieval systems. In Proceedings of WSDM 2009, 1. Keynote talk. record
- Dean, J., and Barroso, L. A. (2013). The tail at scale. Communications of the ACM, 56(2), 74–80. record
- Fagni, T., Perego, R., Silvestri, F., and Orlando, S. (2006). Boosting the performance of Web search engines: Caching and prefetching query results by exploiting historical usage data. ACM Transactions on Information Systems, 24(1), 51–78. record · 2 pages
- Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, sections 2.4.2, 4.2, 4.5, 7.1–7.2, and 20.3, and chapter 5. Cambridge University Press. record · 102 pages
- Moffat, A., Webber, W., Zobel, J., and Baeza-Yates, R. (2007). A pipelined architecture for distributed text query evaluation. Information Retrieval, 10(3), 205–231. record
- Peng, D., and Dabek, F. (2010). Large-scale incremental processing using distributed transactions and notifications. In Proceedings of OSDI 2010, 251–264. record
- Tonellotto, N., Macdonald, C., and Ounis, I. (2018). Efficient query processing for scalable web search. Foundations and Trends in Information Retrieval, 12(4–5), 319–500. record · 4 pages
- Wang, L., Lin, J., and Metzler, D. (2011). A cascade ranking model for efficient ranked retrieval. In Proceedings of SIGIR 2011, 105–114. record · 3 pages
Reviewed: verified, 16 Nov 2026 · checked against sources, 23 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 12 revisions