Consumer groups and rebalancing
We share partitions among several processes. A process can be alive but no longer own its assignment. We will follow group membership, rebalance, parallelism, and bounded processing.
#Section 17Consumer groups and independent applications
Several projector processes should divide one workload, while notifications should read every relevant event independently. A consumer group gives one logical application a shared partition assignment and durable progress.
In the standard group model used here, one partition has one active assigned member within the group. Another group can independently read that same partition from another position. Four partitions and six members give at most four active partition owners and two idle members under the simple balanced assignment. More members do not create more than four partition-local sequential processing lanes. Kafka 4.1’s share groups and protocol variants should not be mistaken for this introductory ownership contract.
Use the notification application as a separate group rather than another projector member. Within the projector group, the assignment divides partition work among members and shares their logical application’s progress. Across groups, notifications can independently read records the projector already handled. An idle projector member does not create another partition-local lane in the illustrated ordinary-group contract. Assigning a different group identity on every restart would also create another history rather than resume the intended application position. Group identity therefore belongs to the application’s recovery model, not merely to a temporary process name.
Putting projector and notification processes in the same ordinary group makes them divide records instead of each application seeing the required history.
#Section 18Heartbeats, polling, and failure detection
A process sends heartbeats while its application thread stops making progress. Failure detection suspects unavailable or stalled group members using protocol timers and progress rules. Heartbeats and application polling answer different questions.
Bound processing batches so the client can satisfy the documented group behavior. A member that cannot poll or renew as required can lose its assignment even while its process is alive. Large records and blocking outside calls can turn an apparently healthy connection into a stalled consumer. Use pause and bounded worker queues carefully: moving work off the poll thread does not remove the need to commit only completed contiguous work. Timer values trade detection speed against false suspicion under pauses.
A member can continue sending heartbeats while an outside database call prevents its application from finishing the fetched batch. The coordinator can therefore receive evidence of protocol liveness while the last durable offset remains 102. If the applicable progress limit expires, ownership can move and a replacement begins at 102. The old database call may still complete later. A timed sequence must distinguish the last heartbeat, the last required poll, the ownership-expiry event and the last effect completion; only the timers appropriate to the chosen client protocol decide when revocation occurs.
Increasing a timeout can hide slow processing and delay recovery. It does not raise the effect system’s capacity.
#Section 19Rebalance and obsolete work
A consumer loses a partition while one of its fetched records is still being processed. A rebalance changes group assignments when membership or relevant metadata changes. The replacement can replay work from the committed boundary.
Stop accepting new work for a revoked partition, finish or cancel the permitted in-flight work under the protocol, and commit only a valid completed boundary while ownership allows it. Group generations reject obsolete progress updates. But an external database does not learn that generation automatically; a late old worker can still try its effect. Duplicate-safe source identity or explicit resource fencing protects that boundary. Cooperative and newer rebalance protocols can reduce disruption but do not make outside effects magically atomic with ownership.
Follow offset 102 through the handoff. The old member fetched it but has not recorded a safely completed prefix beyond 102. After revocation, the replacement starts at 102 and can attempt the same effect. If the old call later finishes, a broker generation check prevents its obsolete progress commit but does not undo its database call. The database must reject a stale resource generation or recognize the same source identity. A consumer that merely stops fetching after revoke still has this race unless it also handles its already-issued effects.
An application that keeps processing a revoked partition without a protection rule can race its replacement even if Kafka correctly rejects its old offset commit.
#Section 20Parallelism, skew, and contiguous progress
A consumer runs several tasks concurrently, and record 103 finishes before 102. Contiguous completion means every record below the committed next position has a safely represented effect.
Do not commit 104 merely because 103 finished. Preserve a completion map or another bounded tracker until 102 also completes; then the safe boundary can advance. If the domain requires sequential match state, parallelize across independent keys or partitions rather than reordering that match. A hot partition can limit one group despite many idle workers. Increasing partitions improves some parallelism but changes routing and history assumptions. Measure successful effect rate and oldest unprocessed age, not only fetch throughput.
The completion tracker must remain bounded while an earlier effect stalls. If 103 completes but 102 remains pending, retain the completed result and hold the durable next position at the safe prefix. Once 102 safely completes, the tracker can release the contiguous completed work and permit 104. If later tasks keep finishing while 102 never resolves, pause new application intake before the map grows indefinitely. The business ordering rule may require stopping that key earlier still. Successful parallel work is useful only when restart can distinguish its completed effects from the unfinished prefix.
Unlimited completion tracking is another queue. Bound the out-of-order window and apply backpressure when an early record stalls.