Distributed ReliabilityRetry, idempotency and ownershipPrincipal
Why do Kafka transactions not guarantee exactly-once updates to an external search index?
By Amit Kumar2 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A consumer writes document revision 17 to a search index, then crashes before committing its Kafka position. Replay creates duplicate chunks. Explain the transaction boundary and reversed-write-order failure, then design stable identities, revision gates, partial-publication recovery and a truthful user-visible invariant for an arbitrary index API.
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
First ask what was inside the transaction. Kafka can atomically commit produced Kafka records and the consumed offsets. An external search index is a different state store. Writing there and committing a Kafka offset are two operations unless we have built a separate coordination scheme. Kafka's design documentation says this external-system boundary is the limitation to account for when discussing exactly-once processing.
Suppose the consumer indexes document revision 17 successfully, then crashes before committing offset 900. A replacement consumer reads offset 900 and indexes revision 17 again. If the index write is an upsert with stable document ID, version and deterministic contents, replay may be harmless. If it appends a fresh chunk ID, increments a counter or sends a notification, the duplicate is visible. Reversing the order is worse: commit the offset first, then crash before indexing, and Kafka will not replay that event through normal consumption. Calling the Kafka transaction exactly once does not close either external gap.
For an indexer I would use stable source document and chunk identities, carry a monotonic source revision, and make writes idempotent. A stale revision must not overwrite a newer one. Record progress in the same store as the effect when that store supports an atomic transaction, or use an inbox and durable publication marker with a reconciliation loop that can compare source revision, index revision and Kafka position. Not all search engines offer the same atomicity or external versioning semantics, so I would check the actual API before claiming the fix is guaranteed.
For a hypothetical revision with 50 chunks, write deterministic chunk IDs into a staged generation. A crash after 30 writes leaves that revision unpublished. Retry fills or replaces the same 50 IDs, validates completeness, then makes the completed generation eligible through a publication record that readers enforce. The prior complete revision can remain visible under the product’s freshness policy. This requires an actual conditional publication mechanism and generation-aware reads. A marker in an unrelated database cannot magically make arbitrary index queries atomic.
The interviewer may push for a universal exactly-once switch. There is none across an arbitrary external index. Define the user-visible invariant instead: for each source document, the index eventually exposes at most the latest authorized revision, and replays do not multiply chunks. Test crashes immediately before and after the index call, timeouts with unknown outcome, and partition reassignment. Kafka lag is zero. Why is the search index missing yesterday's updates? covers zero Kafka lag with missing index updates. Here the advertised transaction works within Kafka, while the external index effect can be repeated.
Related questions
Keep practising distributed reliability
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