Kafka Exception OffsetOutOfRangeException
org.apache.kafka.common.errors.OffsetOutOfRangeException
Non-retriable
Consumer
No reset policy has been defined, and the offsets for these partitions are either larger or smaller than the range of offsets the server has for the given partition.
Common Causes
- Consumer stored offset points to a segment that has since been deleted by retention policy (time or size-based)
- Consumer group was inactive for a long time and the committed offset fell behind the log start offset
- Topic was deleted and recreated, resetting offsets to 0, but consumer still holds the old committed offset
Solutions
- Set 'auto.offset.reset=earliest' on the consumer to fall back to the beginning of available data when the stored offset is out of range
- Use kafka-consumer-groups.sh --reset-offsets to explicitly reposition the consumer group to --to-earliest, --to-latest, or --to-datetime <timestamp>
- If data loss is a concern, increase log retention: set 'log.retention.hours' or 'log.retention.bytes' on the topic to ensure offsets remain valid longer than your consumer SLA
Example Stack Trace
org.apache.kafka.common.errors.OffsetOutOfRangeException: The requested offset is not within the range of offsets maintained by the server.Diagnostic Commands
# Describe consumer group offsets and lag
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group <group> --describe
# Check earliest and latest offsets for the topic
kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic <topic> --time -2
# Check latest offsets
kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic <topic> --time -1Related
Protocol error: OFFSET_OUT_OF_RANGE (code 1)
Related Consumer exceptions: CommitFailedException · CoordinatorLoadInProgressException · CoordinatorNotAvailableException · FencedInstanceIdException · FencedMemberEpochException · GroupMaxSizeReachedException · IllegalGenerationException · InvalidGroupIdException
Hitting
OffsetOutOfRangeException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.