How Kafka Handles Backpressure: Durable Log, Pull Consumers, Blocking Producers
What producer.send() Actually Does#
send() is asynchronous in a specific and limited sense: it hands a record to an in-memory buffer and returns. When that buffer has no room, it does not return. A payments service writes card authorizations to a six-partition orders topic, and the call site looks like every producer example ever published: build the record, call send(), attach a callback, return the HTTP response. During a Friday afternoon spike, a thread dump caught that call doing something the team's own design doc says it never does.
Sixty seconds parked inside a method that returns a Future. The suspect everyone reaches for first is the settlement consumer group, which reads orders, calls a slow downstream settlement API, and has been accumulating lag all morning. A slow reader stalling a writer is what backpressure means in almost every other system a developer has worked with, so the story writes itself.
It is also wrong, and the reason it is wrong is the interesting part. Kafka has no credit protocol. A consumer never tells a broker to slow down its upstream, and a broker never relays consumer progress back to a producer. The two ends of the pipeline are not connected by any mechanism that could transmit a stall. So if Kafka has no flow-control protocol, what held that thread for a minute?
Start with why send() is fast at all. It never touches a broker. The record goes into an in-memory RecordAccumulator, where records are grouped into per-partition batches and drained by a separate Sender thread that owns all the network I/O1. The returned Future is a promise about work that background thread has not done yet. Asynchrony here is a property of a handoff to a buffer, not a guarantee about latency, and a handoff to a buffer stops being free the moment the buffer fills.
That is one edge. There are three places in the whole system where a rate mismatch turns into an actual stall: the producer's bounded accumulator, the broker's quota enforcement, and the consumer's pull loop. Everywhere else, Kafka converts the mismatch into stored bytes, which is exactly what a system built for high-volume feeds and large data backlogs was designed to do2. The payments producer, the orders topic, and the settlement group come back at each edge, starting with what the log does while nobody is being throttled at all.
No Credit Protocol: Why the Log Absorbs the Mismatch#
There is no credit-based flow control in the Kafka protocol. No window size, no demand signal travelling upstream, nothing that corresponds to request(n) in reactive streams. Engineers arriving from Reactor or Akka Streams tend to search the configuration reference for it, find several settings that look close, and conclude the documentation is hiding something. The setting does not exist because the design does not need it: Kafka is closer to a database log than to a traditional messaging system2.
Two properties follow from that, and together they explain why a producer and a consumer running at different speeds never have to negotiate. First, a record is not destroyed by being read. Kafka stores messages after they are consumed rather than removing them on delivery, so a slow consumer holds nothing back from anyone3. Second, the client drives every interaction: it opens the socket, writes request messages, and reads the corresponding responses4. Every API in the protocol is a request/response pair4. A broker never pushes a batch at a consumer that did not ask for one, which means a consumer cannot be overrun by definition. It can only fall behind.
| Property | Classic message broker | Kafka partition log |
|---|---|---|
| Contended resource | Broker memory (queue depth) | Broker disk (log segments) |
| What delivery does to the record | Consumes it | Leaves it in place at its offset |
| Who initiates transfer | Broker pushes | Client fetches |
| What a rate mismatch produces | Producer stalls or messages drop | Lag grows |
Put numbers on the orders topic from the opening. Six partitions, six settlement instances, and each record costs about 700ms of settlement work, so one instance clears roughly 1.4 records per second and the group clears about 8.6 per second. Producers are appending 200 records per second at an average of 1 KB. The group absorbs 8.6 of those; the remaining 191 land on disk and stay there. Over an hour that gap is around 690,000 records, or roughly 670 MB of partition log per broker set, sitting at offsets nobody has read yet. Nothing errors and nothing slows down. The mismatch has been converted into stored bytes.
That conversion holds only while the bytes are still on disk. Kafka deletes old segments once a topic's retention limit is reached, and consumers have to read messages before they are purged5. Lag that outruns retention stops being a delay and becomes missing settlements. Where that boundary sits for a given topic is a function of the retention setting and the rate the gap is growing, and both are knowable numbers.
Diagram as text
flowchart LR
PROD["Producer writes record"]
LOG[("Partition log on disk")]
CONS["Consumer"]
LAG["Offset gap grows in bytes"]
RET{"Still within retention?"}
LOST["Records deleted, never read"]
PROD --> LOG
CONS -->|"sends fetch request"| LOG
LOG -->|"returns only requested records"| CONS
LOG --> LAG
LAG --> RET
RET -->|"yes: log absorbs mismatch"| CONS
RET -->|"no: segment aged out"| LOSTThrottle Point One: The Producer's Bounded RecordAccumulator#
Here is the payments service producer, configured with nothing beyond the required properties and pushed hard:
The accumulator is bounded, and that bound is the whole mechanism behind the send() that stopped returning immediately. buffer.memory sets the total bytes the producer may use to hold records waiting to go to the server, 32 MiB by default, and when records are produced faster than they can be delivered the producer blocks for max.block.ms before failing with an exception6. For send(), that timeout covers both the metadata fetch and the buffer allocation, and it defaults to one minute6.
So the loop above does not fail when the brokers fall behind. It slows to the rate the brokers can absorb, one blocked allocation at a time, which is as close as Kafka gets to telling a producer to ease off. The cost lands on whichever thread called send(): an HTTP worker handling a checkout request now holds its connection open for as long as the allocation waits, and the symptom surfaces as request latency in the payments API rather than as anything obviously Kafka-shaped.
Batching determines how quickly that buffer drains. The producer groups records destined for the same partition into a single request, which helps performance on both the client and the server, with batch.size capping each batch at 16 KiB by default6. Larger batches mean fewer, bigger writes and higher throughput, up to the point where the network or the brokers become the limit1. You pay for that in latency. Since Kafka 4.0, linger.ms defaults to 5, so a partly filled batch waits 5ms for company before it ships; raising it to 50 cuts request count and adds up to 50ms to records sent when there is no load to fill batches quickly6. Under real pressure the effective linger runs higher than the setting anyway, because broker backpressure holds batches longer than the timer would6.
Notice what a blocked producer actually tells you: the brokers or the network cannot keep up with the write rate. If the consumers are the bottleneck instead, this buffer drains normally and never fills, the producer never blocks, and the pressure accumulates somewhere the producer cannot see at all.
Diagram as text
sequenceDiagram
participant App as "Application Thread"
participant Acc as "RecordAccumulator"
participant Sender as "Sender Thread"
participant Broker
App->>Acc: send(record)
Acc->>Acc: try allocate from buffer.memory
alt space available
Acc->>Acc: append to per-partition batch
Acc-->>App: return Future immediately
else buffer.memory exhausted
Acc-->>App: block inside send(), wait up to max.block.ms
alt Sender frees space in time
Acc->>Acc: append to per-partition batch
Acc-->>App: return Future (after delay)
else max.block.ms elapsed
Acc-->>App: throw TimeoutException
end
end
loop drain cycle
Sender->>Acc: drain ready batches
Sender->>Broker: produce request
Broker-->>Sender: ack
Sender->>Acc: deallocate buffer memory
endThrottle Point Two: Broker Quotas Insert a Deliberate Delay#
The payments producer holds at 18 MB/s. Not a sawtooth, not a spike that recovers: a flat line that survived a doubling of application threads and a larger batch.size, both of which should have moved it. Nothing in the client configuration names 18 MB/s. buffer.memory is 64 MB, and the buffer is only briefly full. Meanwhile the producer's throttle-time metric, which sat at zero all through the batching work above, is now reporting tens of milliseconds on average.
That number is the tell, because it is reported by the client but decided somewhere else. A Kafka cluster can enforce quotas on requests to control the broker resources used by clients, applied per group of clients sharing a quota7. Two kinds exist: network bandwidth quotas defining byte-rate thresholds, and request rate quotas defining CPU utilization as a percentage of the broker's network and I/O threads7. Neither appears in any property the producer sets. A client can be perfectly configured and still meet a ceiling it cannot see from its own config file.
The reason for the ceiling is straightforward once you think about the cluster rather than the application. Producers and consumers can move enormous volumes and generate requests fast enough to monopolize broker resources, saturate the network, and cause denial-of-service for other clients and for the brokers themselves7. On a multi-tenant cluster, payments running unbounded is someone else's outage.
What makes the quota a backpressure mechanism rather than an error is how it is applied. The broker's lever is delay: instead of rejecting the produce request, it holds the response before returning it, so the client observes latency rather than failure. That delay propagates backward into the accumulator. Responses arriving later means in-flight requests stay in flight longer, batches for those partitions stay resident in the RecordAccumulator, and free space in buffer.memory recovers more slowly than the application is consuming it. Eventually send() blocks, exactly as it would under a purely local buffer shortage.
Which is why the two cases need separating before you tune anything. A non-zero average produce throttle time alongside buffer exhaustion means the broker set your rate and the buffer is only relaying that decision; raising buffer.memory buys a longer runway, not more bandwidth. Buffer exhaustion with throttle time flat at zero is a client-side problem, and the batching and sizing levers above still apply.
Throttle Point Three: The Pull Loop the Consumer Owns#
Why did the settlement consumer get kicked out of the group when nothing crashed? No exception, no OOM, no broker outage in the logs. One instance simply stopped being a member, its partitions moved elsewhere, and the offsets it had been working through were replayed by whoever picked them up.
That failure mode follows from an absence. A producer that outruns its buffer stalls inside send(); the consumer loop has nothing equivalent to stall on, because it holds its own position in each partition and advances that position itself, so a consumer sitting at offset 5 has read 0 through 4 and will next be handed 58. It also never receives more than it requested. Fall behind and the records do not pile up in your process; they stay on the broker's disk. What breaks instead is membership. The client is built to load-balance consumption across a group and to adapt as partitions move between members8, and a member that goes quiet for long enough is treated as one of those movements.
One turn of the loop makes the timing visible. The client issues a fetch, the broker returns a response bounded in bytes, the client buffers what came back, poll() hands your application a slice of it, your code processes that slice, and offsets are committed before the next poll(). Every one of those steps happens between two poll() calls, and the interval between them is what the group coordinator watches. Take 400 records and spend 900ms each on an external settlement API, and the wall clock passes the interval budget long before the batch is done.
Four knobs bound different parts of that turn. Defaults have shifted across client releases, so confirm them against the version you actually run.
fetch.max.bytes: how much data a single fetch response may return.max.poll.records: how many records onepoll()call hands to your code.max.poll.interval.ms: the wall-clock budget between consecutivepoll()calls, five minutes by default in recent clients.pause()/resume(): stops and restarts fetching for specific partitions without leaving the group.
Shrinking max.poll.records is the blunt fix, and it works when processing cost per record is roughly uniform. When it is not, pausing is the honest valve: keep calling poll() on schedule so the group stays healthy, but pause the partitions whose backlog you cannot drain yet.
The loop keeps its heartbeat while the work queue drains, and the unread records keep accumulating on the broker where they started.
Diagram as text
flowchart TB
P["poll()"]
F["Fetch capped by fetch.max.bytes"]
D["At most max.poll.records"]
A["Process batch"]
CM["Commit worker progress"]
C{"Next poll within max.poll.interval.ms?"}
subgraph failure["Failure path"]
FAIL["Member considered gone"]
RB["Partitions reassigned"]
end
subgraph remedy["Remedy path"]
PA["pause() assigned partitions"]
RE["resume() when drained"]
end
P --> F
F --> D
D --> A
A --> CM
CM --> C
C -->|"yes"| P
C -->|"no"| FAIL
FAIL --> RB
A -->|"worker falls behind"| PA
PA --> CM
PA -->|"empty polls keep member alive"| P
PA -->|"backlog drains"| RE
RE --> PReading the Signal: Consumer Lag Against Retention#
| What you observe | Which edge is engaged | The knob that actually moves it |
|---|---|---|
send() blocks, then throws TimeoutException after max.block.ms | Producer's RecordAccumulator is full | buffer.memory, batching via linger.ms, or fewer partitions per producer instance |
produce-throttle-time-avg or fetch-throttle-time-avg sits above zero | Broker-enforced client quota | The quota entry for that client or user, or the client's own request rate |
poll() returns normally but the group rebalances again and again | The consumer's pull loop, processing slower than max.poll.interval.ms | max.poll.records, fetch.max.bytes, pause()/resume() around slow work |
None of those three numbers is the one you should page on. They tell you which edge is currently absorbing the mismatch, not whether you are in trouble. Trouble has a different number.
If the log absorbs producer and consumer rate mismatch, what stops the absorption from being free? Absorption is bounded by durability, not by memory. Kafka stores records in a fault-tolerant, durable way rather than discarding them once a consumer has read them9, so a slow consumer costs disk rather than dropped writes. Disk is patient. Retention is not. Segments older than retention.ms are deleted on the cleanup cycle, the deletion is irreversible, and consumers must read messages before they are purged5. With the default log.retention.hours=168 you have seven days of runway5, and no more.
Lag is the signal Kafka does expose, because the consumer's position is its own property: position 5 means offsets 0 through 4 are consumed and offset 5 comes next8. Subtract that position from the partition's log end offset and you have an exact, per-partition measure of how far behind the settlement group is running. Nothing in the protocol pushes that number back at the producer. Everything in your capacity planning should read it.
So go get it for the group from the earlier sections:
Take the LAG column, take the rate it grew over the last hour, and answer two questions in that order. First: at the current growth rate, how many hours until the oldest unread offset reaches the retention window? Alert well before you arrive, and treat lag in hours crossing roughly 80 percent of the retention window as the trigger5. Second: which of the three edges do you move first? If throttle time is non-zero, the quota is the ceiling and no client tuning gets past it. If send() is blocking, the producer is already applying the only backpressure it has. If neither is true, the deficit is downstream, and max.poll.records against your processing time per record is the arithmetic to do next.
Sources
- Kafka Producer Batchingaxonops.com
- Designkafka.apache.org
- What Is Apache Kafka? | IBMibm.com
- Protocol | Apache Kafkakafka.apache.org
- Apache Kafka® Retention Explained: Policies & Best ...confluent.io
- Producer Configs | Apache Kafkakafka.apache.org
- Kafka Quotas | Confluent Documentationdocs.confluent.io
- KafkaConsumer (kafka 0.10.1.1 API)kafka.apache.org
- Introduction | Apache Kafkakafka.apache.org
Keep reading
How Kafka Rebalances a Consumer Group, Step by Step
The orders topic has six partitions. Consumer A owns 0 through 2, consumer B owns 3 through 5, and both are keeping pace with the write rate. Ahead of a traffic spike you start a...
Debugging Kafka in Production: Four Failure Modes and Their Parameters
The orders-events topic has 12 partitions, consumed by six instances of a payments-enrichment service. Roughly every five minutes, the group logs a rebalance, all 12 partitions...
Five Kafka Design Patterns Every Backend Engineer Should Know
Kafka is a distributed commit log. Producers append records to topics; consumers read those records independently, each maintaining their own offset into the log. Unlike a...