Skip to main content
InterviewHubPRO
Section Overview
Q24

Question 24 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

48%
Apache Kafka Streaming (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

How do you optimize Kafka batching parameters (`batch.size`, `linger.ms`, `compression.type`)?

senior LevelSystem DesignApache KafkaMicroservices

In Simple Words: By default, producers send records almost immediately, resulting in thousands of tiny network packets. Tuning batching improves throughput by up to 10x with negligible latency addition:

  • linger.ms=20: Tells the producer to wait up to 20 milliseconds before sending, allowing incoming records to accumulate into a single batch.
  • batch.size=65536 (64KB): Max byte size of a partition batch.
  • compression.type=lz4 or zstd: Compresses batches at the producer before network transfer. Compressing entire batches achieves much higher compression ratios than compressing individual records, saving network bandwidth and broker disk space.