Video in progress
The consumer log says "max.poll.interval.ms exceeded" and messages keep coming again and again. What's going on and how do you fix it?
The listener can't process the messages from one poll within max.poll.interval.ms (5 minutes by default). The consumer is removed from the group, the offset isn't committed, the partition moves to another consumer, and the same messages are processed again.
📖 Answer
It's almost always the same loop: 500 messages fetched → each one calls a slow external API → 5 minutes pass → rebalance → the commit fails (CommitFailedException) → another pod gets the same 500 → it can't finish either.
Ways to fix it, usually in this order:
- Reduce the number of messages per poll:
spring:
kafka:
consumer:
max-poll-records: 50
- Cut the processing time of each message: put timeouts on external calls, remove N+1 queries.
- If the work is truly long, increase
max.poll.interval.ms. But that also lengthens the time it takes to take the partition back after a crash.
For diagnostics, export the processing time of a single message as a metric (Timer). Often the problem isn't "Kafka is slow" but one slow SQL query inside the listener.
The heartbeat runs on a separate thread, so session.timeout.ms isn't the culprit here. Don't mix them up.
Sign up to mark studied questions and save your progress.