Integration / Apache Kafka Interview questions
How can you optimize Kafka producer throughput?
Producer throughput tuning is mostly about maximizing effective batching and network efficiency without pushing latency higher than the use case can tolerate.
- Increase batch.size and linger.ms — larger, less frequent batches mean fewer, more efficient network round trips, at the cost of slightly higher per-record latency.
- Enable compression (
compression.type=lz4orzstd) — smaller batches over the wire mean less network time, often a large win with only modest CPU cost. - Increase buffer.memory if producer threads are blocking because the accumulator buffer fills up faster than batches can be sent.
- Tune acks appropriately for the use case — acks=1 is meaningfully faster than acks=all, and is an acceptable trade-off when occasional data loss on a broker crash is tolerable.
- Use multiple producer instances or partitions if a single producer's I/O thread is the bottleneck rather than the broker.
The general trade-off running through all of these: throughput optimizations generally cost either latency (larger batches) or durability (weaker acks), so the "optimal" setting depends entirely on which of those the specific application can actually afford to give up.
More Related questions...