Kafka Producer error Expiring 10 record(s) for TOPICXXXXXX 6686 ms has passed since batch creation plus linger time
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a distributed event streaming platform capable of handling trillions of events a day. While Kafka is designed for high throughput and reliability, developers may encounter errors during the production of messages. One common issue is the message expiration in Kafka producers. Understanding the specifics of this error message, 'Expiring 10 record(s) for TOPIC:XXXXXX: 6686 ms has passed since batch creation plus linger time', is crucial for effectively managing Kafka applications.
What does the Error Message Mean?
This error occurs when a Kafka producer attempts to send a batch of messages to a Kafka topic, but the batch is not sent within a specified timeout period. The error message:
Expiring 10 record(s) for TOPIC:XXXXXX: 6686 ms has passed since batch creation plus linger time
tells us that:
10 record(s)were due to be sent.- They were for
TOPIC:XXXXXX. - The time elapsed since the batch was created, combined with the configured linger time, exceeded
6686 ms.
Underlying Causes
Several factors might contribute to the occurrence of this error:
- Network Issues: Delay or disruptions in the network causing high latency.
- Broker Overload: The Kafka broker might be overwhelmed with messages, leading to processing delays.
- Improper Configuration: Misconfiguration of producer settings like
batch.size,linger.ms, andrequest.timeout.ms.
Key Producer Parameters
- batch.size: Controls the maximum size of a batch of records that can be sent to a broker.
- linger.ms: Determines how long a producer will wait to allow other records to join a batch before sending it off.
- request.timeout.ms: This is the duration the producer will wait for a response from the broker after sending data.
When a producer sends a message, if it doesn't receive an acknowledgment from the broker within the request.timeout.ms, it throws a timeout exception, leading to message expiration as other factors like batch.size or linger.ms might also be influencing.
Troubleshooting and Mitigation Steps
To reduce the likelihood of this error, consider the following adjustments:
- Review Network Performance: Ensure the network connectivity between the Kafka producers and brokers is stable and high-speed.
- Adjust Producer Configuration: Increase
request.timeout.msto give more time for brokers to respond. However, this means if a broker is down, it will take longer to detect a failure. Reducinglinger.mscan also help in speeding up batch sends. - Scale Kafka Brokers: Increase the number of brokers or enhance the current broker configurations to handle higher loads.
- Monitoring and Logs: Implement comprehensive monitoring and logging to catch issues early before they impact the system extensively.
Summary Table
| Parameter | Description | Suggested Action |
batch.size | Maximum batch size in bytes the producer can utilize. | Increase if underutilized; decrease if overload. |
linger.ms | Wait time to add more messages to the batch. | Decrease to reduce message waiting time. |
request.timeout.ms | Max wait time for a broker's acknowledgement. | Increase in case of network delays. |
Additional Considerations
While troubleshooting, it's essential to find a balance in configurations to achieve optimal performance without risking message loss or delay. Ensuring the producers, brokers, and consumer configurations are in harmony can greatly enhance system reliability.
Through understanding and regular monitoring of Kafka metrics, logs, and error messages, developers can maintain a robust Kafka environment, minimizing issues like message expiring and ensuring smooth data flow for real-time applications.
Related reading
- Kafka Producer Exception NoClassDefFoundError
- Kafka producer fails to send messages with NOT_LEADER_FOR_PARTITION exception
- Kafka Producer From Remote Server
- Kafka Producer Got error produce response with correlation NETWORK_EXCEPTION
- Kafka Producer Handle Exception in Async Send with Callback
- Kafka producer is connecting to localhost instead of the real IP
- Kafka producer huge memory usage (leak?)
- Kafka producer in a multi-broker, multi-server cluster cannot write to newly created topic

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.