Hybrid Logical Clocks (HLC) give distributed databases 64-bit, NTP-compatible timestamps that stay within clock error epsilon of physical wall time while preserving Lamport’s happened-before causality without blocking writes. In their 2014 technical report, Sandeep Kulkarni, Murat Demirbas, Deepak Madeppa, Bharadwaj Avva, and Marcelo Leone bridged logical clocks (which cannot answer wall-time queries) and physical NTP clocks (whose 1 to 100 ms skews and backward jumps invert cause and effect).
Two years earlier, Google Spanner had achieved global snapshot reads using GPS antennas, atomic clocks, and a 2 * epsilon commit-wait delay per write. HLC showed how commodity cloud clusters running standard NTP can support wait-free consistent snapshots by pairing a bounded wall-time tracker l with a tiny causal counter c, a pattern now standard in CockroachDB and YugabyteDB.
- One-way causality in
O(1)space: For any eventseandf,e hb fimplies(l.e, c.e) < (l.f, c.f)using two integers instead ofO(N)vector clocks, whilel.f >= pt.falways holds (Theorems 1 and 2). - Bounded drift and counter size: Separating
l(maxptseen) fromc(same-ltie-breaker) bounds drift to|l.f - pt.f| <= epsilon(Corollary 1) and counters toc.f <= N * (epsilon + 1)(Corollary 3). - Drop-in 64-bit NTP layout: Ceiling-rounding
ptto the top 48 bits (microsecond resolution) leaves 16 bits forc(up to 65,536), reading NTP passively via superposition without modifying host clocks. - Tiny counters in AWS clusters: Across 4 to 16
m1.xlargenodes sending 75,000 to 425,000 wire-speed messages,c = 0held for 65.56% to 95% of events (maxc = 8on 16 nodes; maxl - pt = 0.02 msacross four WAN regions).
Why the single-scalar naive algorithm drifts forever
Kulkarni and colleagues formalize the HLC problem with four strict requirements (Section 3.1): assign every event e a timestamp such that (1) e hb f implies l.e < l.f, (2) space is O(1) integers updated in O(1) operations, (3) representation space stays bounded (ideally 64 bits), and (4) |l.e - pt.e| remains bounded close to physical time pt.
The most tempting design uses a single integer l.j initialized to 0 and combines Lamport’s rules with max(..., pt.j):
- On a send or local event:
l.j := max(l.j + 1, pt.j) - On receiving message
m:l.j := max(l.j + 1, l.m + 1, pt.j)
That naive algorithm satisfies requirements 1 and 2, then breaks requirements 3 and 4 immediately. In the paper’s Figure 4 counterexample, node 0 seeds a higher physical clock (10) into a tight messaging loop among nodes 1, 2, and 3 whose physical clocks sit at 0, 1, 2, ... and tick slower than message hops. Each hop forces +1 (11, 12, 13, 14, ...), driving |l - pt| upward without bound even if every node’s physical clock increments between local events.
The root cause is subtle: storing both the maximum physical clock seen so far and per-event +1 increments in one variable erases provenance. Once l hits 15, a node cannot tell whether 15 came from a real pt = 15 somewhere in the cluster or from five fast causal hops starting at pt = 10, so there is never a safe place to reset l without risking a violation of e hb f => l.e < l.f.
HLC solves this with one level of indirection, splitting the timestamp into (l.j, c.j) (Figure 5):
l.jtracks only the highest physical time seen so far: On local or send events,l.j := max(l0.j, pt.j)(dropping+ 1). On receive,l.j := max(l0.j, l.m, pt.j). By induction (Theorems 2 and 3),l.f >= pt.falways holds, and wheneverl.f > pt.f, some causal ancestorg hb factually hadpt.g = l.f. Under bounded NTP skew|pt.g - pt.f| <= epsilon, Corollary 1 guarantees|l.f - pt.f| <= epsilon.c.jbreaks ties strictly whenlcannot advance: On local or send events, ifl.j = l0.j, incrementc.j := c.j + 1; otherwise resetc.j := 0. On receive, ifl.j = l0.j = l.m, setc.j := max(c.j, c.m) + 1; ifl.j = l0.j, setc.j := c.j + 1; ifl.j = l.m, setc.j := c.m + 1; otherwisept.jmoved strictly ahead, so resetc.j := 0.
Replaying the Figure 4 loop under HLC (Figure 6) shows why drift stops cold: nodes 1, 2, and 3 stamp messages (10, 0), (10, 1), (10, 2) while l stays pinned at 10. As soon as any node’s pt advances past 10, l jumps to pt and c resets to 0. Even without assuming slow message rates, Corollary 3 bounds c.f <= N * (epsilon + 1) across N nodes, and if a message hop always spans at least d physical ticks, Corollary 4 shrinks that worst-case bound to epsilon / d + 1.
Consistent snapshots, 64-bit packing, and NTP resilience
Separating l from c turns HLC into a direct substitute for both Chandy-Lamport snapshots and TrueTime read timestamps, without special hardware or write pauses.
To take a consistent snapshot read at physical time t (Section 6.1, Figure 12), HLC uses virtual dummy events: between any two consecutive real events e and f on a node with l.e < l.f, conceptually fill in internal dummy states (t', c = 0) for every t' in [l.e + 1, l.f]. Now every node is guaranteed to have a state at (l = t, c = 0). Because (l.e, c.e) = (l.f, c.f) implies e || f (no causal path can share identical HLC pairs under Theorem 1), reading every node at (l = t, c = 0) yields a causally consistent global cut whose events all occurred within [t - epsilon, t]. Unlike Chandy-Lamport, no marker wave has to traverse the cluster at query time; unlike Spanner’s commit-wait, writes never stall waiting out [earliest, latest].
For backwards compatibility with existing storage formats, Section 6.2 packs (l, c) into a single 64-bit NTP timestamp. Standard NTP uses 32 bits for seconds (rolling over every 136 years) and 32 bits for fractional seconds (~233 picoseconds resolution). HLC rounds pt up via ceiling to the top 48 bits for l (preserving microsecond granularity) and devotes the bottom 16 bits to c (allowing c up to 65,535). Crucially, HLC operates as a superposition on NTP: it reads the OS clock without ever slewing or stepping it, avoiding Fan and Lynch’s impossibility trap where peer clock adjustments cause global drift away from real time.
Across live Amazon AWS runs on m1.xlarge nodes synced to 0.ubuntu.pool.ntp.org (75,000 to 425,000 wire-speed TCP messages), c and l - pt stayed far below theoretical bounds. On 4 nodes, c never exceeded 3 (83.90% at c = 0 under 5 ms NTP offset). On 8 nodes, tightening NTP sync from 9 ms to 3 ms lifted c = 0 from 65.56% to 91.18% and cut max l - pt from 107.9 ms to 7.4 ms (90th percentile falling from 41.4 ms to 0.1 ms). On 16 nodes at 6 ms offset, c peaked at 8 (75.43% at 0, max l - pt 46.8 ms, mean 0.3 ms). Across four WAN regions (Ireland, US East, US West, Tokyo) at 3 ms offset, transit time exceeded clock skew so incoming timestamps trailed local pt: 95% of events had c = 0, 5% had c = 1, and max l - pt was 0.02 ms.
Trace five timing scenarios through HLC
Burst traffic, lagging stragglers, and snapshot reads each hit a different branch of Figure 5’s rules. Switch through the tabs below to compare naive clocks, HLC behavior, and measured bounds.
Select a scenario (or use Left and Right arrow keys) to compare naive behavior, HLC's update rule, and empirical bounds.
Burst of local or send events within one clock tick
Local & sendA node generates multiple events faster than 48-bit physical time advances (or while NTP steps backward).
- Why naive fix breaks
- Raw physical time assigns identical or decreasing timestamps, violating causality; naive scalar l := max(l+1, pt) leaks permanent drift into l.
- HLC's mechanism
- l.j stays equal to l0.j = max(l0.j, pt.j), while c.j increments by 1; as soon as pt.j advances past l.j, c.j resets to 0.
- Bit budget
- 48-bit ceiling rounding tracks microseconds; the remaining 16 bits allow up to 65,536 causal events per microsecond before overflow.
- AWS cluster rate
- In 4-node single-AZ wire-speed runs, c = 0 accounted for 83.66% to 83.90% of events and c never exceeded 3.
Tight messaging loop after receiving a higher timestamp
Section 3.2Node 0 sends l = 10 to nodes 1, 2, and 3, which exchange messages faster than one physical clock tick per hop.
- Why naive fix breaks
- Every receive executes max(l.j+1, l.m+1, pt.j), pushing l to 11, 12, 13 forever and growing |l - pt| without bound (Figure 4).
- HLC's mechanism
- Nodes hold l = 10 across hops and bump c from (10,0) to (10,1) and (10,2); once local pt ticks past 10, l updates to pt and c resets to 0 (Figure 6).
- Formal bound
- Even without message-delay assumptions, Corollary 1 bounds |l.f - pt.f| <= epsilon and Corollary 3 bounds c.f <= N * (epsilon + 1).
- 16-node AWS test
- Under 6 ms average NTP offset at wire speed, max l - pt stayed 46.8 ms (mean 0.3 ms) and c peaked at 8.
A lagging node whose NTP clock falls behind peers
Section 5.2One node loses NTP sync or drifts behind by epsilon or 5 * epsilon while receiving messages from up-to-date peers.
- Why naive fix breaks
- Under pure physical time or LWW (like raw Cassandra), writes from the lagging straggler get stale timestamps and silently lose conflicts.
- HLC's mechanism
- The straggler adopts higher l.m values from incoming peer messages and increments its own c when l stays stuck, without inflating peers' c.
- Simulation result
- At 1 event/ms with 0 delivery delay, a straggler at epsilon hit max c = 97 and at 5*epsilon hit c = 514 locally, while 99% of cluster events stayed c <= 4.
- Why peers stay clean
- Healthy receivers already have newer local pt, so receiving a straggler's high-c message updates l to pt and immediately resets c := 0.
A fast or corrupted node running ahead of wall time
Section 4.1A node's clock runs ahead by up to 5 * epsilon, or suffers transient corruption emitting a wildly futuristic timestamp.
- Why naive fix breaks
- Blindly trusting every incoming timestamp lets one corrupt machine drag the entire cluster's logical clock years into the future.
- HLC's mechanism
- Normal skew up to 5 * epsilon is masked within tolerance Delta (max c = 8 in sim, under 1% > 3); messages past l - pt > Delta are ignored and logged.
- Self-stabilization
- If local state violates Theorem 2 or Corollary bounds, the node resets l := pt and c := 0, recovering as soon as NTP stabilizes.
- Practical tuning
- Setting Delta to a conservative constant multiple of epsilon (or seconds) masks 99.9% of ordinary NTP kinks without false drops.
Wait-free consistent global read at physical time t
Section 6.1A database client queries a multiversion store for a globally consistent view near wall time t without pausing writers.
- Why naive fix breaks
- Reading every node at pt = t misses causal pairs across skew windows (Figure 2); Spanner TrueTime avoids this only by delaying commits for 2 * epsilon.
- HLC's mechanism
- Virtual dummy events guarantee (l = t, c = 0) exists on every node; because equal HLC timestamps are concurrent, reading at (t, 0) yields a consistent cut.
- Time window
- Theorem 3 and Corollary 2 guarantee the returned snapshot reflects real execution within the global window [t - epsilon, t].
- External consistency
- HLC does not block writes; Section 6.3 notes strict serializability can still be added via client-notification-wait after a transaction finishes.
If you skip clicking through the tabs, here is how HLC handles all five scenarios:
- Same-tick bursts:
lholds atmax(l0, pt)whileccounts causal steps (up to 65,536 per microsecond in 16 bits) untilptticks forward and resetsc = 0. - Fast messaging loops: holding
lconstant while incrementingckeeps|l - pt| <= epsilon, avoiding the unbounded runaway drift of single-scalar hybrids. - Stragglers: a lagging node borrows current
lfrom peers and absorbs elevatedclocally (up to514at5 * epsilonlag) without infecting healthy nodes. - Rushers and corruptions: a tolerance bound
Deltamasks normal NTP jitter (c <= 8in 5x rusher sims) while rejecting out-of-bounds timestamps and resetting corrupted state to(pt, 0). - Consistent snapshots: reading every shard at
(l = t, c = 0)returns a causally consistent cut in[t - epsilon, t]with zero write-side commit-wait.
Caveats and production tradeoffs
Three caveats define what HLC solves and what distributed engineers still have to handle separately.
First, HLC provides one-way causality, not concurrency detection or strict serializability. As with Lamport clocks, (l.e, c.e) < (l.f, c.f) never implies e hb f, so conflict detection still needs vector clocks or Dynamo-style version vectors. Skipping commit-wait also means out-of-band external callers across lagging nodes can still violate real-time order unless databases add client-notification-wait or uncertainty read restarts.
Second, Delta tuning and 48+16-bit packing embed operational tradeoffs. Setting Delta too small turns routine 100 ms+ NTP glitches into dropped messages; setting it too wide lets a rusher pull cluster l ahead of wall time, widening [t - epsilon, t] snapshot staleness. Ceiling-rounding pt to 48 bits also assumes microsecond resolution suffices and 16-bit c (65,535) never overflows before pt advances.
Third, the 2014 benchmarks measured raw messaging, not transactional storage. The AWS runs tested 4 to 16 m1.xlarge nodes sending TCP messages alongside 1 event/ms simulations, leaving consensus queues and disk fsync tails to implementers. Even so, decoupling l from c gave distributed databases a durable, hardware-free 64-bit clock for consistent snapshots.


