Offsets, Seeking and Replay

Kafka · lesson 19 of 34 · 4 min read

Control where a consumer starts, and rewind a group on purpose without guessing.

Open this lesson in the learning hub

Key points

  • auto.offset.reset applies only when a group has no committed offset for a partition: earliest, latest or none.
  • It is not a replay switch. An existing group already has offsets, so changing the setting and restarting does exactly nothing.
  • To replay: stop every member, then --reset-offsets with --to-earliest, --to-datetime or a shift.
  • Run it with --dry-run first. It prints the offsets it would write; --execute is what actually commits them.
  • In code, seek() after the first poll(), or from a ConsumerRebalanceListener.
  • A replay re-runs every side effect. Only ever replay into handlers you know are idempotent.

Example

# Where is the group now? Stop all members first -- a live group refuses a reset.
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
  --describe --group billing-service

# Dry run: prints target offsets, writes nothing
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
  --group billing-service --topic orders \
  --reset-offsets --to-earliest --dry-run

# Replay everything since a point in time
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
  --group billing-service --topic orders \
  --reset-offsets --to-datetime 2026-07-01T00:00:00.000 --execute

# Nudge one partition back 500 records:
#   --topic orders:3 --reset-offsets --shift-by -500 --execute

auto.offset.reset is for new groups only. Replay is a deliberate, dry-run-first offset reset.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Kafka course, and every lesson in it is listed on the Kafka contents page.