Kafka producer
max.inflight property
data streaming
Apache Kafka
message processing

Kafka producer max.in.flight.requests.per.connection explained

Codemia Knowledge Hub ·

max.in.flight.requests.per.connection (often shortened to max.inflight) sets the maximum number of unacknowledged requests a Kafka producer sends on one connection before it blocks waiting for the broker to acknowledge. Raising it improves throughput; values above 1 combined with retries can deliver messages out of order. It is one of the key settings for tuning a producer's performance and reliability, because it limits how many produce requests can be in flight at once. Set to 1, the producer waits for an acknowledgment after each send before sending the next.

Throughput vs. ordering

  • Higher throughput: More requests in flight let the producer make better use of the network by batching more messages and spending less time waiting for acknowledgments.
  • Ordering risk: With a value greater than 1 and retries > 0, a retry after a failure can put messages out of order, because other messages may succeed and get written while the failed one is being retried.

When order matters, especially where order integrity within a partition is crucial, setting it to 1 is advisable. Otherwise, pick the value that balances throughput and ordering for your application.

How messages get reordered

Suppose the setting is 3:

  1. The producer sends Message 1, Message 2 and Message 3.
  2. Message 1 fails and is retried while messages 2 and 3 succeed. If the retry succeeds after 2 and 3 are written, message 1 ends up after them in the log.

This is the ordering problem that appears whenever max.in.flight.requests.per.connection is greater than 1.

Prioritymax.in.flight.requests.per.connection SettingJustification
High ThroughputHigher (e.g., 5)Increases unacknowledged requests in flight
Strong Ordering Guarantee1Ensures order by processing one request at a time
Balance2-3Provides a middle ground for moderate throughput and ordering
  • Broker configuration: Make sure producer settings fit the broker configuration. Broker settings like max.request.size and message.max.bytes also affect producer behavior.
  • Network latency and bandwidth: A higher value does not always help, especially with high latency or limited bandwidth.
  • Idempotence and error handling: With a higher value, proper error handling and enable.idempotence=true matter more, to handle duplicates caused by retries.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design