The interview problem
A product catalog has 100 million documents and receives 2,000 updates per second. Rebuild its distributed search index with a new analyzer while continuing to serve searches. Prevent old updates from resurrecting deleted products, avoid mixed analyzer generations within a query and support consistent multi-page results.
Original system-design practice, not a reported company interview. Capacities and timings are hypothetical. Primary technical documentation retrieved September 27, 2026; interview date not applicable.
1. Separate three consistency promises
Generation consistency means all shards used by one query share the intended analyzer, schema and scoring configuration. Freshness means the index has applied source changes through a specified watermark. Pagination consistency means subsequent pages traverse the same search view. None automatically provides the others.
The source database remains authoritative. Search may lag by an agreed interval, but eligibility and sensitive visibility changes require an authoritative check before returning protected content. Define whether partial shard results are acceptable; this exercise fails the query with a retryable error rather than presenting incomplete results as complete. Ranking and relevance validation remain release gates even if every document is present.
2. Build isolated generations
consistent source snapshot at W0 + retained change log
↓
generation G2 bulk loader + ordered replay
↓
shard readiness manifest and validation
↓
atomic active-generation pointer: G1 → G2
↓
query coordinator pins generation → shards → mergeEach generation has an immutable identity and manifest describing shard routing, analyzer version, schema and build lineage. Resolve the active pointer once when admitting a query, then carry the resolved generation through every shard request and retry. A worker must reject a generation mismatch instead of silently using whatever index is currently active on that machine.
Consider two shards, A and B. If each switches independently, a query can hit A's new analyzer and B's old analyzer. The merged scores then come from a configuration that was never validated. A single coordinator-resolved generation avoids that mixture even while old queries finish on G1 and new queries start on G2. Physical readiness of every required shard is a prerequisite to publication, not a consequence of changing a pointer.
3. Join the snapshot and update stream safely
Capture a consistent snapshot and its matching change-log boundary W0 using the database's supported protocol. Retain all later changes. Bulk-load the snapshot, then replay changes after W0, or overlap these activities with atomic per-document version checks. An approximate wall-clock start time is not a substitute for a gap-free snapshot/log boundary.
Every source mutation carries document identity, a monotonic per-document revision and an upsert or delete operation. Accept a write only if its revision is newer than the stored revision; identical revisions must have identical meaning or produce a corruption alert. For revision 10 upsert, revision 11 delete and delayed revision 10 retry, the final state remains deleted. Recreating the same document identity must continue its revision sequence or include an ordered incarnation identifier; resetting to revision one would conflict with the retained delete fence.
A delete must retain its revision as a tombstone or in a separate version fence. Removing both the document and its version allows an old retry to resurrect it. Retention must cover snapshot loaders, retry queues and all permitted replay horizons. If arbitrary historical replays are allowed, a short fixed tombstone TTL cannot prove safety; constrain replays or retain durable fences.
Track a contiguous applied watermark per source partition, not the maximum offset seen. Offset 105 applied while 104 failed does not mean the partition is complete through 105. Quarantined records block readiness unless an explicit, audited exclusion is part of the product contract. A partition vector need not represent a globally transactional snapshot; if cross-document atomic search visibility is required, add transaction-aware publication barriers rather than claiming it from independent offsets.
4. Budget rebuild and catch-up separately
At an effective bulk rate of 20,000 documents/second, 100 million documents take 5,000 seconds, or 83 minutes 20 seconds. If replay starts afterward, 2,000 changes/second produce 10 million queued changes. With replay capacity 6,000 changes/second while 2,000 new changes/second continue arriving, net drain is 4,000/second. Catch-up takes 2,500 seconds, or 41 minutes 40 seconds: 125 minutes total before validation overhead.
If replay capacity falls to the arrival rate, the backlog never drains; adding a cutover deadline does not solve that. The example assumes sustained rates and enough log retention. Account for throttling, replica recovery, index merging and hot keys. Parallel bulk and replay may reduce elapsed time but share resources and require version fencing.
Suppose each generation occupies 500 GB before replication and uses two total copies. Keeping old and new generations requires 2 × 500 × 2 = 2,000 GB, or 2 TB decimal. Adding 25% headroom gives 2.5 TB, excluding separately budgeted logs and snapshots. Measure actual index expansion and merge peaks; source-document bytes are not index bytes.
5. Publish only a query-ready generation
Choose a validation watermark vector W1. Require complete replay through W1, search visibility of those writes on the replicas eligible to serve, compatible configuration and healthy shard coverage. A successful indexing acknowledgement may precede search visibility. Compare counts by partition, deterministic document samples, deletion cases and representative queries; counts alone miss replacement or content errors.
Serialize publication through a control-plane transaction or compare-and-swap from expected G1 to G2. If another publisher has already changed the pointer, stop and reconcile instead of overwriting it. For the strict cutover promise, new query admission uses a linearizable pointer read or a coordinated epoch barrier; independently expiring coordinator caches would allow additional G1 admissions after publication. Generation pinning alone prevents mixing, but does not make cached pointer reads fresh. Continue consuming source changes into G2. The operation publishes a generation atomically for coordinators; it does not make every subsequent source mutation globally atomic across shards.
Retain G1 for bounded in-flight queries and rollback. Keep it consuming compatible source updates during the rollback window, or explicitly catch it up before reverting. Otherwise rollback may restore old documents and permission metadata. If the analyzer change also requires application changes, version the query contract and deploy compatible readers before switching.
6. Pin a search view across pages
An immutable generation identity alone is insufficient because documents within it continue updating. Use a point-in-time search view with a stable sort and tie-breaker. A cursor binds the view, generation, query/filter digest, last sort values, expiration and caller context. Validate current authorization on each request; a cursor is not a permanent access grant.
Elasticsearch documents search_after with a point in time for stable traversal; requests preserve query and sort and use the latest returned PIT identifier. Apply the equivalent contract in the chosen engine. Without a stable view, a product whose sort position changes between pages can be skipped or repeated even when the generation stays unchanged.
Bound active views and their lifetime because they retain resources. On expiration, return an explicit restart-required result rather than silently opening a different view and claiming continuation. Enforced deletions or access revocations may require filtering old-view results or invalidating the cursor; explain that security takes priority over historical completeness.
7. Failure drills and self-review
Test a delayed old upsert after deletion, a shard missing a replay offset, a coordinator retry after publication, incompatible query code, expired pagination state and a rollback after source updates. Observe replay lag per partition, search-visible lag, rejected stale revisions, shard failures, query latency and relevance changes. A small average lag can hide one permanently blocked partition.
Trade-offs: Dual generations cost storage and indexing capacity but make publication and rollback explicit. Short pagination lifetimes reduce retained resources but interrupt long traversals. Version tombstones preserve ordering at storage cost. Fail-closed shard behavior protects completeness at an availability cost.
Follow-ups: Does changing an alias ensure documents are caught up? No. Can the largest seen offset prove readiness? No, gaps matter. Can an old generation be immediately deleted after cutover? Not while supported readers or views still need it. Does a PIT guarantee current permission? No, authorization needs its own enforcement.
Score 0–2 each for generation pinning, gap-free capture, update/delete ordering, realistic catch-up math and pagination/rollback semantics. A strong answer names exactly which consistency guarantee each mechanism supplies.
Sources and next steps
- Elasticsearch: paginate search results — search_after, tie-breakers and point-in-time traversal; documentation publication date not established.
The generation protocol, failure cases and capacity calculations are original design proposals, not claims of automatic engine guarantees. Continue with change-data capture for transport details and online shard migration for moving authoritative data ownership.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.