The goal
Logical clocks order events but drift far from wall clock time, so timestamps look meaningless to humans. Physical clocks read like real time but skew between machines breaks causal order. A hybrid logical clock gives a single timestamp that stays close to physical time and respects causality.
The two part timestamp
An HLC timestamp has a physical part l and a small logical counter c.
- On a local event, set l to the max of the previous l and the current physical clock. If l did not advance, increment c, else reset c to zero.
- On receiving a message with timestamp l prime and c prime, set l to the max of the local l, l prime, and the physical clock, then adjust c so the new timestamp dominates both inputs.
The counter c absorbs cases where physical time did not move forward, keeping timestamps monotonic and causal.
Why it matters
- HLC stays within a bounded distance of physical time, so timestamps remain meaningful.
- It guarantees that if event A causes B then the timestamp of A is less than that of B.
- It needs only a few extra bits versus a raw physical timestamp.
Key idea
Hybrid logical clocks merge a physical time component with a bounded logical counter so timestamps track real time yet still encode causality.