Quick revision
The short answer
A Kafka consumer asks for data only when it calls poll(), so a slow consumer simply falls behind and the backlog stays on the brokers as lag, unlike a push broker that keeps delivering. A Spring Kafka listener can slow itself deliberately by pausing its container or single partitions through the KafkaListenerEndpointRegistry, which keeps polling to stay in the group but returns no records, and max.poll.records bounds the work per loop. A consumer still runs out of memory when it hands records to an unbounded executor queue or fires unlimited async calls, so queues must be bounded and the container paused when they fill, and retention must cover the longest expected backlog.
What to remember
In this answer, we saw that Kafka's pull model gives natural backpressure: a consumer only gets records when it polls, so a slow consumer falls behind and the backlog stays on the brokers as lag. A Spring Kafka listener can slow itself by pausing its container or single partitions through the KafkaListenerEndpointRegistry while still polling, and max.poll.records bounds the work per loop. Memory still runs out when records go into unbounded executor queues or unlimited async calls, so we bound in-flight work and pause when full, and we size retention to cover the longest backlog.
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.
A Kafka consumer asks for data only when it calls poll(), so a slow consumer simply falls behind and the backlog stays on the brokers as lag, unlike a push broker that keeps delivering. A Spring Kafka listener can slow itself deliberately by pausing its container or single partitions through the KafkaListenerEndpointRegistry, which keeps polling to stay in the group but returns no records, and max.poll.records bounds the work per loop. A consumer still runs out of memory when it hands records to an unbounded executor queue or fires unlimited async calls, so queues must be bounded and the container paused when they fill, and retention must cover the longest expected backlog.
Why this question is asked
Backpressure is how a system tells a fast producer to slow down when a consumer cannot keep up. Without it, the excess piles up somewhere, usually in memory, until something crashes. Kafka's design gives us a strong form of backpressure for free, and interviewers ask about it to see whether we understand why, how to use it deliberately in Spring, and where we can accidentally defeat it. In this answer, we will compare pull and push, see where the backlog goes, slow a listener down on purpose, find the memory traps, and connect lag to retention.
1Pull Against Push
In a push broker, the broker sends messages to the consumer as they arrive, up to some prefetch limit. If the consumer is slow, the broker must decide what to do with the rest: keep them in its own memory, slow the producers, or keep sending until the consumer's buffer overflows. Backpressure has to be negotiated through credits or prefetch counts.
A Kafka consumer pulls. It calls poll(), the client fetches a batch from the brokers, and nothing more is fetched for the application until it calls poll() again (the client prefetches a bounded amount in the background, controlled by fetch sizes). If processing a batch takes ten seconds, the next poll happens ten seconds later. The consumer is never sent more than it asks for.
| Push broker | Kafka (pull) | |
|---|---|---|
| Who decides the pace | Broker sends as messages arrive | Consumer, by calling poll() |
| Slow consumer | Buffers fill, broker or client strain | Consumer falls behind |
| Where the backlog lives | Broker memory or consumer buffers | On broker disks, as lag |
| Limit | Prefetch and credits | Retention of the topic |
2Lag Is the Buffer
When a Kafka consumer is slow, the records it has not read yet stay in the partition on the brokers' disks. The distance between the end of the partition and the consumer's committed position is called lag. Lag is the backlog, but it is stored in the cheapest, most durable place available: replicated log segments that were written anyway. The producer is not slowed down, the consumer is not overwhelmed, and when the consumer speeds up again it works through the lag at its own pace.
This is why Kafka is good at absorbing spikes. A consumer that handles 1,000 records per second can survive a 10-minute burst of 5,000 per second; it builds 2.4 million records of lag and then drains it after the burst.
3Slowing a Listener Down on Purpose
Sometimes we want to slow down on purpose, for example when a downstream database is struggling. Spring Kafka lets us pause a listener container, or individual partitions, through the KafkaListenerEndpointRegistry. While paused, the container keeps calling poll() so the consumer stays alive in the group and does not trigger a rebalance, but the paused partitions return no records. When we resume, consumption continues from the same position.
The pause takes effect between polls, so the records already returned by the current poll are still processed. Separately, max.poll.records limits how many records one poll hands to the listener, 500 by default, which bounds the work per loop and makes the loop's duration predictable. It must stay small enough that a batch is processed well within max.poll.interval.ms, five minutes by default, or the consumer is removed from the group.
4Where a Consumer Still Runs Out of Memory
The pull model protects us only if processing stays inside the poll loop. A common pattern breaks this: the listener hands each record to an executor for parallel processing and returns immediately. The poll loop now runs as fast as Kafka can deliver, and every record goes into the executor's queue. Executors.newFixedThreadPool uses an unbounded LinkedBlockingQueue, so if the workers are slower than the loop, the queue grows until the heap is full. The backlog has moved from the brokers' disks into our JVM.
The same happens when the listener fires async HTTP calls or reactive pipelines without a limit on how many are in flight. The fix is to bound the work and push back into Kafka: use a bounded queue or a semaphore of permits, so the listener waits briefly when every slot is taken, and pause the container (or the partition) when the slots stay nearly full, so a slow downstream never holds the poll loop past max.poll.interval.ms. Offsets also need care, since records finishing out of order must not commit an offset past an unfinished record.
- poll() returns a batch
- Permit available?YesSubmit to worker poolNoWait briefly for a permit
- Worker finishes, releases permit
- Fewer than 50 permits free?YesPause the containerNoResume or keep consuming
4 steps in order. Play them, or step through them one at a time.
Notice what changed: when work piles up, the listener stops taking records, and the backlog returns to Kafka as lag, where it belongs.
5Retention Must Cover the Backlog
Lag is a buffer only while the records still exist. Kafka deletes old segments by retention, for example 7 days by default, regardless of whether a consumer has read them. If a consumer is down or paused for longer than retention, or falls so far behind that its position is older than the oldest segment, those records are deleted unread. The consumer then jumps to the earliest or latest offset depending on auto.offset.reset and silently skips data.
So retention must be sized for the longest backlog we expect, such as a weekend outage plus catch-up time, and we should alert when a group's lag, measured in time rather than records, approaches a fraction of retention.
6Follow-up questions
Does pausing a container cause a rebalance?
No. A paused container keeps calling poll(), which keeps the consumer in the group and satisfies max.poll.interval.ms. That is the difference from simply stopping the container, which leaves the group and triggers a rebalance.
Why does max.poll.records matter for backpressure?
It bounds how much one poll gives the application. With a smaller value, each loop finishes sooner, pause and resume react faster, and the risk of exceeding max.poll.interval.ms is lower.
Can the consumer's own fetch buffer use too much memory?
It is bounded by fetch.max.bytes and max.partition.fetch.bytes per fetch, so it is predictable, but with many partitions and large values it can still be hundreds of megabytes. Size those settings with the heap in mind.
7Conclusion
In this answer, we saw that Kafka's pull model gives natural backpressure: a consumer only gets records when it polls, so a slow consumer falls behind and the backlog stays on the brokers as lag. A Spring Kafka listener can slow itself by pausing its container or single partitions through the KafkaListenerEndpointRegistry while still polling, and max.poll.records bounds the work per loop. Memory still runs out when records go into unbounded executor queues or unlimited async calls, so we bound in-flight work and pause when full, and we size retention to cover the longest backlog.
Open with
Kafka consumers pull, so a consumer only gets more records when it calls poll. If processing is slow, the next poll just happens later, and the records it has not read stay on the brokers as lag.
Then, if they want more
That is natural backpressure: the backlog sits on replicated disks instead of piling up in the consumer, unlike a push broker that keeps delivering until buffers fill. In Spring Kafka I can slow a listener deliberately by getting its container from the KafkaListenerEndpointRegistry and calling pause, or pausePartition for a single partition.
While paused, the container keeps polling, so it stays in the group without a rebalance, but it receives no records; resume continues from the same offset. max.poll.records, 500 by default, limits how many records each poll hands over, which bounds the work per loop.
Where it goes wrong is when the listener hands records to an executor with an unbounded queue, or fires async calls with no limit. Then the poll loop races ahead and the in-process queue absorbs everything until the heap runs out.
The fix is a bounded queue or a semaphore, and pausing the container when it fills, so the backlog goes back to Kafka. And lag is only a buffer while the data exists, so retention must cover the longest backlog we expect.
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 "Explain why this gives natural backpressure, how a Spring Kafka listener can slow itself...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-design/2f8baee088/