liveBook · Manning

Linger.ms

As explained in Apache Kafka in Action

linger.ms is a Kafka producer setting that specifies how long a producer waits for additional records before sending a batch.

linger.ms is a Kafka producer setting that controls how long the producer waits for additional records before sending a batch. A batch is sent when it becomes full or when the linger time expires. The default is 0 milliseconds, so the producer sends as quickly as possible, although natural batching can still occur when records arrive close together. section 6.2.1 section 8.1.3

Increasing batching for higher-throughput producers

For a producer sending more than 100 messages per second, setting linger.ms to approximately 10 milliseconds can improve throughput and latency by allowing more records to join each batch. For example, configure linger.ms=10 alongside an appropriately sized batch.size. The trade-off is that batching can add waiting time, so immediate delivery may favor the default of 0. section 6.2.1 section 6.5

Tune linger.ms together with the producer's batching and delivery settings:

  • Use batch.size to set the maximum batch size in bytes; use linger.ms to set the waiting period in milliseconds. section 6.2.1
  • Expect the producer to send as soon as either the batch is full or the linger interval ends. section 6.2.1
  • Treat linger.ms as distinct from request.timeout.ms and delivery.timeout.ms: it delays batch formation, while the other settings govern broker responses and eventual failure. section 8.1.3
Figure 6.5 The producer batches messages for each topic and partition. A message is sent as soon as either the batch is full or the linger time is up.
A group of colorful squares

AI-generated content may be incorrect.

Shows the producer's per-topic, per-partition batching flow and the two conditions that trigger a send. section 6.2.1

How Apache Kafka in Action covers it

How deep it goes
Explains defaults, units, batch-trigger conditions, tuning guidance, and timeout relationships without detailing producer internals.
Examples
Uses the 0-millisecond default, an approximately 10-millisecond recommendation, and full-batch versus timer-based sending.
What you can do after
Apply it via Kafka producer configuration while balancing batching efficiency against delivery latency.
How it connects
Connects batching with batch.size, throughput, latency, request.timeout.ms, and delivery.timeout.ms.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.