how to get the group commit offset from kafka(0.10.x)
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a distributed streaming platform designed to handle data streams in a fault-tolerant and scalable way. One of the key concepts in Kafka is the commit offset, which plays a crucial role in message consumption. In Kafka version 0.10.x, understanding how to retrieve and manage these offsets can significantly impact the efficiency and reliability of data processing pipelines. This article details how to get the group commit offset from Kafka 0.10.x and includes technical explanations and examples.
Understanding Kafka Offsets
In Kafka, an offset is a unique identifier for each record in a partition. It denotes the position of a record within that partition. For consumers grouped together (consumer group), keeping track of which messages have been successfully processed (committed) is managed through offsets. The commit offset for a consumer group in a particular partition is the next message offset that the group is expected to read. By committing this offset, the consumer can handle failures and restarts without data loss or message duplication by resuming from the last committed offset.
How Offsets are Stored in Kafka 0.10.x
In Kafka 0.10.x, offsets can be stored in two ways:
- Kafka internal topic (__consumer_offsets): From version 0.9 onwards, Kafka provides a built-in mechanism to store offsets within an internal Kafka topic named
__consumer_offsets. - Zookeeper: Earlier versions largely used Zookeeper for storing offsets. However, storing offsets in Zookeeper isn’t recommended since version 0.9 because of scalability issues.
Retrieving Commit Offsets
To retrieve the committed offsets for a consumer group in Kafka 0.10.x, you can use the Kafka-consumer-groups tool. This command-line utility comes with the Kafka distribution and can list all consumer groups, describe a group, delete consumer group info, or reset consumer group offsets.
Using Kafka Consumer Groups Command
Here’s how to get the group commit offset using the kafka-consumer-groups.sh script:
Replace localhost:9092 with your Kafka server and my-consumer-group with the name of your consumer group. This command returns information about where each consumer in the group is in terms of offset.
Output Analysis:
The output will contain columns showing:
- TOPIC & PARTITION: The specific topic and partition.
- CURRENT-OFFSET: The latest offset that has been consumed.
- LOG-END-OFFSET: The last offset available in the log.
- LAG: The difference between the last available offset and the latest consumed one.
Example Output:
Handling Offset Commits Programmatically
In scenarios where programmatically handling offsets is necessary, consumer APIs provide methods to manually commit offsets. You can use the manual commit pattern when you need fine-grained control over offset commits.
For example, using Kafka's Consumer API in Java:
In this example, commitSync() is called to commit the offsets in a synchronous manner.
Summary
| Feature | Description |
| Offset Storage | Kafka 0.10.x stores offsets in __consumer_offsets topic or in Zookeeper (deprecated). |
| Tools Use | kafka-consumer-groups.sh for retrieving and managing commit offsets. |
| Programmatic Control | Kafka Consumer API allows programmatic commits and fetches of offsets. |
| Offset Commit Command | Use commitSync() or commitAsync() for manual offset management in the Consumer API. |
Related reading
- How to get the latest offset from the Kafka topic in Confluent kafka C# library?
- How to get topic list from kafka server in Java
- How to get topics list from Kafka using C#
- How to get windowed aggregation from kafka stream?
- How to get the short sha for the github workflow?
- How to get their changes in the middle of conflicting Git rebase?
- How to gracefully shutdown spring-kafka consumer application
- How to Guarantee Message delivery with Celery?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.