Inside a Search System 00:00:01 Scatter a query and gather candidates A learner searches for distributed systems. Three machines own different documents, one machine answers late, and two think a query word is unusually rare. Whose result should occupy the first position? A user asks for distributed systems. Lowercase and stem, like the documents. One copy of each shard is asked, all at once. BM25, and only the best three are kept. Ids and scores travel back, about 20 bytes each. Three documents are fetched, one from each shard here. The answer is cached and sent. A coordinator requests local candidates, combines comparable scores and fetches the chosen documents. The stored results must respect the query's index generation, filters and access rules. 00:00:55 Work through a BM25 score N = 1,000, the word is in 100 documents, average length 200. The corpus has a thousand documents and a hundred contain this term. Under this smoothed inverse-document-frequency formula, the natural logarithm of one plus nine hundred point five divided by a hundred point five is about two point three. All three candidates share this term weight. For short document A, divide eleven by five point seven five to get a frequency-and-length factor of about one point nine one. Multiply by the common term weight. The longer document B has a larger normalization term. Eleven divided by seven point five five gives about one point four six, before multiplying by that same weight. Document C is short and has two matches. Its normalized factor is one point six, above B’s one point four six, so C can outrank B despite fewer repetitions. In this numerical exercise, document frequency sets the rarity contribution while frequency saturation and document length distinguish the candidates. Change one input at a time before attributing an observed rank change to document length alone. 00:02:11 A fan-out inherits a slow tail Each shard is slow in one request of a hundred. Suppose each of ten independent shard calls is slow one percent of the time. The chance the combined search waits on at least one slow call is one minus ninety-nine percent raised to the tenth power, about 9.6 percent. Across a hundred independent calls the same calculation gives about 63.4 percent. Shared failures could make the independence assumption inappropriate. C takes 300 ms. The user waits although A and B are done. After 40 ms, the usual p95, a second copy of C is asked. It needs 25 ms. Hedging a slow shard against an eligible replica can help when spare capacity exists. Launching duplicates during saturation can instead increase queueing and delay both copies. 00:03:06 Name a partial answer Three requests with one deadline. A and B are back. C is silent. The best of two: 9, 7, 5. The 8 of C is missing. The answer is marked partial and not cached. If a shard misses the deadline, the coordinator does not know which high-scoring documents it failed to inspect. Return an explicit partial result or an error according to the product contract. 00:03:33 Two shards disagree on rarity The same document text on two small shards. 100 documents, the word is in 1. It looks very rare. 100 documents, the word is in 50. Together: 51 of 200. Collect counts first, use fewer shards, or spread documents by hash. A term common globally may appear rare on a small shard. Comparable collection statistics or an appropriate distributed scoring procedure can matter when merging scores from dissimilar partitions. 00:04:09 Do not save a temporary omission A partial answer is stored for a minute. Shard C is late once. The answer has two shards. The code caches whatever came. C is fine again, and everybody still gets the poor answer. Store only complete answers. A short-lived shard timeout should not turn into a long-lived cached omission after the shard recovers. Include completion status in the caching policy and record how often users actually receive complete results. A search result needs three kinds of evidence: which documents could match, how they were scored and which shards actually contributed. Protect all three when caching or reporting an answer.