Kafka Exception OutOfOrderSequenceException
This exception indicates that the broker received an unexpected sequence number from the producer, which means that data may have been lost. If the producer is configured for idempotence only (i.e. if enable.idempotence is set and no transactional.id is configured), it is possible to continue sending with the same producer instance, but doing so risks reordering of sent records. For transactional producers, this is a fatal error and you should close the producer.
Reviewed 2026-10-27 · 4.4.0 · source-reviewed. Source · Source
Common Causes
- The broker received an unexpected sequence number for a producer ID and epoch. The final application exception and the internal response need different handling.
Solutions
- Use the selected client’s idempotence constraints: Kafka Java 4.4 requires acks=all, retries>0 and max.in.flight.requests.per.connection<=5. This is a client configuration requirement, not a broker-version-only rule.
- An OutOfOrderSequenceException exposed to a transactional producer is fatal. For an idempotent producer, inspect the documented ordering/data-loss implications before continuing or recreating it. Do not blindly replay an ambiguous batch.
Example Stack Trace
org.apache.kafka.common.errors.OutOfOrderSequenceException: The broker received an out of order sequence number.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
Protocol error: OUT_OF_ORDER_SEQUENCE_NUMBER (code 45)
Related Producer exceptions: BufferExhaustedException · InvalidProducerEpochException · RecordBatchTooLargeException · RecordTooLargeException · TransactionAbortedException · UnknownProducerIdException · UnsupportedForMessageFormatException
OutOfOrderSequenceException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.