Skip to content

Read from an offset

Messaging basics · Article 3 of 12 · 2 min read

Offsets let a consumer stop, restart and replay without losing its place.

The short version

Every message in a partition gets a number called its offset, starting at 0. A consumer reads from an offset and moves forward.

Details

Offsets never change and are never reused. Because Kafka keeps messages, you can go back to an old offset and read again. This is called replaying.

Try it yourself

docker exec -it kafka /opt/kafka/bin/kafka-console-consumer.sh \
  --bootstrap-server localhost:9092 --topic greetings --partition 0 --offset 1 \
  --property print.offset=true

You should see only hello again, labelled with offset 1. The first message, at offset 0, is skipped.

Explain it to the duck

A consumer crashes halfway through a topic. How could an offset help it carry on from the right place?

Tested with: Kafka 4.1.0 in Docker.