Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Breaking Kafka max.poll.interval.ms
Rebalance Death Spirals.

Downstream DB latency turns a 500-record Kafka batch into a 400s stall, exceeding max.poll.interval.ms and trapping the group in an infinite rebalance loop.
Start the journey3 stages· Last modified Dec 2, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When resolving Kafka rebalance storms, bound max.poll.records below half of max.poll.interval.ms at worst-case latency.

TL;DR30-second simplified summary
▾

Bounded batches + incremental rebalances restore steady throughput.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Kafka CommitFailedException diagnostics
Core prerequisite: Kafka CommitFailedException diagnostics.
Consumer offset commit lifecycle
Core prerequisite: Consumer offset commit lifecycle.
Full walkthrough · 3 stages
01
L4 · FUNDAMENTALS

Diagnosing the CommitFailedException Loop.

Logs show CommitFailedException: Commit cannot be completed since the group has already rebalanced, with consumer lag climbing continuously.

Before · Naive
After · Hardened
02
L4 · FUNDAMENTALS

Bounded Batching & Pause/Resume Flow Control.

Cap max.poll.records=50 and pause partitions when async worker queues fill up.

conf = {
    'group.id': 'orders',
    'max.poll.interval.ms': 300000,
    'partition.assignment.strategy': 'cooperative-sticky',
}
# Fetch <= 50 messages per batch so processing finishes in ~40s << 300s
03
L5 · APPLIED DESIGN

Idempotent Consumers for At-Least-Once Recovery.

Pair rebalance prevention with idempotent DB upserts so any transient partition handoff never creates duplicate side effects. [INSERT YOUR BENCHMARK / PROD NOTE] for drain speed.

Before · Before Fix (Default 500-Record Batch)
  • Batch Duration: 400s (Evicted)
  • Net Throughput: 0 msg/s
After · After Fix (max.poll.records=50 + CooperativeStickyAssignor)
  • Batch Duration: 40s (Safe)
  • Net Throughput: 12,000 msg/s
Engineering Decision Framework
Problem
Downstream DB latency spikes turn a default 500-record poll batch into a 400s stall, exceeding max.poll.interval.ms (300s) and causing CommitFailedException rebalance loops.
Naive Solution
Increase max.poll.interval.ms to 30 minutes so slow batches do not trigger coordinator eviction.
Why It Fails
Inflating max.poll.interval.ms masks genuinely hung or deadlocked consumers for 30 minutes, delaying partition recovery and letting lag grow unchecked.
Alternatives
Lower max.poll.records to 50 (40s batch) with CooperativeStickyAssignor, or offload work to an async worker pool paired with pause()/resume() and poll(0) heartbeats.
Engineering Decision
Cap max.poll.records at 50, enable CooperativeStickyAssignor, and pair with idempotent DB upserts and pause()/resume() backpressure.
Trade-Offs
Increases poll() and offset commit frequency slightly in exchange for predictable <300s poll intervals, incremental rebalances, and fast dead-pod detection.
Decision Exercise · Make the Call

Why does simply increasing max.poll.interval.ms to 30 minutes mask the problem and hurt recovery?

ChoiceWhat it buysWhat it costs
Default 500-Record Batch (Before Fix)Fewer poll() round-trips under healthy 20ms DB latencyBatch Duration: 400s (Evicted) Net Throughput: 0 msg/s
Bounded 50-Record Batch + CooperativeStickyAssignor (After Fix)Batch Duration: 40s (Safe) Net Throughput: 12,000 msg/sSlightly more frequent poll() and offset commit calls
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 1
Score: 0/1

What does CommitFailedException indicate in a Kafka consumer?

Recommended Learning Flow