Kafka Error OUT_OF_ORDER_SEQUENCE_NUMBER
Error code 45 · Non-retriable Producer
The broker received an out of order sequence number.
Common Causes
- Producer sent batches in a non-sequential order — can happen if in-flight batches are reordered by the network or application logic outside the client
- max.in.flight.requests.per.connection > 1 with retries enabled and a batch was reordered after a retry (pre-Kafka 2.1 issue with idempotent producers)
- Producer instance was restarted mid-session without the broker expiring the old producer ID, causing epoch/sequence desync
Solutions
- Set max.in.flight.requests.per.connection=1 if using older brokers (<2.1); on Kafka 2.1+ with idempotent producers, 5 in-flight requests are safe
- Enable idempotent producer (enable.idempotence=true) which manages sequence numbers correctly and prevents reordering issues
- On producer restart after this error, create a new KafkaProducer instance to get a fresh producer ID rather than reusing the old one
Diagnostic Commands
# Look for sequence number errors in logs
grep 'OUT_OF_ORDER_SEQUENCE\|OutOfOrderSequence\|sequence number' /var/log/kafka/server.log | tail -20
# Check for under-replicated partitions
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic <topic> 2>&1 | grep -E 'Isr|UnderReplicated'Related APIs
This error can be returned by: Produce
Debugging Kafka errors? Conduktor Console gives you real-time visibility into your cluster. Explore all errors in the Error Decoder.