Kafka
Consumer Group
Offset Retention
Data Management
Distributed Systems

Kafka consumer group offset retention (offsets.retention.minutes)

Codemia Knowledge Hub ·

Kafka keeps a consumer group's committed offsets for at least offsets.retention.minutes, which defaults to 10080 minutes (one week) since Kafka 2.0. Since Kafka 2.1 (KIP-211) the clock starts when the group becomes empty, so an active group keeps its offsets. Once the group has had no members for that long, its offsets may be discarded and it can no longer resume from where it left off.

What a consumer group offset is

A consumer group is a set of consumers that jointly read one or more topics, with each consumer reading specific partitions. The offset is a number that tracks the last record a consumer read in a given partition. Committed offsets let the group pick up where it stopped after a consumer failure or rebalance.

Why retention matters

Retained offsets let a group resume consumption after a period of inactivity or a restart. Retention mostly matters for consumers that process data infrequently, or that are down for maintenance or upgrades.

offsets.retention.minutes and offsets.retention.check.interval.ms

offsets.retention.minutes sets the minimum period, in minutes, to retain committed offsets. The default of 10080 can be changed to fit business requirements or operational policies.

offsets.retention.check.interval.ms controls how often Kafka checks for stale offsets to purge. A shorter interval cleans up offsets faster but may add load on the brokers.

ParameterDefault ValueDescription
offsets.retention.minutes10080 minutesMinimum time to retain the committed offsets.
offsets.retention.check.interval.ms600000 (10 minutes)Frequency at which Kafka checks for old offsets to clean.

Example configuration:

properties
1# Set offset retention to 3 days
2offsets.retention.minutes=4320
3
4# Set interval for offset retention check to 6 hours
5offsets.retention.check.interval.ms=21600000

Where offsets are stored

Consumers commit offsets to an internal Kafka topic named __consumer_offsets, which Kafka manages itself. Kafka periodically checks this data against the retention configuration and removes entries that exceed the threshold.

What goes wrong when retention is misconfigured

  • Data re-processing: if offsets are cleaned up too early, consumers can start from an earlier offset and process messages again.
  • Loss of state information: stateful applications that rely on offsets for context or processing order can be significantly disrupted.
  • Storage cost: very long retention rarely affects consumers, but it increases storage on the brokers, which can indirectly affect performance.

Choosing a retention period

  • Match consumption patterns: infrequent consumers may need longer retention.
  • Monitor and adjust: revisit the settings as the scale or shape of consumption changes.
  • Balance: weigh retention duration against broker resource usage.

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