Kafka’s hidden latency trap: linger.ms is costing you time
Jack vanlightly broke down a quiet but expensive Kafka setting that most teams leave on default.
The setting: linger.ms. It controls how long the broker waits to batch messages before sending them to disk.
The default is zero. That means every single message gets written immediately. In a high-throughput system, that’s a lot of disk writes. And disk writes are expensive.
The fix is simple. Set linger.ms to something like 5 or 10 milliseconds. The broker now waits a few milliseconds, collects a small batch, and writes them together. One write instead of ten.
The result: throughput jumps. Latency per message drops. CPU usage on the broker goes down.
But it’s not free. You’re trading a tiny bit of tail latency for a big gain in throughput. If your system is already slow at the edges, this won’t help. But if you’re writing thousands of messages per second, this setting is probably the cheapest performance win you’ll find.
The blog post walks through the math. It shows how batching changes the I/O profile. It’s not rocket science. It’s just a setting most people ignore because it’s buried in the docs.
No magic. No new tool. Just a number you can change in your config and watch your broker stop choking.
Why this matters for us: Most of the apps our communities rely on — the ones running on shared servers, the ones that can’t afford a bigger instance — are probably running this default. A 10ms tweak costs nothing and buys you breathing room. We don’t need to wait for a bigger budget to run our systems smoother.