Kafka - difference between Log end offset(LEO) vs High Watermark(HW)
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Apache Kafka is a widely utilized distributed streaming platform, designed to handle high-throughput, low-latency data pipelines, and streaming applications. Two critical concepts integral to understanding Kafka's data consistency and reliability models are the Log End Offset (LEO) and the High Watermark (HW).
Log End Offset (LEO)
Log End Offset (LEO) represents the offset position where the next new message will be appended within a Kafka log partition. Each broker in a Kafka cluster maintains its own LEO for each partition it hosts. This offset is crucial for producers, as it gives them the point at which the next message can be written.
Technical Explanation: Upon receiving a new message, a Kafka broker increments its LEO and appends the message at this new offset. The LEO is always moving forward as new messages are appended. Importantly, the LEO is local to the broker's view of the log and can vary between brokers until replication is complete.
Example: Suppose a producer sends a message to a topic with a single partition hosted by three brokers. The LEO is initially 10, meaning the last message was written at offset 9. When the new message is appended, the LEO on the leader broker immediately increments to 11. However, follower brokers will only update their LEO once they have successfully replicated the new message.
High Watermark (HW)
High Watermark (HW) is a critical marker in Kafka, defining the offset position before which all messages are guaranteed to be committed and replicated to all in-sync replicas (ISRs). Thus, the HW represents the offset up to which messages are reliably stored and can be consumed.
Technical Explanation: The high watermark is maintained per partition and is the minimum LEO among all in-sync replicas for that partition. It ensures data consistency, as it guarantees that any message before the HW is available on all replicas and can be safely read by consumers. The HW is updated frequently as followers acknowledge replication of new messages to the leader.
Example: Continuing from the previous scenario, once all three brokers (assuming all are in-sync replicas) have received and stored the message at offset 10, the HW can be moved to 11. This update allows consumers to read up to offset 10 (inclusive) confident in the data’s integrity and availability.
Comparative Overview
To visualize the differences between LEO and HW within a Kafka system, the following table can be helpful:
| Concept | Definition | Usage | Dependent on | Example |
| Log End Offset (LEO) | Offset where the next new message will be appended. | Data writing by Producers | Local broker's state | New message to be appended at LEO = 11 |
| High Watermark (HW) | Maximum offset consumers can reliably read. All messages before are replicated to ISRs. | Data reading by Consumers | Acknowledgment and replication among all ISRs | Consumers can read up to HW = 10 (0 to 10 inclusive) |
Additional Considerations
- Impact on Consumers: Consumers are directly affected by the HW, as it limits the visibility of the messages they can see and ensure data consistency in the event of a broker failure.
- Producer Acknowledgment: Producers can control their write acknowledgment settings, choosing to wait until messages are acknowledged by all ISRs before considering a write successful ("all"), only by the leader ("leader"), or none at all, impacting LEO and HW.
- Broker Configuration: Kafka’s configuration parameters such as
min.insync.replicasandacksgreatly influence how HW and LEO are managed, affecting data durability and availability.
Conclusion
Understanding the distinctions between LEO and HW is crucial for effectively managing Kafka’s data consistency and reliability. Developers and system architects must comprehend these concepts to design robust streaming applications that meet stringent data integrity and availability requirements.

