Kafka Producer Latency Configuration
Evaluate batching and failure-response budgets without disabling idempotence or replica acknowledgements.
producer
| Config / reference | Default → proposal | Rationale and conditions |
|---|---|---|
| Batching and compression | ||
| linger.ms Java client 4.4 Evaluate | 5 ms → 0 | Sets the intentional batching wait. Full batches can be sent earlier; zero removes this wait but does not prevent batching. Tradeoff: A larger value can delay partially filled batches. Queueing and broker backpressure can add other delays. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: A latency budget smaller than the proposed batching wait. Measure: record-queue-time-avg, batch-size-avg, end-to-end p95/p99 latency In Java, delivery.timeout.ms must be >= linger.ms + request.timeout.ms. librdkafka timeout names and validation rules are different. max.block.ms bounds synchronous waiting for metadata/buffer allocation; linger.ms concerns batching after enqueueing. There is no general requirement that max.block.ms exceed linger.ms. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| batch.size Java client 4.4 Keep | 16 KiB (unchanged) | Sets the allocation target for a batch for one partition; fuller batches can amortize request overhead. Tradeoff: Larger batches can consume more buffer memory without filling at low traffic. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: Low per-partition traffic or a tight memory budget. Measure: batch-size-avg, records-per-request-avg, buffer-available-bytes The producer buffer is shared across partitions. Exhaustion can block send() until max.block.ms; handle synchronous exceptions as well as asynchronous send failures. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| compression.type Java client 4.4 Keep | none (unchanged) | Selects the batch compression codec. Evaluate the candidate with the actual payload and record rate. Tradeoff: Compression trades CPU for network and storage bytes. No codec or compression ratio is best for every workload. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: Already-compressed payloads or a CPU-bound producer without a measured benefit. Measure: compression-rate-avg, CPU, bytes sent and p95/p99 latency A codec-specific compression level only applies to the selected codec. Benchmark CPU, bytes and latency; no fixed gain is implied. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| Delivery and transactions | ||
| acks Java client 4.4 Keep | all (unchanged) | With acks=all, successful writes require the relevant in-sync replica acknowledgements and the configured minimum ISR. Tradeoff: Durability depends on replication, ISR and failure conditions. acks=1 can lose acknowledged writes after leader failure and conflicts with explicitly enabled idempotence. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: Using acks=all as a substitute for reviewing topic replication and min.insync.replicas. Measure: UnderMinIsrPartitionCount, produce errors, replication state and acknowledgement latency Java idempotence requires acks=all, retries>0 and max.in.flight.requests.per.connection<=5. Explicit conflicting settings are rejected. acks=all must be reviewed with actual topic replication, ISR and failure scenarios. A single-replica ISR can satisfy a minimum ISR of one. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| enable.idempotence Java client 4.4 Keep | true (unchanged) | Deduplicates retried producer batches within the producer protocol and preserves ordering with compatible settings. It is not end-to-end exactly-once processing. Tradeoff: Requires acks=all, retries greater than zero and at most five in-flight requests in Java. Application retries across producer sessions can still duplicate business events. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: Conflicting acknowledgement, retry or in-flight settings; unsupported client versions. Measure: duplicate business events, producer errors and sequence-related failures Java idempotence requires acks=all, retries>0 and max.in.flight.requests.per.connection<=5. Explicit conflicting settings are rejected. Without idempotence, retries with multiple in-flight requests can reorder records. Idempotence does not deduplicate arbitrary application resends. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| max.in.flight.requests.per.connection Java client 4.4 Keep | 5 (unchanged) | Controls request pipelining per broker connection. Java idempotent production supports at most five in-flight requests. Tradeoff: Without idempotence, retries with more than one in-flight request can reorder records. Serializing requests reduces concurrency. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: Raising beyond the client idempotence limit or disabling ordering protections without application review. Measure: request latency, in-flight requests, throughput and record ordering Java idempotence requires acks=all, retries>0 and max.in.flight.requests.per.connection<=5. Explicit conflicting settings are rejected. Without idempotence, retries with multiple in-flight requests can reorder records. Idempotence does not deduplicate arbitrary application resends. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| delivery.timeout.ms Java client 4.4 Evaluate | 2 min → 10 s | Bounds the delivery attempt window after send() returns, including batching, acknowledgement waits and retryable failures. Tradeoff: A longer window delays final failure reporting and can hold buffered records longer. It must be at least request.timeout.ms + linger.ms in Java. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: A failure-response budget shorter than this window, or treating it as a guarantee of successful delivery. Measure: delivery failures, record-queue-time and recovery during broker outages In Java, delivery.timeout.ms must be >= linger.ms + request.timeout.ms. librdkafka timeout names and validation rules are different. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| Other controls | ||
| request.timeout.ms Java client 4.4 Evaluate | 30 s → 5 s | Bounds waiting for a Java client request response. For producers, review it together with the delivery window. Tradeoff: A shorter request timeout can trigger retries during slow responses; it is not an application processing deadline. librdkafka request.timeout.ms has different, broker-enforced acknowledgement semantics. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: Translating this setting directly to librdkafka or setting it below observed response tails. Measure: request-latency-max, timeout rate and retry rate In Java, delivery.timeout.ms must be >= linger.ms + request.timeout.ms. librdkafka timeout names and validation rules are different. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| max.block.ms Java client 4.4 Evaluate | 1 min → 1 s | Bounds blocking in producer API calls for metadata and buffer availability; it is separate from asynchronous delivery timing. Tradeoff: The application thread can block for this duration. User serializer or partitioner time is not included in the documented send() bound. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: Blocking latency-sensitive application threads or assuming this is constrained by linger.ms. Measure: blocked send duration, buffer exhaustion and synchronous send exceptions The producer buffer is shared across partitions. Exhaustion can block send() until max.block.ms; handle synchronous exceptions as well as asynchronous send failures. max.block.ms bounds synchronous waiting for metadata/buffer allocation; linger.ms concerns batching after enqueueing. There is no general requirement that max.block.ms exceed linger.ms. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| metadata.max.age.ms Java client 4.4 Evaluate | 5 min → 30 s | Bounds the interval between periodic metadata refreshes even when no leadership change was detected. Tradeoff: Errors can trigger earlier refreshes. Lowering this interval is not a direct fix for leader failover latency and increases metadata traffic. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: Using periodic refresh as the sole explanation for failover recovery. Measure: metadata request rate, metadata age and discovery time for new partitions Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| Network and buffers | ||
| send.buffer.bytes Java client 4.4 Keep | 128 KiB (unchanged) | Requests a TCP send buffer size; the operating system determines the effective allocation. Tradeoff: Larger socket buffers may use more kernel memory. A larger configured value does not guarantee lower blocking or higher throughput. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: A socket buffer change without evidence of network backpressure or OS limit review. Measure: effective SO_SNDBUF, network throughput, socket memory and RTT Java socket buffers use -1 for the OS default. librdkafka uses 0. Effective allocation and autotuning depend on the OS. Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |
| socket.connection.setup.timeout.ms Java client 4.4 Evaluate | 10 s → 3 s | Sets the initial connection establishment timeout; repeated failures can increase it up to the configured maximum. Tradeoff: A shorter value can reject legitimate slow connections. It does not directly bound every send() call or guarantee immediate rebootstrap. Workload, validation and sourcesWorkload: Production with an explicit latency and failure-response budget; retain delivery guarantees. Avoid when: Slow TLS/authentication paths without measured connection setup times. Measure: connection setup time, connection failures and reconnect rate Versioned reference · 2026-10-27 · unbenchmarked tuning proposal |