Skip to content

Performance & Tuning

Tuning Kafka is mostly about choosing where you sit on the throughput-versus-latency curve — bigger producer batches, compression, more partitions, and stronger acks each push one way or the other, so you tune toward your workload rather than chasing a single “fast” setting.

Producer levers: batching, compression, acks

Section titled “Producer levers: batching, compression, acks”

The producer is where most throughput is won or lost. Three settings dominate:

  • Batchinglinger.ms and batch.size let the producer wait a few milliseconds and pack many records into one request. Larger batches mean far higher throughput at the cost of a little latency per record.
  • Compressioncompression.type (lz4, zstd, snappy, gzip) shrinks each batch, cutting network and disk usage. It trades CPU for throughput and is almost always worth it under load.
  • acksacks=all waits for the ISR to persist the record (durable, higher latency); acks=1 waits for only the leader (faster, weaker guarantee). This is the classic durability-versus-latency dial.
# Throughput-leaning producer: wait a little, batch bigger, compress, stay durable
linger.ms=10
batch.size=65536
compression.type=lz4
acks=all
flowchart LR
  batch["Bigger batches + linger.ms"] --> tp["Higher throughput"]
  comp["Compression (lz4 / zstd)"] --> tp
  acksall["acks=all"] --> dur["Stronger durability"]
  acksall --> lat["Higher latency"]
  small["Small batches + acks=1"] --> low["Lower latency"]
The throughput versus latency trade-off

Partitions are your parallelism unit: a partition is consumed by at most one consumer in a group, so the partition count is the ceiling on consumer parallelism. Size it from a target:

partitions ≈ target throughput ÷ per-consumer (or per-partition) throughput

If one consumer instance handles 10 MB/s and you need 100 MB/s, you need at least 10 partitions to let 10 consumers run in parallel. Round up and leave headroom for growth and for uneven key distribution.

Brokers are deliberately simple, and their speed comes from the operating system:

  • Page cache — Kafka does not maintain its own big in-process cache. It writes to the OS page cache and relies on the kernel to serve recent reads from memory. Leave plenty of free RAM for the page cache; do not give the JVM a huge heap that starves it.
  • Disk — sequential writes make spinning disks and especially SSDs efficient. Use fast local disks, and spread load with multiple log directories if needed. Disk throughput and fsync behavior bound your durability and speed.
  • Network — replication and consumer fan-out are network-bound. A replication-factor of 3 means every produced byte is written roughly three times across the network, so provision NICs accordingly.
What do larger producer batches (via linger.ms and batch.size) mainly trade?
Why does partition count cap consumer parallelism?
What is the risk of creating far more partitions than you need?
How does Kafka rely on the operating system for read speed?