Offset Management: Auto vs Sync vs Async Commits
Evaluate the trade-offs of automatic offset commits versus manual commitSync and commitAsync, and learn how to safely replay historical records.
A consumer's position in a topic partition is defined by an integer: the Offset. When a consumer crashes, restarts, or undergoes a partition rebalance, it queries the cluster to find out where to resume reading.
If your offset management strategy is flawed, your application will either process duplicate records by the thousands or silently drop records without processing them.
In this lesson, you will evaluate the three offset commit strategies, understand where Kafka stores commit checkpoints, and learn how to rewind offsets for historical data replay.
01The Three Offset Concepts
Before evaluating commit strategies, distinguish between three distinct offset pointers:
[Offset 0] ... [Offset 40 (Committed)] ... [Offset 45 (Current Read)] ... [Offset 50 (HW)]- Current Read Offset: The offset of the next record returned to your code by
consumer.poll(). The consumer advances this pointer in memory as records are iterated. - Committed Offset: The highest offset confirmed and written to Kafka's internal storage. If the consumer dies right now, the replacement consumer instance will start reading from this committed offset.
- High Watermark (HW): The upper boundary of messages safely replicated across the In-Sync Replicas (ISR). Consumers cannot read past the High Watermark.
Where Offsets Live: The __consumer_offsets Topic
In early versions of Kafka, offsets were stored in ZooKeeper. In modern Kafka, offsets are stored in an internal, compacted system topic named:
__consumer_offsetsThis topic has 50 partitions by default and uses log compaction. Each record in __consumer_offsets is a key-value pair where the key is [groupId, topic, partition] and the value is [offset, metadata, commitTimestamp].
Because the topic is compacted, Kafka retains only the latest committed offset per consumer group per partition, keeping storage overhead minimal.
Loading the rest of the lesson…