dkduckkit.dev

kafka linger.ms

Kafka

linger.ms is a Kafka producer configuration that controls how long the producer waits to accumulate messages into a batch before sending, even if batch.size has not been reached. The default is 0 — the producer sends immediately without waiting. Setting linger.ms to a positive value introduces a small deliberate delay that allows more messages to accumulate, improving batch efficiency, compression ratio, and throughput at the cost of added latency.

Why it matters in practice

linger.ms=0 is optimal for latency-sensitive, low-throughput producers but suboptimal for high-throughput producers using compression. A producer sending 1,000 messages/second with linger.ms=0 creates 1,000 single-message batches per second. The same producer with linger.ms=10ms creates ~10 batches of ~100 messages each — dramatically improving compression efficiency. For Kafka topics where throughput matters more than per-message latency (event streams, audit logs, analytics), linger.ms=5–20ms is a common default.

Common mistakes

  • Keeping linger.ms=0 when compression is enabled — the compression overhead exceeds savings for single-message batches.
  • Setting linger.ms very high (seconds) for interactive APIs — this adds noticeable producer-side latency for every message.
  • Not considering linger.ms interaction with acks=all — with acks=all, produce latency already includes replication RTT; adding linger.ms on top compounds the effect.