When hardening Kafka consumer groups, size max.poll.records for p99 downstream latency and switch to CooperativeStickyAssignor.
TL;DR30-second simplified summary▾
Incremental rebalances + bounded poll batches keep throughput steady.
Heartbeat Thread vs. max.poll.interval.ms.
Background heartbeats only prove network liveness; max.poll.interval.ms enforces forward processing progress between poll() calls.
CooperativeStickyAssignor & Static Membership.
CooperativeStickyAssignor only revokes partitions that must move, leaving healthy partitions uninterrupted, while group.instance.id absorbs rolling restarts.
props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, "50");
props.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG, CooperativeStickyAssignor.class.getName());
props.put(ConsumerConfig.GROUP_INSTANCE_ID_CONFIG, System.getenv("POD_NAME"));
props.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "45000");
Async Worker Decoupling with pause() / resume().
If downstream latency is unbounded, pause() assigned partitions and call poll(0) to keep liveness alive without fetching more records. [INSERT YOUR BENCHMARK / PROD NOTE] for lag recovery.
- poll() blocked > 300s
- max.poll.interval.ms exceeded
- Eager rebalance storm
- poll(0) resets 300s timer
- 0 new records fetched while paused
- 0 group evictions
- Problem
- Prevent max.poll.interval.ms evictions and stop-the-world rebalance storms when downstream I/O latency spikes or pods perform rolling restarts.
- Naive Solution
- Keep default max.poll.records=500 with eager RangeAssignor and rely on background heartbeats for liveness.
- Why It Fails
- Background heartbeats only verify socket liveness; slow batches exceed max.poll.interval.ms (300s), triggering eviction and revoking 100% of group partitions.
- Alternatives
- Increase max.poll.interval.ms indefinitely (delays dead-consumer detection) or use manual assign() without consumer group coordination (loses automatic failover).
- Engineering Decision
- Pair bounded max.poll.records sized for p99 processing latency with CooperativeStickyAssignor, static group.instance.id, and pause()/resume() backpressure for unbounded downstream calls.
- Trade-Offs
- Smaller batches slightly increase poll() overhead and two-round cooperative rebalances take an extra sync cycle for moved partitions, in exchange for uninterrupted healthy partitions.
Why does calling poll(0) on paused partitions prevent max.poll.interval.ms eviction without overloading workers?
| Choice | What it buys | What it costs |
|---|---|---|
| RangeAssignor (Eager) | Simple single-round partition assignment | Stop-the-world (100% of partitions revoked) Full consumer group pause during rolling deploys |
| CooperativeStickyAssignor | Incremental handoff with zero stop-the-world pause Only moved partitions pause during rolling deploys | Requires two-round rebalance protocol for moved partitions |
Practice: Make the trade-off yourself.
Why can a healthy Kafka consumer with an active background heartbeat thread still be kicked out of its consumer group?