Monedula

Kafka producer config

max.in.flight.requests.per.connection and message ordering

Producer config · default 5 · Apache Kafka 4.3

max.in.flight.requests.per.connection is how many produce requests a producer may have sent on one connection without an answer yet (default 5). Without idempotence, a value above 1 lets a retried batch land after a later one, reordering the partition. With idempotence on, the broker keeps order for up to 5 in-flight requests, so the default is both fast and ordered.

Config
max.in.flight.requests.per.connection (producer)
Default
5
Valid values
1 or more; 5 or less with idempotence on
Reference
Apache Kafka documentation for max.in.flight.requests.per.connection
A's retry lands at offset 2 - REORDER. A's retry finally appends at offset 2. The log is [A, B, A]: A was produced before B, yet its retried copy sits AFTER B. max.in.flight > 1 + idempotence off reordered the log (and, being non-idempotent, also duplicated A). Open this step in the full playground

What it does

The producer pipelines requests: it can send the next batch to a broker before the previous one is acknowledged. When a request fails with a retriable error and is sent again, the requests behind it may already have been written. An idempotent producer numbers every batch per partition, and the broker rejects a batch that arrives out of sequence so the producer can resend in order; the broker remembers the last 5 batches of each producer, which is where the limit of 5 comes from. A producer without idempotence has no such check, so a retry can append after a later batch.

The trade-off

More requests in flight means more throughput on a high-latency link, because the producer does not wait a full round trip per batch. Setting it to 1 is the old way to keep order without idempotence, at the cost of that pipelining. Above 5, idempotence is no longer possible: if enable.idempotence was not set explicitly it is turned off without a word, and if it was set to true the producer fails with a ConfigException.

Advice

See it in the simulator

Related configs

All Kafka configs