Highlights

Contents

Part IX
09

Case study: search end to end

We assemble the chapter’s pieces into one defensible system. A named box is useful only when its state and failure boundary are clear. We will follow a report update, a phrase query, a deletion, and the complete resource count.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Search basics: why LIKEfails2Tokenization and analysis3The inverted index4Ranking: TF-IDF and BM255The indexing pipeline6Shards and replicas7Autocomplete and fuzzysearch8Operating a searchcluster9Case study: search end toend

#Section 33The report update trace

Report 1 changes to source version 8. The database transaction commits its text and an outbox change together. The relay publishes the change. The indexer checks the version, applies the title analyzer, and writes the selected primary shard. Replication follows the engine’s acknowledgement rule. A later refresh opens a search view containing the new representation.

The visible checkpoints are different. Source version 8 can be durable before the indexer receives it. The primary can acknowledge indexing before a search view exposes it. The source remains the repair authority if a malformed field prevents ingestion. A status API can describe indexed source progress without pretending that a single timestamp proves all documents are visible.

SOURCE COMMIT, INDEXING AND READER VISIBILITY HAVE DISTINCT BOUNDARIESSOURCE COMMIT, INDEXING AND READER VISIBILITY HAVE DISTINCT BOUNDARIESone source commitv8intentanalyzeprimaryreplicarefresh: local view changelocal reopen
Figure 15.33Illustrative end-to-end write trace. The final self-transition represents a local reader-view change.

The self-transition in the diagram names local state, not a network message. When drawing at a whiteboard, mark which arrows cross machines and which describe an internal action. This habit prevents invented latency and message counts. It also lets a reviewer ask precisely which step can repeat after a crash.

#Section 34The phrase query trace

The viewer queries red bird. The query analyzer emits red and bird with an adjacent phrase rule. The coordinator selects one usable copy of each relevant shard. A shard reads the two posting lists, intersects candidate IDs, checks their positions, applies visibility filters, and computes the selected scoring contributions.

In the tiny corpus the intersection is document 1. Its positions are 1 and 2, so the exact phrase qualifies. Its BM25 contributions sum to 1.049822 under our explicit formula. The shard returns an ID, score, and stable tie-break value. The coordinator chooses global winners and fetches their display fields before the API responds.

A PHRASE QUERY CHECKS IDS, POSITIONS, PERMISSION AND SCOREA PHRASE QUERY CHECKS IDS, POSITIONS, PERMISSION AND SCOREquery: red birdred13bird124doc 11 → 2adjacent positionscurrent permission1.049822score under stated formulafetch display content only after eligibility and winner selection
Figure 15.34Computed illustrative query trace. Score is rounded to six decimals and only compares results under the stated scoring model.

If the phrase finds document 1 but its current permission excludes the viewer, the visible answer is empty. That is a correct negative result despite a positive lexical match and score. The API must also omit its highlight and hidden-document contribution to counts. Walking this branch explains why the permission stage remains necessary inside a supposedly public text-search mechanism.

If the user searches without quotes, the product may choose all-term matching rather than adjacency. Make that decision in query construction. Do not change phrase semantics silently because a broad query is cheaper. A useful interview answer names the exact query contract and follows its representation through the engine.

#Section 35The deletion and recovery trace

The owner deletes report 1 at version 9. A durable publication record transfers that decision to the indexer. The consumer records the higher version and removes search visibility. A later replay of version 8 fails its version check. Private suggestion caches and other derived search copies also need the deletion rule.

If the index fails after applying the delete but before advancing its source checkpoint, replay repeats version 9 harmlessly. If it fails before applying the delete, replay applies it on recovery. This is the reason to make the effect idempotent and checkpoint only resolved work. Exactly-once transport is not required to make the document’s final state converge correctly.

REPLAY KEEPS THE HIGHER DELETION VERSION AUTHORITATIVEREPLAY KEEPS THE HIGHER DELETION VERSION AUTHORITATIVEdelete v9doc 1version 9late v8repeat v9v8 rejectedcheckpoint after the resolved deletion; repeated v9 has no new effect
Figure 15.35Illustrative recovery trace. The deletion version remains authoritative across repeated and late delivery.

During an outage, the product chooses between stale search, disabled search, or a limited alternative. It should not let an unrestricted source scan absorb every failed search request. Recovery capacity must exceed ongoing change input to drain the backlog. Search availability and deletion freshness may deserve different incident policies.

#Section 36Count the whole design and defend its limits

The illustrative source contains 500,000,000 report bytes. The assumed searchable representation uses 750,000,000 bytes, divided into four primaries of 187,500,000 bytes each under equal balance. Three total copies per shard produce twelve shard copies and 2,250,000,000 data bytes. Temporary segments, merges, snapshots, caches, and reindex overlap are separate additions.

The assumed query workload creates 4,000 shard executions per second and up to forty candidates for a top-ten request before fetch. The source changes at 20 per second. A one-second refresh exercise groups twenty changes. A 200-second reindex copy overlaps 4,000 changes that must be replayed. These values reconcile with the same workload rather than changing the service between examples.

ACCOUNT FOR THE LOGICAL INDEX AND ALL PHYSICAL COPIESACCOUNT FOR THE LOGICAL INDEX AND ALL PHYSICAL COPIEScopycopyP0187,500,000 BcopycopyP1187,500,000 BcopycopyP2187,500,000 BcopycopyP3187,500,000 B750,000,000 B × 3 copies = 2,250,000,000 B4 primary shards × 3 = 12 shard copiestemporary segments, merges, snapshots and rebuild overlap are additional
Figure 15.36Computed illustrative capacity summary. The index expansion ratio and throughput assumptions require measurement before deployment.