Kafka offsetcommit request with high level consumer API
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 popular distributed streaming platform that is extensively employed for building real-time streaming data pipelines and applications. Kafka facilitates the publishing and subscribing of streams of records. In a Kafka cluster, messaging is partitioned and spread over multiple nodes to ensure fault tolerance and horizontal scalability. One of the key components in the Kafka ecosystem involves managing the offset, which is a way to track the progress of a consumer in reading messages from a partition.
Understanding Offsets
In Kafka, an offset is a unique identifier for each record in a partition. It denotes the position of a consumer in the partition. Whenever a consumer reads a message, it advances its offset. Proper management of these offsets ensures that a consumer can resume reading from where it left off in case of any failures or restarts.
The High-Level Consumer API
The High-Level Consumer API abstracts a lot of the complex details involved in managing partitions and offsets. Users can focus on specifying the topics, the group of consumers, and how the records need to be processed. The API is responsible for maintaining the proper offset in the background.
OffsetCommitRequest in Kafka
The OffsetCommitRequest is a crucial part of the Kafka Consumer API. It's the formal way a consumer indicates to Kafka that it has completed processing messages up to a certain point, and Kafka can consider those messages as consumed (i.e., commit the offset). Typically, this operation can either be automated within the high-level API, or explicitly managed by the developer for finer control.
Usage
The high-level consumer uses either an automatic periodic commit based on a timer (auto.commit.interval.ms) or manual committing using the commitSync() and commitAsync() methods from the consumer object. The key distinction is:
- Automatic Committing: With this setting, the consumer offsets are committed automatically at specified intervals to Kafka.
- Manual Committing: Provides the developer more control over when offsets should be committed. This is particularly useful in ensuring that messages are processed and successfully committed only when certain conditions are met.
Technical Details
Under the hood, OffsetCommitRequest keeps track of which messages have been consumed by storing the offset of the next message to be read. Here's a breakdown of how these requests are managed:
- Consumer Group: Each consumer in a group reads from exclusive partitions of the topic. Kafka keeps track of the last offset read by each member of the consumer group.
- Session Management: Kafka also recognizes when a new consumer joins a group or when an existing member leaves. It redistributes the partitions accordingly and ensures that the new consumer starts reading from the correct offset.
Example of Manual Offset Management
Summary Table
| Feature | Description |
| Offset Management | Keeps track of read/messages to ensure data processing continuity. |
OffsetCommitRequest | Used by consumers to report position in stream to Kafka, can be automated or manual. |
| Automatic Committing | Offsets are committed at configurable intervals. Useful for typical use-cases. |
| Manual Committing | Offers greater control, allowing commitments to be made post-conditions verification. |
Conclusion
Properly managing offsets through OffsetCommitRequest in Kafka ensures reliable message consumption in distributed systems, providing flexibility depending on the application’s need for manual control versus convenience. By understanding and utilizing this mechanism effectively, developers can build robust systems that maintain data integrity and consistency, even in the face of failures.
Related reading
- Kafka on AWS ECS, how to handle advertised.host without known instance?
- kafka on kubernetes cannot produce/consume topics (ClosedChannelException, ErrorLoggingCallback)
- Kafka on kubernetes cluster with Istio
- Kafka on kubernetes cluster with Istio
- Kafka Processor API Different key for Source and StateStore?
- Kafka producer difference between flush and poll
- Kafka on Kubernetes multi-node
- Kafka on Masstransit

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.