liveBook · Manning

Compression

As explained in Kafka for Architects

Data compression is the transformation of data into a more compact representation to reduce storage or transmission size.

Compression transforms Kafka messages into smaller representations, reducing network throughput and retained storage. The preferred architecture compresses complete producer batches before transmission; Kafka stores and forwards the compressed data, while consumers decompress it automatically. section 4.4

Kafka supports two placement strategies with different operational consequences:

  • Producer-level compression uses gzip, snappy, lz4, or zstd. Setting compression.type to none disables compression. section 4.4
  • Batch compression improves ratios because messages in a batch often share similar structure. section 4.4
  • Broker-level compression can retain the producer codec or recompress with another codec; changing codecs forces decompression and recompression, adding work. section 4.4
  • Compression choices affect CPU usage, message limits, batching, buffer sizing, throughput, storage, and cloud cost, especially for repetitive JSON or Avro payloads. section 10.1.4

A producer-side compression path

A producer groups similar events into a batch, compresses the batch with zstd, and sends it to Kafka. The broker retains the compressed form and forwards it to consumers, which decompress it without special consumer configuration. Keeping the producer codec avoids broker-side recompression. section 4.4

Figure 4.22 Compressing the data on producer side
A screenshot of a computer

Description automatically generated

Trace the producer-side flow from batching and compression through broker storage and consumer delivery. section 4.4

How Kafka for Architects covers it

How deep it goes
Explains producer and broker placement, batch behavior, codecs, consumer decompression, and recompression overhead.
Examples
Uses gzip, snappy, lz4, zstd, uncompressed data, producer batches, and repetitive JSON or Avro payloads.
What it assumes
Assumes familiarity with Kafka producers, brokers, consumers, message batches, and configuration properties.
What you can do after
Operate/configure Kafka compression by selecting codecs, placement, batching, and limits against throughput, CPU, and storage requirements.
How it connects
Connects compression with Kafka producers, brokers, consumers, batching, message size, throughput, storage, CPU, and cloud cost.

Also explained in

Compare how 11 books explain compression →

Related concepts

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