Spring Kafka, overriding max.poll.interval.ms?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
max.poll.interval.ms is a Kafka consumer setting, so in Spring Kafka you override it the same way you override other Kafka client properties: pass it into the consumer configuration. The important part is not only where to set it, but also understanding why the listener is taking so long that the poll interval needs to change.
What max.poll.interval.ms Controls
Kafka expects each consumer to keep calling poll() often enough to prove that it is still alive and making progress. If message processing takes longer than max.poll.interval.ms, the broker considers that consumer stuck and triggers a rebalance.
That usually shows up as repeated partition revocations, duplicate processing, or commit failures after long-running listener work.
This setting is different from session.timeout.ms. Heartbeats keep the consumer session alive, but max.poll.interval.ms still limits how long your code can go between poll cycles.
Set It Through Spring Kafka Consumer Properties
In Spring Boot, the safest generic approach is to pass the raw Kafka property through the consumer properties map.
That sets the poll interval to ten minutes. It is explicit and works even when a Kafka client property does not have a dedicated convenience field in Boot.
You can do the same programmatically:
Both forms are valid. Choose one place and keep the configuration centralized.
Increasing the Value Is Not the Whole Fix
If a listener needs more than five minutes regularly, the right fix is often architectural, not just a bigger timeout. Common causes are:
- processing too many records in one poll
- making slow network calls inside the listener thread
- doing large database batches synchronously
- blocking on retries instead of sending work elsewhere
Often you get better behavior by reducing max.poll.records, moving heavy work to another executor, or acknowledging after smaller chunks.
Example of reducing the number of records processed per poll:
That can shorten per-poll work enough that rebalances stop without pushing the interval to an extreme value.
Listener Container Timing Still Matters
Spring Kafka listener containers can add their own pacing behavior, such as idle time between polls. That delay still has to fit within the consumer’s poll-interval budget once actual record processing time is included.
So if you deliberately slow the container down, make sure the total time remains comfortably below the configured interval.
A Practical Tuning Strategy
A reasonable order is:
- measure how long a batch actually takes to process
- reduce batch size if the listener is doing too much work per poll
- move slow downstream work off the poll thread if possible
- increase
max.poll.interval.msonly after the above steps are understood
That sequence prevents the timeout from becoming a bandage for a design problem.
Common Pitfalls
The most common mistake is setting the property in the wrong place. It belongs in Kafka consumer properties, not in an unrelated listener annotation.
Another issue is confusing max.poll.interval.ms with heartbeat-related settings. They solve different failure modes.
A third problem is raising the interval drastically while leaving a slow, overloaded listener unchanged. That delays rebalances but does not improve throughput.
Summary
- Override
max.poll.interval.msthrough Spring Kafka consumer properties. - In Spring Boot,
spring.kafka.consumer.properties.max.poll.interval.msis the explicit form. - The Java equivalent is
ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG. - Tune batch size and listener design before relying only on a larger interval.
- Keep total processing time plus any container delay comfortably below the configured limit.
Related reading
- Spring Kafka Partitioning
- Spring Kafka Poll for new messages instead of being notified using `onMessage`
- Spring Kafka Producer not sending to Kafka 1.0.0 (Magic v1 does not support record headers)
- Spring Kafka producers throwing TimeoutExceptions
- Spring Kafka producers throwing TimeoutExceptions
- Spring Kafka SeekToCurrentErrorHandler Find Out Which Record Has Failed
- Spring Kafka The class is not in the trusted packages
- spring kafka thorws InstanceAlreadyExistsException exception after setting concurrency > 1

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.