Kafka offset
auto commit
offset store
Kafka configuration
message processing

Kafka enable.auto.commit vs enable.auto.offset.store

Codemia Knowledge Hub ·

enable.auto.commit decides whether the consumer periodically commits offsets to Kafka in the background. enable.auto.offset.store (a librdkafka setting, used by clients such as confluent-kafka) decides which offsets are eligible for that commit: when it is true, the default, an offset is stored automatically as soon as a message is handed to your application; when it is false, only offsets you store yourself after processing get committed.

What an offset is

An offset uniquely identifies a record within a partition and marks its position in the immutable log. Committed offsets let a consumer resume from where it stopped after a failure or restart.

enable.auto.commit

With enable.auto.commit=true, the consumer commits offsets automatically on an interval, writing them to the __consumer_offsets topic. After a restart it resumes from the last committed offset.

Example configuration:

properties
enable.auto.commit=true
auto.commit.interval.ms=5000

Here offsets are committed every 5000 milliseconds. A smaller interval reduces how many messages are re-processed after a failure, but adds commit overhead. Auto-commit does not guarantee that each message is processed only once: messages handled after the last commit are delivered again after a crash.

enable.auto.offset.store

Setting enable.auto.offset.store=false stops the client from storing offsets automatically when messages are read. Your application then stores the offset explicitly once processing succeeds (for example with store_offsets() in confluent-kafka Python), and the background auto-commit commits only those stored offsets. Alternatively, with auto-commit also off, you commit manually.

Example scenario: each message's result must be written to a database, and the offset should advance only if that write succeeds. If offsets advance automatically on read, an error between consuming the message and writing the result can lose or duplicate data. With enable.auto.offset.store=false, you store the offset only after the database write.

Configuration KeyValue OptionsPurposeTypical Use Case
enable.auto.committrue / falseEnable or disable auto-commit of offsetsFor simpler use cases without strict transaction requirements
enable.auto.offset.storetrue / falseEnable or disable auto-storage of offsets when readTo manage offsets manually in complex processing scenarios

Combining the two settings

  • Auto-commit on, auto offset store off: the common pattern for at-least-once processing with librdkafka. You store each offset after processing the message, and the background commit sends the stored offsets to Kafka. Forgetting to store offsets means nothing is committed.
  • Both off: full manual control. You commit offsets yourself, which suits systems with strict transactional requirements.

Choosing and testing an offset strategy

  1. Decide on the processing guarantee you need (at-most-once, at-least-once, exactly-once) before choosing the configuration.
  2. Test consumer failover to confirm behavior under failure, especially with manual offset control.
  3. Monitor offset lag and consumer groups for abnormalities, whatever the configuration.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design