Data and Knowledge SystemsIngestion and freshnessPrincipal
How do you build a search index from a snapshot and change stream without losing updates or reviving deletions?
By Amit Kumar4 min readWorked answer includedReviewed 26 Sept 2026
The question
Interview question
A connector must load a hypothetical 200 million source objects into a new search index while edits and deletions continue. It can export a snapshot and consume a change stream, but an old snapshot record may arrive after a newer update. Design the bootstrap, explain when the index is safe to activate, and describe recovery if the change log expires before the export finishes. State which guarantees you need from the source.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
A new index needs both a starting view of the data and every relevant change after that view. A snapshot supplies the starting view. Change data capture, usually shortened to CDC, supplies a stream of committed edits and deletions. The difficult part is joining them without leaving a period in which a change belongs to neither path, or allowing an older snapshot record to overwrite a newer change.
Imagine a hypothetical document with revision 7 in the snapshot. While the export is still running, the source commits revision 8 and then deletes the document. The change consumer processes both events before the slow snapshot worker delivers revision 7. An index that accepts the last arriving write recreates a deleted document. All three messages arrived successfully. Their arrival order was simply different from their source order.
The first design requirement is a source-supported handoff. One possible contract provides a consistent snapshot associated with change position S, while retaining the log needed to consume changes after S. A change position identifies progress through the source's committed history. It is not the wall-clock time at an indexing worker. Establish retention before the export starts and record the snapshot's coverage and handoff position durably. “Finish the export, then turn on CDC” is unsafe if writes during the export can fall outside the retained stream.
At the destination, each object needs an ordering rule. If the source supplies comparable object revisions for both paths, use an atomic conditional update that accepts only a newer revision. Duplicate deliveries become harmless repeats. Represent deletion with a tombstone, a retained marker carrying the deleted identity and revision. The tombstone prevents revision 7 from recreating the object after its deletion. Removing the marker too early reopens that race, so its lifetime must cover any stale replay that the system still permits.
Do not assume every source supplies such revisions. A snapshot row may have no directly comparable log offset. In that case the connector needs an explicit coordination protocol for the overlap. Debezium's PostgreSQL incremental snapshot documentation describes chunk windows that buffer snapshot reads and discard a buffered read when a streamed update or deletion for the same key supersedes it. That is a specific implemented approach. It is not a guarantee that arbitrary exports and event feeds can be combined by sorting timestamps.
The ordering requirement continues after event consumption. Suppose revision 8 requires a slow embedding job and revision 9 finishes quickly. The embedding writer must also check the object's accepted source revision before publishing its output. Otherwise the connector is ordered but the final index is stale. Track parsing, embedding, writes and deletes through to query visibility, including failures that were moved aside for repair.
Build into a staging generation, an index version that readers do not yet use. A promotion record should identify completed snapshot partitions, the handoff, and the chosen catch-up positions. With a partitioned source, this may be a vector of positions rather than one global number. Require proof that all changes through those positions have been applied and are queryable. A consumer offset alone is insufficient if its downstream embedding queue still contains unfinished work. Keep current authorization at disclosure time, as in retrieval with fast permission revocation. Content completeness does not make an old permission snapshot authoritative.
Log expiry changes what can be proved. If the earliest required position has disappeared, continuing from the oldest available event can miss an update or deletion permanently. Mark the staging generation incomplete and stop promotion. Recover using a fresh consistent snapshot and handoff, or an authoritative reconciliation that can establish current identities, versions and removals at a defined boundary. Comparing a sample of documents cannot prove that an unobserved deletion was not missed.
For 200 million hypothetical objects, the operational trade-off is substantial. A long retained log consumes source storage. A large snapshot increases source load and extends the overlap. Chunked snapshots bound restart work but need their own collision handling. Monitor export rate, retained-log headroom, oldest unfinished downstream work and catch-up lag. If the source provides no consistent view, no adequate change history and no authoritative inventory, say that gap-free bootstrap cannot be guaranteed from that interface. Keeping the old generation serving is preferable to activating a new index whose completeness is unknown.
Related questions
Keep practising data and knowledge systems
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux