Video in progress
What does an offset mean in Kafka?
An offset is the sequence number of a message within a partition (0, 1, 2...). The consumer group commits the offset it has processed up to and continues from there after a restart.
📖 Answer
An offset only means something inside one partition. Offset 15 in orders-0 and offset 15 in orders-1 are completely different messages.
There are two kinds of offsets to tell apart:
- log-end offset — the number of the next message that will be written to the partition;
- committed offset — the number the consumer group saved as "I've processed up to here".
The committed offset is stored in Kafka's internal __consumer_offsets topic. In old versions it lived in ZooKeeper; not anymore.
One subtle point: the value you commit is the offset of the next message to read. So if you've finished message 41, you commit 42. Spring Kafka does this for you, but if you call commitSync(Map) by hand, don't forget the +1. Otherwise the last message comes again after a restart.
Sign up to mark studied questions and save your progress.