Apache Kafka / Intermediate: contracts, failures and observability / Lesson 14
Parallel processing and commit frontiers
Track contiguous completed work when one consumer processes partition records concurrently.
On this page
Lesson goals
- Explain why completion order can differ from partition order.
- Calculate a safe contiguous commit frontier and reconcile in-flight work.
Separate delivery and completion
A consumer can receive ordered records from a partition and hand their business work to a bounded worker pool. The pool can finish a later record first. A committed offset represents the next position to read, so advancing it past unfinished work can omit that work after a restart. This lesson uses an application-level completion tracker; it does not claim the Kafka consumer is safe for arbitrary concurrent access.
Identify a completion gap
In this synthetic fixture, offsets 10 and 12 have completed but 11 has not. Assuming all earlier offsets were already safely completed, the contiguous completed prefix ends at 10 and the next safe position is 11. Committing 13 merely because 12 finished would skip 11 on a normal resume. The example does not execute a broker or specify a client implementation.
{"partition":0,"completed_offsets":[10,12],"unfinished_offsets":[11],"safe_next_offset":11}
Offset 11 remains unfinished; the next position cannot advance beyond it under the stated assumptions.
Advance only after the gap closes
After offset 11 completes and its required destination effect is durably acknowledged, all three offsets form a contiguous completed prefix. The next position can advance to 13 under this simplified contract. Actual applications must handle failed or ambiguous effects, bounded queues and the consumer’s poll requirements. A successful commit is progress evidence, not proof that an independent external system performed exactly one effect.
{"partition":0,"completed_offsets":[10,11,12],"safe_next_offset":13}
With 10 through 12 complete, 13 is the next offset in this synthetic partition.
Handle ownership changes
A rebalance or shutdown can occur while workers still hold records. Stop admitting work for revoked partitions, use the client’s supported ownership callbacks and reconcile completed and uncertain operations according to the deployment’s protocol. Do not allow a stale worker to commit progress for a partition it no longer owns. The exact callback and threading design must follow the client version and application architecture.
Test failure between effect and commit
In a disposable integration environment, process identifiable synthetic records and deliberately interrupt after one durable effect but before its progress is committed. Resume and verify that the same occurrence can be delivered again without duplicating the destination effect. Include an out-of-order completion and an unresolved failure. Capture partition, offset, event identity and destination result; do not infer end-to-end correctness from offset arithmetic alone.
Common errors and fixes
The consumer commits the highest completed offset plus one despite a gap.
- Why it happens
- Completion order was confused with the contiguous prefix.
- How to fix it
- Hold the frontier at the first unfinished offset.
- Prevent it next time
- Test out-of-order completion and interruption.
A worker commits after its partition was revoked.
- Why it happens
- Ownership was not coordinated with in-flight processing.
- How to fix it
- Stop work and reconcile using the client’s supported rebalance handling.
- Prevent it next time
- Exercise ownership changes under bounded load.
A replay repeats a payment or notification.
- Why it happens
- Offset progress was treated as external-effect deduplication.
- How to fix it
- Use a durable destination idempotency contract.
- Prevent it next time
- Test the effect-to-commit failure interval.
2 practice exercises
1. Offsets 10 and 12 are complete, 11 is unfinished and earlier work is complete. What is the next safe position?
Show worked solution
It is 11 under the stated assumptions. The finished 12 cannot move the contiguous frontier past 11. After 11 and its required effect complete, the frontier can move to 13 if no other earlier work is unresolved.
2. A destination accepted offset 11 but the worker crashed before committing. What happens on replay?
Show worked solution
The record may be delivered again. The destination must recognize the same business occurrence or otherwise apply an explicit repeat-safe contract. A commit made before the effect would instead introduce a risk of lost work.
Key takeaways
- Track the earliest unfinished position per partition.
- Coordinate ownership and destination effects independently of offset commits.