How to view and set offsets.retention.minutes using kafka-configs
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Apache Kafka employs various configuration parameters that control how data is managed within the system. One of these configurations is offsets.retention.minutes, which plays a critical role in determining how long Kafka retains offset information on the broker side.
Understanding Offsets in Kafka
In Kafka, an offset is a unique identifier for each record within a partition. It denotes the position of each record in the partition. Consumer groups need these offsets to track the records that have already been processed. Once a record is processed by all members of the consumer group, its offset can be considered obsolete.
Importance of offsets.retention.minutes
The offsets.retention.minutes setting specifies the minimum amount of time that the offset data will be retained after its consumer group is inactive. If the consumer group does not consume any new messages for a duration that exceeds the specified retention period, the offset data might be deleted.
Default Setting
By default, Kafka sets the offsets.retention.minutes to 10080 minutes (7 days). This means that offset data is safeguarded against deletion for a week after consumer inactivity.
Viewing and Setting offsets.retention.minutes
Apache Kafka provides a command-line tool, kafka-configs.sh, which is useful for modifying broker configurations without needing to restart the broker.
Viewing Current Configuration
To view the current setting of offsets.retention.minutes, you can execute the following command on a Kafka broker:
Replace localhost:9092 with your Kafka broker's address and 0 with the actual broker ID. This command will list all configurations for the specified broker, including the offsets.retention.minutes if explicitly set.
Modifying the Offset Retention Period
To change the offsets.retention.minutes, use the following command:
Again, replace localhost:9092 with your broker's address, 0 with the desired broker’s ID, and <new_value_in_minutes> with the new offset retention period in minutes.
Example Scenario
Suppose a Kafka system is experiencing rapid offset data buildup due to inactive consumer groups over long periods. To mitigate this, you might want to reduce the offset retention period from the default 7 days to 3 days (4320 minutes). You can do this with the following command:
Summary Table
| Parameter | Description | Default Value | Command to Alter |
offsets.retention.minutes | Time in minutes Kafka retains the offsets after a consumer group becomes inactive. | 10080 (7 days) | kafka-configs.sh --entity-type brokers --alter --add-config offsets.retention.minutes=<minutes> |
Additional Considerations
- Impact on Consumers: Lowering the
offsets.retention.minutescan lead to the loss of offset data for inactive consumer groups, potentially causing re-processing of messages. - Cluster-Wide Settings: The change affects all topics on the broker unless overridden at the topic level.
Conclusion
Proper management of offsets.retention.minutes is crucial for maintaining efficient data management and ensuring that consumer groups can continue from the last processed message without any issues. By utilizing the kafka-configs.sh tool, administrators can adapt their Kafka configuration dynamically to meet their operational requirements.

