liveBook · Manning

Automatic offset commit

As explained in Kafka Streams in Action, Second Edition

Automatic offset commit is a consumer behavior that periodically records the offsets associated with consumed records without an explicit commit call.

Automatic offset commit lets KafkaConsumer periodically record the offsets for consumed records without an explicit commit call. Enable it with enable.auto.commit=true; auto.commit.interval.ms controls the elapsed time between commit checks. section 4.3.5

A poll retrieves a batch, the application processes it, and the consumer checks the interval before starting the next poll. When the interval has passed, Kafka commits the previous batch’s highest offset plus one, marking those records as consumed. section 4.3.5

Figure 4.17 With automatic commits enabled when returning to the top of the poll loop, the consumer commits the highest offset +1 of the previous batch if the auto-commit interval has passed.
figure

Trace the poll-loop timing and the highest-offset-plus-one value used by automatic commits. section 4.3.5

Keep these operational consequences in mind:

  • Kafka stores committed offsets in the internal __consumer_offsets topic. section 4.3.5
  • Failures before a commit can cause records to be processed again after restart. section 4.3.5
  • Asynchronous processing combined with auto-commit can potentially mark records before processing finishes, losing them on failure. section 4.3.5

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains configuration, poll-loop timing, offset arithmetic, broker storage, and failure consequences, but not commit implementation code.
Examples
Uses a batch spanning offsets 10 through 20 and diagrams showing reprocessing and asynchronous-processing loss.
What it assumes
Assumes basic KafkaConsumer polling while establishing offsets, committed positions, and broker-managed offset storage.
What you can do after
Configure KafkaConsumer automatic commits and anticipate duplicate processing or potential loss around asynchronous work.
How it connects
Connects KafkaConsumer, offsets, polling, topics, partitions, and the __consumer_offsets topic.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.