Skip to content
Kafka Is Fun

Lesson 5 of 5

Batching & Compression

1 min read

Overview

Producers batch records before sending, which spreads the overhead of a network round trip over many records. linger.ms is an upper bound on how long to wait for more records: once batch.size worth of records for a partition is ready, it is sent immediately. batch.size is per partition. compression.type accepts none (the default), gzip, snappy, lz4 or zstd and is applied to whole batches. A batch stays compressed in the log and is sent to consumers compressed; consumers decompress it, and the broker decompresses a batch to validate it. Broker and topic compression.type default to producer, which keeps the producer's codec.

Key configuration

Producer settingsproperties
linger.ms=5 — the default since Kafka 4.0 (it was 0 before)
batch.size=16384 — default, 16 KiB per partition
compression.type=lz4 — one of none (default), gzip, snappy, lz4, zstd

Production tip

Check yourself

Where is a compressed batch decompressed?

Sources

Checked against Kafka 4.2 documentation on Oct 2026. Draft: not yet reviewed by a Kafka specialist. Releases move on, so confirm against the current documentation before you act on a number.

Browse all troubleshooting entries