Kafka Producer Configuration
The most impactful producer configurations for reliability, throughput, and exactly-once delivery. Getting these right is the difference between a production-grade Kafka producer and one that silently loses data.
| Config | Default | Category | |
|---|---|---|---|
| acks acks controls how many broker acknowledgements the producer waits for before considering a write successful. | all | reliability | |
| enable.idempotence enable. | true (since Kafka 3.0) | reliability | |
| batch.size batch. | 16384 (16 KB) | performance | |
| linger.ms linger. | 0 | performance | |
| compression.type compression. | none | compression | |
| delivery.timeout.ms delivery. | 120000 (2 minutes) | delivery |
Reliability
acks controls how many broker acknowledgements the producer waits for before considering a write successful. acks=0: fire-and-forget (no ack, possible data loss). acks=1: leader acknowledges (data loss if leader fails before replication). acks=all/-1: all in-sync replicas acknowledge (no data loss as long as min.insync.replicas is met). acks=all is the default since Kafka 3.0.
Maximum durability (payments, orders): acks=all with min.insync.replicas=2
enable.idempotence=true gives each producer a unique PID (Producer ID) and adds a sequence number to every record. The broker deduplicates retried records by tracking the last sequence number per (PID, partition). This prevents duplicate records from network retries. Idempotence is required for exactly-once delivery and is enabled by default since Kafka 3.0.
All production workloads: enable.idempotence=true (default since 3.0)
Performance
batch.size controls the maximum number of bytes in a single batch of records sent to a partition. The producer batches records destined for the same partition. When the batch fills up, it is sent immediately. A larger batch.size reduces per-request overhead and improves throughput at the cost of higher latency. Combine with linger.ms to control when incomplete batches are sent.
High throughput pipeline: batch.size=131072 with linger.ms=20
linger.ms tells the producer to wait up to N milliseconds for more records before sending an incomplete batch. Default 0 sends batches immediately (lowest latency, lower throughput). Increasing linger.ms allows the producer to accumulate more records into fewer, larger batches – improving throughput and compression ratio at the cost of added latency.
Real-time, low latency required: linger.ms=0 (default)