Skip to content
hashkey.bond

Archivedistributed-systems

Hybrid Logical Clocks Keep Causality and Wall Time

HLC timestamps stay close to physical time while never violating happens-before.

Published
Reading time
1 min read

Lamport clocks preserve causal order but drift arbitrarily far from wall time. Hybrid logical clocks (HLC) preserve causality and stay within a bounded distance of physical time, which makes them useful for MVCC and debugging.

The update rule

l' = max(l, pt, received_l)
if l' == l == received_l: l' = l + 1
timestamp = (l', node_id)

On send, attach the current (l, c). On receive, advance l to the max of local physical time, local logical time, and the incoming logical time. The counter c breaks ties and encodes events at the same physical millisecond.

Properties

  • e1 → e2 implies HLC(e1) < HLC(e2).
  • HLC(e) ≈ physical_time(e) within a bounded skew.
  • Totally ordered by (l, c, node_id).

Where it is used

CockroachDB uses HLC for transaction timestamps and detects clock skew against a max-offset budget; MongoDB uses a similar cluster time.

Takeaway: HLC gives you causally consistent, human-meaningful timestamps at low cost. It does not give you linearizability by itself.