Kafka
TimeoutException
Kafka Producer
IT Troubleshooting
Software Bugs

Kafka producer TimeoutException: Expiring 1 record(s), causes and fixes

Codemia Knowledge Hub ·

The producer throws TimeoutException: Expiring 1 record(s) when a record was not acknowledged by the brokers within its delivery timeout. On Kafka 2.1 and later clients that is delivery.timeout.ms (default 2 minutes), which covers batching, waiting for the acknowledgment and retries; older clients expired batches after request.timeout.ms. The usual causes are a slow network, overloaded brokers, large messages, or badly tuned delivery.timeout.ms, request.timeout.ms, batch.size or linger.ms. Raise the timeout, shrink large payloads, fix the network path and give the brokers more capacity.

What the error looks like

 
org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s): Expiring 1 record(s) for TOPIC-1:1200 ms has passed since last append

The producer could not get acknowledgment from the brokers for the record writes within the configured timeout, so it gave up on (expired) the pending records. The message also states how many records the timeout applied to, which here is one.

Causes

  1. Network issues: slow or unreliable connections between the producer and the cluster delay sends and acknowledgments.
  2. Broker performance: overloaded or struggling brokers cannot process incoming messages fast enough.
  3. Large messages: big payloads process slowly, especially with limited bandwidth.
  4. Configuration: poor values for request.timeout.ms, batch.size or linger.ms cause premature timeouts.

What it costs you in production

  • Data loss: unacknowledged records can be lost unless they are re-sent.
  • Lower throughput: frequent timeouts drag down overall performance.
  • Higher latency: re-sending adds latency, which can rule out real-time use.

Fixes

  1. Increase the timeouts: raise delivery.timeout.ms (and request.timeout.ms if individual requests time out) so records have more time before they expire. Kafka requires delivery.timeout.ms to be at least request.timeout.ms plus linger.ms.
  2. Reduce message size: split large payloads into smaller ones.
  3. Review the network: tune the network between producer and Kafka for throughput and low latency.
  4. Scale or tune the brokers: scale up the brokers or optimize their configuration so they handle higher loads efficiently.

Producer settings involved

These are the producer parameters most closely tied to this exception. Review them together, because batching settings change how long records wait before they are sent:

ParameterDescriptionTypical Value
request.timeout.msThe timeout for a request.30 seconds
batch.sizeThe maximum size of a batch of records to be sent in one go.16KB
linger.msAdds a small amount of latency to batch records more effectively.0 or 1 ms

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