---
title: "Kafka buffer.memory and max.block.ms: producer backpressure"
description: "Slow acks fill a 2048-byte buffer.memory, so the third Kafka send blocks for max.block.ms, then fails with a TimeoutException instead of buffering forever."
url: https://monedula.dev/kafka-simulator/scenarios/backpressure-buffer-memory/
---

# Kafka buffer.memory and max.block.ms: producer backpressure

Scenario 01.2.4 · Backpressure: buffer.memory and max.block.ms. Producers & EOS · Intermediate · about 3 min · Apache Kafka 4.3.

buffer.memory caps the producer's un-acked send buffer: when slow acks fill it, the next send BLOCKS for up to max.block.ms - and if the buffer never drains, the send times out.

Run it: https://monedula.dev/kafka-simulator/playground/?scenario=01.2.4

## What you start with

buffer.memory is the producer's send-buffer budget for records waiting to be sent or still awaiting their ack; completed batches free space. p1 is capped at 2048 bytes (room for 2 un-acked records) writing acks=all behind two throttled followers, so the high watermark never advances and no ack ever returns. Two records fill the buffer, the third send blocks (backpressure) for max.block.ms, then times out when the buffer never drains.

## Step by step

1. **Cluster ready** (t+0.000s): p1 writes acks=all with buffer.memory = 2048 B (room for 2 un-acked records) and max.block.ms = 600. The buffer starts empty. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=01.2.4&t=0)
2. **Followers throttled** (t+0.300s): Both followers (broker-2, broker-3) are slow, so the high watermark will never advance - meaning acks=all can never commit and no ack will return to free the buffer. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=01.2.4&t=1)
3. **A1 buffered, not acked** (t+0.600s): A1 lands on the leader's log (offset 0) but the slow followers never fetch, so HW stays 0 and A1 is never acked. The un-acked buffer holds 1024 B; p1 sits in waiting. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=01.2.4&t=2)
4. **Buffer full (2 records)** (t+0.800s): A2 lands on the leader (offset 1), still un-acked. The buffer now holds 2048 B = exactly buffer.memory. The next send has no room. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=01.2.4&t=3)
5. **Send blocked (backpressure)** (t+1.200s): A3's send finds the buffer full (2048 >= 2048), so it BLOCKS - p1 goes to blocked, holding A3 while max.block.ms counts down (fires at 1600 ms). A3 is not appended; the log still holds only [0, 1]. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=01.2.4&t=4)
6. **Still blocked, no ack** (t+1.500s): Mid-block: no ack has arrived (the followers are still slow), so the buffer has not drained. The send is still blocked, the timer still counting down. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=01.2.4&t=5)
7. **Block timed out** (t+1.700s): max.block.ms elapsed with the buffer still full, so A3's send FAILS with a BufferExhaustedException (a TimeoutException; the simulator shows it as request_timed_out). p1 goes to error and the held record is dropped - backpressure surfaced the stall instead of buffering without limit. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=01.2.4&t=6)

## The takeaway

Backpressure is the producer protecting itself: when the broker can't keep up, a full buffer.memory makes the next send block for up to max.block.ms instead of buffering without limit - and past that window the stalled send fails with a TimeoutException rather than growing memory unbounded.

## Configs in this scenario

- [`buffer.memory`](https://kafka.apache.org/43/configuration/producer-configs/#producerconfigs_buffer.memory): The bytes the producer may hold for records waiting to be sent or still awaiting an acknowledgement (default 33554432, 32 MiB); when it is full, send() blocks for up to max.block.ms and then fails with BufferExhaustedException.
- [`max.block.ms`](https://kafka.apache.org/43/configuration/producer-configs/#producerconfigs_max.block.ms): How long send(), partitionsFor() and the transaction methods may block, waiting for metadata, for room in buffer.memory or for the transaction coordinator, before they throw a TimeoutException (default 60000, 1 minute).
- [`acks`](https://kafka.apache.org/43/configuration/producer-configs/#producerconfigs_acks): How many replicas must have a write before the producer counts it as sent: 0 (none), 1 (the leader only) or all (every in-sync replica, the default, and required for idempotence). [How acks works](https://monedula.dev/kafka-simulator/configs/acks/)

## Further reading

- [Apache Kafka documentation](https://kafka.apache.org/43/configuration/producer-configs/#producerconfigs_buffer.memory)

## Troubleshooting

- [TimeoutException in Kafka producers: causes and fixes](https://monedula.dev/kafka-simulator/troubleshooting/producer-timeout-exception/)
