Consumer offset

Also known as: Kafka offset

On this page 8

A consumer offset is the position of the next record to read in a partition of an append-only log, stored on behalf of a consumer or consumer group so that processing can resume exactly where it stopped. In streaming data platforms such as Kafka, where the term Kafka offset is common, every record in a partition receives a monotonically increasing integer, and the committed offset is simply the number of the next record the consumer expects to see.

Offsets turn a passive log into a replayable source of truth. Because the broker does not delete records when they are read, the offset alone decides what counts as consumed, which makes it the central lever for recovery, reprocessing and delivery guarantees in streaming data pipelines.

How a consumer offset tracks progress

A consumer offset tracks progress by recording, per partition and per consumer group, the index of the first record that has not yet been processed. The broker assigns each appended record an offset that starts at zero and never changes or gets reused, so a single integer is enough to describe a reader’s position in an ordered sequence.

Reading and committing are two separate operations. The consumer fetches a batch starting at its current in-memory position, processes the records, and then commits the offset of the next unread record to durable storage. In Kafka, committed offsets live in an internal compacted topic named __consumer_offsets, keyed by group, topic and partition, which replaced the older practice of storing them in ZooKeeper.

The following table separates the related positions that practitioners often confuse when they inspect a partition.

PositionWhat it marksWho maintains it
Log start offsetOldest record still retainedBroker, through retention and deletion
Committed offsetNext record the group will read after restartConsumer, through commits
Current positionNext record the running consumer will fetchConsumer client, in memory
High watermarkEnd of fully replicated, readable recordsPartition leader
Log end offsetOffset the next appended record will receivePartition leader
Positions tracked in a log partition

The difference between the high watermark and the committed offset is the consumer lag, measured in records. Lag is the most widely monitored health signal in a streaming system because it shows directly how far a consumer has fallen behind the producers.

Commit strategies and delivery guarantees

The moment at which an offset is committed relative to processing determines the delivery guarantee a pipeline provides. Committing before processing risks losing records if the consumer crashes mid-batch, while committing after processing risks reprocessing records that were handled but not yet acknowledged.

This table maps the main commit strategies to the guarantee each one produces in practice.

StrategyFailure outcomeResulting guarantee
Commit before processingUncompleted records are skippedAt-most-once
Commit after processingLast batch is processed againAt-least-once
Periodic auto-commitLoss or duplication, depending on timingWeak, timing-dependent
Transactional commit with outputOffsets and results succeed or fail togetherExactly-once within the platform
Offsets stored in the sinkSink and position stay consistentEffectively exactly-once
Commit timing and resulting semantics

Auto-commit in the Kafka client commits on a timer, by default every 5 seconds, during subsequent polls. It is convenient but couples correctness to timing, so production pipelines usually disable it and commit explicitly after successful processing. Exactly-once semantics in Kafka rely on a transactional producer that writes output records and the consumer offset in one atomic transaction, so a downstream reader configured with read-committed isolation never sees partial results.

An alternative pattern stores offsets in the destination database alongside the processed data. Because the write and the position update share one transaction in the sink, a restart reads the offset from the sink and seeks to it, which gives idempotent, consistent recovery even when the broker itself offers no transactions.

Offsets within consumer groups and rebalancing

Offsets belong to the consumer group, not to an individual consumer process. When a group rebalances, for example because a member joins, leaves or misses its heartbeat, partitions move to other members, and each new owner resumes from the committed offset of the partition it receives.

This design makes uncommitted progress the main source of duplicates. Records that the previous owner processed but did not commit are delivered again to the new owner, which is why rebalance listeners commit pending offsets when partitions are revoked. Cooperative incremental rebalancing reduces this exposure by moving only the partitions that must change hands instead of stopping the whole group.

Independent groups keep completely separate offsets for the same topic. A fraud detection service and an archiving job can read one stream at different speeds without interfering, which is the practical basis of the publish-subscribe model on a log-based message broker.

Resetting and replaying with offsets

Resetting an offset lets a team replay history or skip ahead without changing the data itself. Replay is a core advantage of log-based systems over traditional queues, and it underpins the Kappa architecture, in which a reprocessed stream replaces a separate batch layer.

When no committed offset exists, or the stored one points to data already deleted by retention, the client applies the auto.offset.reset policy. The choice between options has real consequences for data completeness, as the following table shows.

Reset optionStarting pointTypical use
earliestLog start offsetBackfills, new analytical consumers
latestLog end offsetLive dashboards that ignore history
noneError raised to the applicationPipelines that must never guess
By timestampFirst record at or after a timeReplay after a faulty deployment
Shift by NCurrent offset plus or minus NSkipping a poison record
Offset reset options and typical uses

Administrative tools such as the Kafka consumer groups command can reset offsets only while the group is inactive. Timestamp-based resets use a per-partition time index, so they map a wall-clock moment to an offset with record-level precision rather than relying on guesswork.

Offsets in other streaming platforms

Every log-based platform has an equivalent of the consumer offset, although names and storage differ. Comparing them clarifies that the concept is architectural rather than vendor-specific.

PlatformPosition conceptWhere it is stored
Kafka and RedpandaInteger offset per partitionInternal offsets topic
Apache PulsarMessage ID with cursorBroker-managed subscription cursor
Amazon KinesisSequence number per shardClient checkpoint table
Apache Flink sourceOffset inside a checkpointCheckpoint state, optionally committed back
Position tracking across platforms

In Apache Flink, the checkpointed offset is authoritative, and any offset committed back to Kafka serves mainly for lag monitoring. Confusing these two positions is a frequent cause of misread dashboards during recovery.

Common mistakes with consumer offsets

Most offset problems come from committing at the wrong moment or from misunderstanding retention. The recurring failure modes are well known among operators of streaming systems.

  • Committing asynchronously without ordering checks, so a late older commit overwrites a newer one.
  • Offset retention expiring for idle groups, which by default happens after 7 days in recent Kafka versions and silently triggers the reset policy.
  • Processing that outlasts the poll interval, which removes the consumer from the group and causes repeated rebalances and duplicates.
  • Assuming offsets are contiguous in compacted or transactional topics, where gaps are normal.
  • Treating lag in records as lag in time, although a burst of small messages can look worse than a slow trickle of large ones.

In everyday language

A consumer offset works like a bookmark in a very long book that keeps growing at the end. The book never loses pages when someone reads them, so each reader needs a bookmark to remember where to continue.

If a reader falls asleep, the bookmark shows the exact page to start from in the morning. If the bookmark was moved too early, a few pages are missed; if it was moved too late, a few pages are read twice. Where and when the bookmark moves decides whether anything is lost or repeated.

Seen in the real world

A payments company runs a consumer group that reads card transactions from a topic with 24 partitions and writes enriched records to a warehouse. The service commits offsets only after the warehouse confirms each batch, which gives at-least-once delivery, and the warehouse table uses the transaction ID as a key so that duplicates are ignored on insert.

After a deployment introduces a currency conversion bug, engineers stop the group, reset its offsets by timestamp to the deployment time, and restart a corrected version. Roughly two hours of transactions are reprocessed within twenty minutes, and the warehouse ends up correct without any manual data repair, because the offset made a precise replay possible.