Kafka
Producer Error
Batch Expiration
Message Queuing
Debugging Kafka Issues

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.

Practice system design

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:

  1. Network Issues: Delay or disruptions in the network causing high latency.
  2. Broker Overload: The Kafka broker might be overwhelmed with messages, leading to processing delays.
  3. Improper Configuration: Misconfiguration of producer settings like batch.size, linger.ms, and request.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:

  1. Review Network Performance: Ensure the network connectivity between the Kafka producers and brokers is stable and high-speed.
  2. Adjust Producer Configuration: Increase request.timeout.ms to give more time for brokers to respond. However, this means if a broker is down, it will take longer to detect a failure. Reducing linger.ms can also help in speeding up batch sends.
  3. Scale Kafka Brokers: Increase the number of brokers or enhance the current broker configurations to handle higher loads.
  4. Monitoring and Logs: Implement comprehensive monitoring and logging to catch issues early before they impact the system extensively.

Summary Table

ParameterDescriptionSuggested Action
batch.sizeMaximum batch size in bytes the producer can utilize.Increase if underutilized; decrease if overload.
linger.msWait time to add more messages to the batch.Decrease to reduce message waiting time.
request.timeout.msMax 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

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

View the course
Track 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.

Practice system design