Monedula

Kafka producer config

linger.ms: how long the producer waits to fill a batch

Producer config · default 5 (milliseconds; 0 before Kafka 4.0) · Apache Kafka 4.3

linger.ms is how long the Kafka producer waits for more records before it sends a batch that is not full yet. A batch goes out when it reaches batch.size or when linger.ms runs out, whichever comes first. The default is 5 ms since Kafka 4.0 (it was 0 before).

Config
linger.ms (producer)
Default
5 (milliseconds; 0 before Kafka 4.0)
Valid values
0 or more
Reference
Apache Kafka documentation for linger.ms
linger.ms elapsed · 2-record batch flushed. No more records arrived, so at linger.ms the batch flushed: O1 and O2 append together (LEO 2) as a single request. Time-triggered flush. Open this step in the full playground

What it does

The producer collects records per partition into batches and sends each batch as part of a produce request. With linger.ms at 0 a batch is sent as soon as the sender thread is free, so batching happens only under load. A small delay lets more records join each batch, so the same data goes out in fewer, larger requests that also compress better.

The trade-off

A higher linger.ms adds up to that much latency to a record that arrives when traffic is light, in exchange for fewer requests, less broker CPU and better compression. Under heavy load batches fill to batch.size before linger.ms runs out, so the delay costs nothing there. A lower value cuts latency at light load and sends more, smaller requests.

Advice

See it in the simulator

Related configs

All Kafka configs