A clock that looks like real time but keeps cause and effect in order, by mixing wall time with a counter.
A hybrid logical clock (HLC) is a timestamp made of two parts: a wall-clock time and a small counter. It looks like real time, so people can read it, but it also keeps cause before effect, like a Lamport clock.
An HLC timestamp is a pair (l, c). l is the largest wall-clock time this machine has seen so far (its own clock, or a time that arrived in a message). c is a counter that only matters when two events have the same l. Timestamps are compared like words in a dictionary: compare l first, and if equal, compare c.
The idea comes from a 2014 paper by Kulkarni, Demirbas and others. The key trick: never let l go backwards, even if the wall clock does. If the local clock says 100 but a message arrived stamped 130, the machine keeps 130 and raises the counter. Time then stays correct in order, and the l part never drifts far from real time (it is at most as far ahead as the fastest clock).
| When | New l | New c |
|---|---|---|
| Local event or send | max(old l, my wall clock) | If l did not change: c + 1. If l moved forward: 0 |
| Receive a message (l_m, c_m) | max(old l, l_m, my wall clock) | If the max is tied between values, take the largest tied c and add 1. If my wall clock alone is the max: 0 |
| Clock | Close to real time? | Cause before effect? | Needs special hardware? | Typical use |
|---|---|---|---|---|
| Wall clock + NTP | Yes, within ms | No | No | Logs, display, expiry |
| Lamport clock | No | Yes | No | Ordering, locks, terms |
| Vector clock | No | Yes, plus detects concurrent | No | Conflict detection (Dynamo-style) |
| Hybrid logical clock | Yes, within the clock error | Yes | No | Distributed SQL, snapshot reads |
| TrueTime | Yes, with a known bound | Yes, with commit wait | Yes, GPS and atomic | Spanner, strong global order |
Many systems squeeze both parts into a single 64-bit integer: the high bits hold physical time in milliseconds, and the low bits hold the counter. Because the high bits come first, sorting the plain integers gives the correct order, which is why HLCs fit easily in existing storage.
| Event | Real time | Its own wall clock | Lamport | HLC (l.c) |
|---|---|---|---|---|
| A does something | 1000 | 1000 | 1 | 1000.0 |
| A sends | 1010 | 1010 | 2 | 1010.0 |
| B receives | 1014 | 974 ✗ older than send | 3 | 1010.1 |
| B does something | 1020 | 980 | 4 | 1010.2 |
| B sends | 1030 | 990 | 5 | 1010.3 |
| C receives | 1034 | 1034 | 6 | 1034.0 |
| C sends | 1040 | 1040 | 7 | 1040.0 |
| A receives | 1044 | 1044 | 8 | 1044.0 |
Real time moves 10 ms per step and a message takes 4 ms. Server A has a perfect clock, B is slow and C is fast by the amounts you set. HLC is shown as l.c, where l is a time in ms and c is the counter that breaks ties. Real systems also reject a message whose time is far ahead of the local clock.
send: l2 = max(l, pt); c = (l2 == l) ? c + 1 : 0; l = l2 · receive: l2 = max(l, lm, pt); c = f(ties); l = l2| Term | Meaning in easy words |
|---|---|
| Hybrid logical clock | A timestamp of wall-clock time plus a counter |
| l (logical wall part) | The largest wall-clock time this node has seen, from its own clock or a message |
| c (counter) | A small number that breaks ties when l is the same |
| Physical time (pt) | What the machine's own clock says right now |
| Causality | If A could have caused B, A must be stamped before B |
| Max clock offset | The largest clock error the system accepts between nodes |
| Bounded drift | l never gets further from real time than the clock error |
| Lamport clock | A pure counter that respects cause but has no time |
| Snapshot read | Reading the data as it was at one timestamp |
| Resolved timestamp | A time T up to which all changes have been delivered |
| Uncertainty window | The range in which the true time may lie, because clocks are not exact |
| Choice | We gain | We lose |
|---|---|---|
| HLC instead of Lamport | Stamps that mean real time | A small bound check to maintain |
| HLC instead of TrueTime | Normal hardware, no commit wait | No external consistency without extra steps |
| HLC instead of vector clock | Constant size | No exact concurrency detection |
| A small max offset | Safer, tighter bounds | More messages rejected when clocks drift |
| Large counter field | Many events per millisecond | Fewer bits for time |