Distributed ReliabilityRetry, idempotency and ownershipPrincipal
What does zero Kafka consumer lag prove about an asynchronously updated search index?
By Amit Kumar4 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A Kafka consumer sends source changes to asynchronous indexing workers and commits offsets. The consumer reports zero lag, but yesterday’s document updates are not searchable. Explain what that metric establishes, trace the durable handoff and query-visibility boundaries, and design safe progress tracking when indexing tasks finish out of order. Include crash recovery and Kafka’s next-offset commit convention.
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
Kafka consumer lag measures progress through a log. It does not directly measure whether the search index contains the corresponding changes. A consumer can stop having unread messages while another queue still contains hours of unfinished parsing, embedding or indexing work. The investigation must follow a source change until readers can actually retrieve its intended revision.
A Kafka offset names a position within one topic partition. A committed offset tells a replacement consumer where to resume. Under the usual convention, it is the next position to read, not the last completed record. Kafka’s consumer guidance discusses coordinating processing with commits. Confluent’s consumer-lag documentation describes the log-position measurement. Neither turns a committed offset into a search-visibility receipt.
Start with one missing document and its source revision. Find its topic partition and offset, enqueue request, durable enqueue acknowledgement, indexing attempt, accepted write and refresh or visibility result. The index may have rejected the new revision while leaving the old one searchable. A successful process exit or HTTP response from an upstream stage does not resolve that question. Preserve source identity through these steps so the trace concerns the same document version.
The queue’s contract determines the first safe handoff. If it durably stores work before acknowledging enqueue, and the consumer commits only after that acknowledgement, a crash between enqueue and commit can produce a duplicate on replay. That is an at-least-once path, not necessarily data loss. The queue must retain and retry the work until its downstream completion contract is met. An in-memory submission or a commit before durable enqueue leaves a different window in which the source record can be skipped after restart.
The sink needs an idempotent application rule so duplicate attempts do not create duplicate active chunks or repeat relative updates. For a full-state document version, a conditional revision check can prevent an old retry replacing a newer state. Sparse patches need ordered application or another protocol preserving all changed fields. Rejecting every older patch after accepting a newer independent field change can lose valid data. Kafka producer transactions alone do not make an arbitrary external search engine participate in a single atomic commit.
Asynchronous completion requires a safe progress boundary rather than the largest successful offset. Consider a hypothetical partition delivering records 100, 101 and 102. Tasks for 100 and 102 finish, while 101 fails. If completion is the commit criterion, committing 103 would skip the failed task on restart. The safe next offset is 101 until its required work completes. After it does, the boundary can advance to 103 because 102 is already complete. Track an ordered set of outstanding delivered records and advance only across completed work.
This is a contiguous processing prefix in the delivered log order. It does not mean every integer offset must appear as an application record. Compaction and transactional visibility can create numeric gaps. Use the consumer’s documented position and isolation semantics, and never cross an earlier delivered record whose work remains unresolved. Maintain separate boundaries per partition because offsets from different partitions are not comparable.
Also distinguish durable acceptance from query visibility. A search write can be durable while refresh is pending. A pipeline that safely commits after durable queue handoff can have zero Kafka lag and a large visibility backlog without losing data. Track the oldest pending source change, durable handoff progress and query-visible progress separately. If retries finish out of order, the visibility boundary needs the same gap accounting. A maximum revision from one fast document cannot certify all other documents.
Recovery depends on which evidence survived. If the durable queue still contains failed work, repair the failure and retry it. If the consumer skipped work but Kafka retains it, replay a bounded interval using version-safe writes. If the required records expired, reconcile current source identities and revisions through a source-supported snapshot/change-stream handoff. Current-state repair may be possible even when the intervening history is gone. State which guarantee was recovered.
Test crashes before enqueue, after durable enqueue, after index acceptance and before visibility acknowledgement. Include one deliberately delayed task between two successful tasks and a rebalance while work is outstanding. The replacement must not skip that task or accept stale completion from an old owner as proof of the new generation’s state. The useful completion signal names the durable and visible boundaries. Zero transport lag remains one measurement within that chain.
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