Monedula

Kafka producer config

batch.size: the producer batch limit

Producer config · default 16384 (bytes) · Apache Kafka 4.3

batch.size is the most bytes the Kafka producer puts in one batch for a single partition (default 16384, 16 KiB). A batch is sent when it is full or when linger.ms runs out, whichever comes first, so batch.size caps a batch rather than making the producer wait for one.

Config
batch.size (producer)
Default
16384 (bytes)
Valid values
0 or more; 0 turns batching off
Reference
Apache Kafka documentation for batch.size
batch.size reached · 3-record batch flushed at once. O3, O4, O5 arrived in a burst and hit batch.size=3 (three records here; real batch.size is 16384 bytes by default), so the batch flushed immediately - without waiting out linger.ms (LEO 5). Bigger batches → fewer requests → more throughput, at the cost of a little latency. Open this step in the full playground

What it does

Each partition the producer writes to has its own open batch, carved out of buffer.memory. Records are appended until the next one would not fit, and then the batch is ready to send. Ready batches for partitions led by the same broker travel together in one produce request. A single record larger than batch.size gets a batch of its own. With compression on, the producer counts the estimated compressed size against batch.size, so a compressed batch holds more records.

The trade-off

A larger batch.size means fewer requests and better compression, so more throughput and less broker load, but every partition in use can hold a batch of that size, so many partitions times a large batch.size can exhaust buffer.memory. A smaller one sends more, smaller requests. On its own a larger batch.size adds no latency: only linger.ms makes the producer wait.

Advice

See it in the simulator

Related configs

All Kafka configs