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:
- The producer sends Message 1, Message 2 and Message 3.
- 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.
Recommended values
| Priority | max.in.flight.requests.per.connection Setting | Justification |
| High Throughput | Higher (e.g., 5) | Increases unacknowledged requests in flight |
| Strong Ordering Guarantee | 1 | Ensures order by processing one request at a time |
| Balance | 2-3 | Provides a middle ground for moderate throughput and ordering |
Related settings to check
- Broker configuration: Make sure producer settings fit the broker configuration. Broker settings like
max.request.sizeandmessage.max.bytesalso 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=truematter more, to handle duplicates caused by retries.
Related reading
- Uneven Distribution of messages in Kafka Partitions
- Unexpected Kafka request of type METADATA during SASL handshake
- Unit test on rabbitMQ
- Unknown magic byte with kafka-avro-console-consumer
- Unknown queue names show on Rabbitmq mgmt. when using Celery
- UnknownHostException kafka
- UnknownMemberId Error in AIOKafka library while consuming messages
- unreasonable length when running kafka-topics command
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.