The broker stores the compressed batch as-is, so consumers pay the decompression cost, not the broker.
props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "zstd"); // or lz4, snappy, gzip
JSON payloads typically compress 5-10x.
lz4: fastest, moderate ratio
zstd: best ratio, slightly more CPU - usually the right default now
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11