Explain the impact of message compression in Kafka.

Instruction: Describe the benefits and potential trade-offs of using message compression in Kafka topics.

Context: This question is designed to explore the candidate's knowledge of Kafka's message compression feature, including its impact on performance, network usage, and storage.

Updated

Official answer

Kafka compression normally operates on record batches. Repeated structure within a batch can reduce bytes sent and stored, saving network and disk bandwidth. Results depend on payload entropy, batch composition and codec; already compressed or encrypted payloads may gain little.

The producer's compression.type selects a supported codec such as gzip, snappy, lz4 or zstd. Topic compression policy can retain the producer's codec or specify another one; conversion can add broker work. Consumers must support the format and spend CPU decompressing data before application processing.

Batch size and linger influence how much data can be compressed together. Compression does not by itself guarantee fewer requests or lower latency. Waiting for batches and compression work can increase latency, while relieving a network bottleneck can improve throughput. Large batches also affect memory and recovery behavior.

Benchmark representative records with the same acknowledgement, replication and offered-load settings. Compare compressed/uncompressed byte ratio, producer/broker/consumer CPU, request sizes, throughput, p95/p99 end-to-end latency and errors. Include sparse traffic and peak load. Keep an explicit latency budget and verify the compatibility of the chosen codec across clients and brokers. User-engagement counts do not isolate a compression improvement.

Producer compression and batching, topic compression policy

Related Questions