Hybrid Logical Clock (HLC)
An HLC timestamp is a pair (l, c), computed from pt, the node’s physical clock reading (typically NTP-synced): l is the maximum physical time learned so far (either the node’s own pt or a value received from a peer), and c is a counter used to disambiguate events that share the same l. On every local event, a node computes l' = max(pt, l); if l' == l, the counter increments (c + 1), otherwise it resets to zero. On message receipt, the node computes l' = max(l, l_m, pt), where l_m and c_m come from the message: if l' == l == l_m, c = max(c, c_m) + 1; else if l' == l, c = c + 1; else if l' == l_m, c = c_m + 1; else c = 0. These rules carry causality across the cluster. Structurally it is a Lamport clock, except that the logical component stays anchored to real time instead of drifting arbitrarily far from it.
The guarantee that matters is that l never diverges from true physical time by more than the maximum clock skew (ε), i.e. l - pt is bounded by ε, assuming clocks stay within NTP/PTP bounds. That bound is why systems such as CockroachDB use HLC timestamps as MVCC versions, and MongoDB tracks a cluster-wide logical time (cluster time) for causally consistent sessions. HLC preserves causality, and real systems add mechanisms such as uncertainty intervals and read restarts to handle clock skew when reading, without requiring a round-trip to a centralised sequencer (as TrueTime-style approaches need, albeit with tighter bounds via atomic clocks/GPS).
- Clock skew bound violation: if NTP fails without raising an alarm and a node’s physical clock drifts beyond the configured
max_offset, the causality guarantees break with no warning, and writes can be misordered relative to reads on other nodes. CockroachDB nodes self-terminate when their clock offset from at least half of the other nodes exceeds 80% of the configured--max-offset, trading availability for correctness. Check your own system’s documented behaviour before relying on a similar safeguard. - Counter growth: under high skew or bursty traffic, the counter
ccan grow large beforeptcatches up, since every merge with a peer whoselalready exceeds localptforces counter-only increments. The original HLC analysis boundsconly under assumptions about clock skew and message rates, so size the counter field with headroom; the backlog clears only as physical time advances. - Not a substitute for consensus: HLC timestamps respect happens-before (if a happens-before b, then ts(a) < ts(b)), and can be totally ordered by adding a node-id tiebreak, but that order is not real-time linearizable. Two nodes can generate HLC timestamps that are close but whose real-world order is ambiguous, which is fine for MVCC snapshot isolation but insufficient for strict serializability without an additional protocol (e.g., commit-wait in Spanner).
System designers like HLC because it is a local computation that needs only per-node state, with no coordinator and no consensus round. It also degrades gracefully to plain physical time when clocks are well synchronised, keeping timestamps human-interpretable for debugging and TTL/GC logic (unlike pure Lamport clocks, which are causally correct but physically meaningless). The price is that HLC correctness depends entirely on your NTP/PTP infrastructure’s SLA, so watching clock synchronisation (drift metrics, leap-second handling) is a core operational job, not an afterthought.
Related reading
About this page
Credited to
Dates
Published
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.