Quick revision
The short answer
session.timeout.ms (45 s) detects a dead process: a background heartbeat thread sends a heartbeat every heartbeat.interval.ms (3 s), and if the coordinator hears none for 45 s it removes the member and rebalances. max.poll.interval.ms (5 minutes) detects a live process whose processing thread is stuck or too slow: if poll() is not called within it, the client leaves the group itself. max.poll.records (500) only limits how many already-fetched records one poll() returns; fetching is separate and fills a buffer in the background of poll().
What to remember
In this answer, we saw that the session timeout and the poll interval protect against different failures. Heartbeats from a background thread every 3 s keep the session alive, and the coordinator removes a member it has not heard from for 45 s, catching dead processes. max.poll.interval.ms, enforced by the client, catches a live process whose code has not called poll() for 5 minutes, and makes it leave the group. max.poll.records only limits how many buffered records each poll returns, and commits after a member has left fail with CommitFailedException while the new owner reprocesses. With group.protocol=consumer, the heartbeat and session settings move to the broker.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
session.timeout.ms (45 s) detects a dead process: a background heartbeat thread sends a heartbeat every heartbeat.interval.ms (3 s), and if the coordinator hears none for 45 s it removes the member and rebalances. max.poll.interval.ms (5 minutes) detects a live process whose processing thread is stuck or too slow: if poll() is not called within it, the client leaves the group itself. max.poll.records (500) only limits how many already-fetched records one poll() returns; fetching is separate and fills a buffer in the background of poll().
Why this question is asked
Consumers that are kicked out of their group, rebalances that never seem to end, and CommitFailedException in the logs all trace back to these few settings. Interviewers ask about them because the two timeouts look alike but protect against different failures, and mixing them up leads to the wrong fix, usually raising the wrong number. In this answer, we will recap the consumer group and the poll loop, then look at the heartbeat and session timeout, the poll interval, what max.poll.records really limits, what happens to commits after a member is removed, and how the new consumer group protocol moves some of these settings to the broker.
1A Quick Recap of the Consumer Group and the Poll Loop
A consumer group is a set of consumers sharing the work of reading a topic. Each partition is assigned to exactly one member, and a broker called the group coordinator tracks who is in the group. When membership changes, the group rebalances: partitions are reassigned among the remaining members.
Our code drives the consumer with a loop: call poll(), process the records it returns, commit offsets, call poll() again. Everything the consumer does on our behalf, fetching data, sending commits, joining a rebalance, happens inside these poll() calls or on a background thread. The timeouts exist because the coordinator needs to know two things about each member: is the process alive, and is it actually making progress?
2Heartbeats and session.timeout.ms: Is the Process Alive?
In the classic protocol, the consumer starts a background heartbeat thread. Every heartbeat.interval.ms, 3 s here and by default, it sends a heartbeat to the coordinator. As long as heartbeats arrive, the coordinator considers the member alive. If none arrives for session.timeout.ms, 45 s here and the default since Kafka 3.0 (it was 10 s before), the coordinator declares the member dead, removes it, and rebalances its partitions to others.
Because the heartbeat thread runs independently of our processing, a consumer busy processing a slow batch still heartbeats happily. So the session timeout catches a crashed JVM, a killed pod, a long garbage-collection pause or a network cut, but it cannot see a processing thread that is stuck. The 3 s interval is usually a third or less of the session timeout, so a couple of lost heartbeats do not trigger a rebalance.
3Max.poll.interval.ms: Is the Processing Thread Making Progress?
The second timeout covers the case the heartbeat cannot see. If our thread does not call poll() again within max.poll.interval.ms, 300,000 ms or 5 minutes by default, the consumer concludes that processing is stuck or too slow. The client itself enforces this: the heartbeat thread notices the overdue poll, stops heartbeating, and sends a request to leave the group, so the coordinator rebalances the member's partitions to others right away. (A static member, one with group.instance.id, does not send the leave request; it stops heartbeating and its partitions move when the session timeout expires.)
This is also the deadline for joining a rebalance: members must call poll() to take part, so a member deep in a slow batch holds up the whole group's rebalance until it polls or its poll interval runs out.
| Setting | Default | Enforced by | Catches |
|---|---|---|---|
heartbeat.interval.ms | 3 s | client heartbeat thread | how often liveness is reported |
session.timeout.ms | 45 s (since 3.0) | coordinator on the broker | crashed process, network cut, long GC pause |
max.poll.interval.ms | 300 s | client, which leaves the group | processing thread stuck or too slow |
max.poll.records | 500 | client | nothing; it only sizes what poll() returns |
4What max.poll.records Really Limits
max.poll.records, 500 by default, is often mistaken for a fetch size. It is not. The consumer fetches data from brokers in fetch requests sized by the fetch settings (fetch.min.bytes, fetch.max.bytes and max.partition.fetch.bytes) and keeps the results in an internal buffer. poll() then hands our code at most max.poll.records records from that buffer. If the buffer already holds 2,000 records, four successive polls return 500 each without any new network request.
So max.poll.records is really a lever on processing time per loop. If each record takes 100 ms, 500 records take 50 s, comfortably inside 5 minutes. If each record takes 1 s, 500 records take 500 s, and the consumer is pushed out of the group. Lowering max.poll.records is the usual first fix, because it shortens each loop without hiding a genuinely stuck consumer.
5What Happens to Commits After the Member Has Left
Suppose a batch took 6 minutes. While we were processing, the client left the group and the coordinator gave our partitions to another member, which started reading from the last committed offset. When our loop finally calls commitSync(), the commit is rejected with CommitFailedException, because we are no longer the owner of those partitions.
Notice the consequence: the new owner starts from the old committed offset and processes those 500 records again. That is why a consumer that keeps exceeding its poll interval produces duplicate processing and repeated rebalances, and why the processing it does must be idempotent.
6How the New Consumer Group Protocol Changes This
Kafka 4.0 made a new consumer group protocol generally available, enabled per consumer with group.protocol=consumer. In it, heartbeat timing and session expiry are controlled by the broker: group.consumer.session.timeout.ms and group.consumer.heartbeat.interval.ms are broker settings, and the client's session.timeout.ms and heartbeat.interval.ms no longer apply. max.poll.interval.ms stays a client setting with the same meaning, because only the client knows whether our code is calling poll().
So the mental model survives the change: one timer for 'is the process alive', owned by the coordinator, and one for 'is the code making progress', owned by the client.
7Follow-up questions
Should I raise session.timeout.ms when my processing is slow?
No, that is the most common mix-up. Slow processing is caught by max.poll.interval.ms, and the heartbeat thread keeps the session alive meanwhile. Raising the session timeout only makes the group slower to notice a crashed consumer. Shorten the batch with max.poll.records, speed up processing, or raise max.poll.interval.ms if the work is genuinely long.
Why is the default session timeout 45 s and not 10 s any more?
Cloud networks and container platforms produce short pauses, such as a brief network blip or a long garbage collection, that used to exceed 10 s and trigger needless rebalances. Kafka 3.0 raised the default to 45 s so that such hiccups do not disrupt the whole group, accepting that a truly dead consumer is detected a bit later.
Does poll() with a long timeout risk the poll interval?
No. The timeout passed to poll() is how long it may wait for data when there is none; it returns as soon as records are available. What risks the interval is the time between poll() calls, which is our processing time.
8Conclusion
In this answer, we saw that the session timeout and the poll interval protect against different failures. Heartbeats from a background thread every 3 s keep the session alive, and the coordinator removes a member it has not heard from for 45 s, catching dead processes. max.poll.interval.ms, enforced by the client, catches a live process whose code has not called poll() for 5 minutes, and makes it leave the group. max.poll.records only limits how many buffered records each poll returns, and commits after a member has left fail with CommitFailedException while the new owner reprocesses. With group.protocol=consumer, the heartbeat and session settings move to the broker.
Open with
There are two different questions the group needs answered about each consumer. First, is the process alive? A background heartbeat thread sends a heartbeat every heartbeat.interval.ms, three seconds here, and if the coordinator on the broker hears nothing for session.timeout.ms, 45 seconds by default since Kafka 3.0, it removes the member and rebalances.
Then, if they want more
That catches crashes, killed pods, network cuts and long GC pauses. But because the heartbeat runs on its own thread, it cannot see a stuck processing thread. That is the second question, is it making progress, and it is answered by max.poll.interval.ms, five minutes by default.
If my code does not call poll again within that time, the client itself leaves the group and its partitions are reassigned. max.poll.records, 500 by default, is not a fetch size at all: fetching fills a buffer according to the fetch settings, and max.poll.records only caps how many of those buffered records one poll returns, so it is my main lever on processing time per loop.
If I do exceed the poll interval, my later commit fails with CommitFailedException and the new owner processes those records again, so processing must be idempotent. With the new protocol, group.protocol=consumer, the session and heartbeat settings move to the broker, while max.poll.interval.ms stays on the client.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Kafka 3.0, Kafka 4.0
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain which failure each timeout detects, which thread enforces it, and how poll()...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/a212e4c82a/