How to get last consumed offset for a consumer group?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
In distributed systems that process data streams, managing how much information each part of the system has processed is critical. For Apache Kafka, a popular distributed event streaming platform, this tracking is handled via consumer offsets. Understanding how to retrieve these offsets for a consumer group is essential for monitoring and administrating your Kafka deployment. This involves using tools provided by Kafka and can also be executed programmatically.
Understanding Consumer Groups and Offsets
First, let's clarify some fundamental Kafka concepts:
- Consumer: Part of an application that reads messages from Kafka topics.
- Consumer Group: Collection of one or more consumers that together consume a topic. They share a group ID.
- Offset: A sequential id tied to each message within a partition. It denotes the position of a consumer in a topic partition.
When consumers in a group read messages from a topic, they commit the offsets of messages they have processed. The last consumed offset is the latest position of the consumer in the log of a partition that the consumer has acknowledged processing effectively.
Retrieving Last Consumed Offsets
Using Kafka Command Line Tools
Kafka ships with a command-line tool known as kafka-consumer-groups.sh, which can list consumer groups, describe their status, and reset consumer offsets.
Here’s a step-by-step process to find the last consumed offsets using this tool:
- Open your terminal.
- Run the command below to get information on consumer groups:
Replace localhost:9092 with your Kafka server's address and your-consumer-group-id with the actual consumer group ID.
This command provides output like the following:
Here, CURRENT-OFFSET is the last offset that the consumer has consumed.
Programmatically Using Kafka API
If you integrate this functionality into your applications, you can use Kafka’s Consumer API. Below is an example using the Java programming language:
Summary Table
| Term | Description |
| Consumer | Reads messages from Kafka topics. |
| Consumer Group | A group of consumers sharing a group ID to consume a topic collaboratively. |
| Offset | Unique identifier for each message in a partition, marking message's position. |
CURRENT-OFFSET | The last message offset acknowledged by a consumer. |
LOG-END-OFFSET | The offset of the latest message in the log + 1. |
Conclusion
Knowing how to retrieve the last consumed offset for a Kafka consumer group is crucial for effectively managing a Kafka-based system. It helps in monitoring progress, troubleshooting issues, and ensuring data integrity through proper synchronization of consumer positions within a stream. Whether through command-line tools or directly within your code, Kafka provides flexible options tailored for diverse operational needs.
Related reading
- How to get latest offset for a partition for a kafka topic?
- How to get message by key from kafka topic
- How to get message from a kafka topic with a specific offset
- How to get rid of negative consumer lag in Kafka
- How to get Spring RabbitMQ to create a new Queue?
- how to get the all messages in a topic from kafka server
- how to get the group commit offset from kafka(0.10.x)
- How to get the latest offset from the Kafka topic in Confluent kafka C# library?

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.