Quick revision
The short answer
Worst-case batch time is roughly records times slow-call latency: 500 records at 0.9 s is 450 s, well above the 300 s max.poll.interval.ms, so in slow periods the consumer is pushed out of the group and the group rebalances again and again. I would lower max.poll.records so a slow batch fits with margin, about 150 records for 135 s, rather than relying on a larger interval, and add per-call timeouts, a circuit breaker and bounded concurrency so a downstream outage fails fast instead of stalling the batch, using the error handler's back-off or a paused container in Spring Kafka.
What to remember
In this answer, we did the arithmetic: 500 records at the p99 latency of 0.9 s take 450 s, beyond the 300 s poll interval, so slow periods push the consumer out and cause repeated rebalances and reprocessing. Lowering max.poll.records to about 150 keeps the worst case near 135 s, while raising the interval would hide stuck consumers and slow rebalances. Per-call timeouts, a circuit breaker and bounded concurrency make batch time predictable, and Spring Kafka's error handler back-off or pausing the container handle outages without letting polls time out.
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.
Worst-case batch time is roughly records times slow-call latency: 500 records at 0.9 s is 450 s, well above the 300 s max.poll.interval.ms, so in slow periods the consumer is pushed out of the group and the group rebalances again and again. I would lower max.poll.records so a slow batch fits with margin, about 150 records for 135 s, rather than relying on a larger interval, and add per-call timeouts, a circuit breaker and bounded concurrency so a downstream outage fails fast instead of stalling the batch, using the error handler's back-off or a paused container in Spring Kafka.
Why this question is asked
Repeated rebalances under downstream slowness are a classic production pattern: the downstream gets slow, consumers get kicked out, the group stops to rebalance, lag grows, and the reprocessed records add even more load on the slow service. Interviewers ask this scenario to see whether we can reason with numbers rather than guess at settings. In this answer, we will work out why the consumer is being removed, size max.poll.records, weigh raising max.poll.interval.ms, make the processing itself robust, and see how Spring Kafka helps.
1Recap: Why a Slow Batch Causes a Rebalance
A consumer must call poll() at least every max.poll.interval.ms, 300 s by default. A batch listener receives the records from one poll, processes them, and returns; only then does the container call poll() again. So the time to process one batch must stay under 300 s. If it does not, the client leaves the group, its partitions are reassigned, and the batch it was working on is processed again by the new owner, because its offsets were never committed.
2Working Out the Worst Case
Normal batches take 45 s, consistent with 500 records at about 90 ms each, close to the 80 ms median. But in slow periods the downstream is slow for everyone, so most calls in a batch approach the p99 rather than the median. Planning with the p99 as the per-call latency gives the realistic worst case.
| max.poll.records | Normal (80 ms) | Slow period (900 ms) | Fits in 300 s? |
|---|---|---|---|
| 500 (default) | 40 s | 450 s | No |
| 250 | 20 s | 225 s | Barely |
| 150 | 12 s | 135 s | Yes, over 2x margin |
| 100 | 8 s | 90 s | Yes, more polls per second |
Notice the feedback loop. When a member is removed after 300 s, the new owner reprocesses up to 500 records it already called the downstream for, adding load exactly when the downstream is struggling. Every rebalance also pauses consumption for the group while partitions move. That is how 'some polls take over 5 minutes' turns into 'the group rebalances repeatedly'.
3Choosing max.poll.records
The rule is to pick the largest batch whose worst-case time fits comfortably inside the interval, with a margin of about 2x for latency we have not measured. 150 records at 0.9 s is 135 s, under half the limit. Smaller batches cost little here: throughput is limited by the downstream calls, not by poll overhead, and the extra polls at 12 s intervals in normal times are negligible.
It also limits the damage when something does go wrong: a rebalance or a crash now reprocesses at most 150 records rather than 500.
4Why Not Just Raise max.poll.interval.ms?
Raising the interval to, say, 10 minutes also stops the removals, and it is sometimes the right call. But it has two costs. A consumer that is truly stuck, on a deadlock or a hung connection without a timeout, keeps its partitions for 10 minutes before anyone takes over. And a rebalance must wait for every member to poll; a member deep in a 9-minute batch holds up the whole group's rebalance for that long. So the interval should describe 'longer than any healthy batch', not 'long enough to hide the slowness'.
5Making the Processing Itself Robust
The deeper problem is that a slow downstream stalls the consumer one call at a time. Three changes make the batch time predictable. First, a per-call timeout, for example 2 s, so a hung call cannot take minutes. Second, a circuit breaker, for example with Resilience4j, which opens after a run of failures and fails calls immediately, so during an outage the batch fails in milliseconds instead of slowly timing out 150 times. Third, where ordering allows, process records concurrently, with a limit on in-flight calls so we do not flood the downstream.
Notice how much concurrency changes the arithmetic: with 20 calls in flight, even the slow period drops from 135 s to about 7 s. If records with the same key must stay in order, we group the batch by key and run each key's records in sequence while different keys run in parallel.
6Using Spring Kafka's Tools During an Outage
When the downstream is down rather than slow, the consumer should stop consuming rather than spin. In Spring Kafka, the DefaultErrorHandler retries a failed batch with a configured back-off, for example an exponential back-off from 1 s to 30 s; for a batch listener, throwing BatchListenerFailedException with the failed record's index tells it which records succeeded. For long outages, we can pause the container through KafkaListenerEndpointRegistry when the circuit breaker opens and resume it when the breaker half-opens. A paused container keeps polling, so it stays in the group without receiving records. Check your Spring Kafka version for options that pause the container during back-off instead of sleeping the consumer thread.
7Follow-up questions
How would I confirm the diagnosis from metrics?
The consumer's time-between-poll-max metric would show peaks above 300 s during slow periods, the logs would show the member leaving because the poll interval was exceeded, and the group's rebalance rate would line up with the downstream's latency graph. Matching those three timelines is usually convincing.
Does a smaller max.poll.records reduce throughput?
Only when per-poll overhead dominates, which happens with very cheap processing. Here each record costs 80 ms of downstream time, so poll overhead is irrelevant and the fetch buffer still holds data between polls, so no time is spent waiting on the network.
8Conclusion
In this answer, we did the arithmetic: 500 records at the p99 latency of 0.9 s take 450 s, beyond the 300 s poll interval, so slow periods push the consumer out and cause repeated rebalances and reprocessing. Lowering max.poll.records to about 150 keeps the worst case near 135 s, while raising the interval would hide stuck consumers and slow rebalances. Per-call timeouts, a circuit breaker and bounded concurrency make batch time predictable, and Spring Kafka's error handler back-off or pausing the container handle outages without letting polls time out.
Open with
I would start with the arithmetic. The worst-case batch time is records per poll times the slow-call latency. In a slow period most calls are near the p99, so 500 records times 0.9 seconds is 450 seconds, which is beyond the default max.poll.interval.ms of 300 seconds.
Then, if they want more
The consumer is removed from the group, the new owner reprocesses the batch, which adds load to the already slow downstream, and every removal pauses the group for a rebalance. So I would lower max.poll.records until the slow case fits with about a 2x margin: 150 records at 0.9 seconds is 135 seconds.
Throughput does not suffer because the cost is the downstream call, not the poll. I would not just raise max.poll.interval.ms, because that delays detecting a genuinely stuck consumer and makes rebalances wait for it.
Then I would fix the processing itself: a per-call timeout of a couple of seconds, a circuit breaker so an outage fails fast instead of stalling, and bounded concurrency where ordering allows; with 20 calls in parallel, even the slow batch takes seconds.
In Spring Kafka I would let the DefaultErrorHandler retry with back-off, throw BatchListenerFailedException with the failing index, and pause the container while the breaker is open, so polls keep happening and the group stays stable.
About this answer
- Last updated
- 13 November 2026
- 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 "How do you choose max.poll.records and max.poll.interval.ms, and what else would you...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/05ef20dd03/