CockroachDB was explicitly designed, per its own creators' stated goal, as an open-source system inspired by Spanner (9.1) — but without Google's atomic-clock/GPS hardware. This article covers exactly how it gets a workable substitute: hybrid logical clocks, combining article 2.1's physical time with article 2.2's Lamport-clock causality tracking, and uncertainty intervals derived from ordinary NTP-synchronized clocks rather than specialized hardware. It also covers Multi-Raft — Raft (5.5-5.6), one instance per data range, run at a scale of potentially millions of ranges across a cluster — the sharding pattern this series flagged in article 9.1 as the genuinely hard multi-shard problem, now shown concretely with Raft instead of Spanner's Multi-Paxos.
Hybrid logical clocks: physical time plus causality
Recall article 2.2's Lamport clocks: a purely logical counter that captures causal ("happened-before") order perfectly, but carries no relationship to real wall-clock time at all — useless for a human or a client wanting to know roughly when something happened. Recall article 2.1's physical clocks: real wall-clock time, but unreliable for ordering because of drift and synchronization limits. A Hybrid Logical Clock (HLC) combines both: each timestamp carries a physical-time component (kept close to real wall-clock time, periodically corrected) and a logical counter component (incremented, Lamport-clock-style, whenever causality demands it — e.g., when a received message's timestamp is ahead of the local physical clock). This gives CockroachDB timestamps that are simultaneously close to real time (useful, human-interpretable) and guaranteed to respect causal order (correct, per article 2.2's core guarantee) — a genuinely elegant synthesis of two mechanisms this series covered four phases apart.
Fig 1 — HLC timestamps carry both a real-time-anchored component and a Lamport-style causality-preserving counter.
Uncertainty intervals without atomic clocks
Without TrueTime's specialized hardware, CockroachDB can't get article 9.1's tight, hardware-backed bound on clock uncertainty — instead it derives a looser bound from configured maximum clock skew (a conservative estimate of how far apart any two nodes' NTP-synchronized clocks might legitimately be), and uses a mechanism directly analogous to Spanner's commit-wait, just with a wider window because the uncertainty itself is wider. When a transaction's timestamp falls within another transaction's uncertainty window, CockroachDB has to do extra work (a restart or an uncertainty-interval read-refresh) to resolve the ambiguity safely — the direct, real-world cost of not having TrueTime's tightly-bounded hardware guarantee, made concrete rather than abstract.
Multi-Raft: one Raft group per range, at massive scale
CockroachDB splits its keyspace into ranges (contiguous chunks of sorted key space, roughly analogous to Spanner's shards), each independently replicated by its own Raft group (5.5-5.6). A large production cluster can have millions of ranges, meaning millions of concurrent Raft groups — a scale that directly motivates several of Phase 7's specialized optimizations (PigPaxos's gossip-relay fan-out fix, article 7.8, is directly relevant here: naively running millions of independent Raft groups each doing full leader-to-follower fan-out would be a genuine bottleneck at this scale). CockroachDB's specific engineering response includes batching heartbeats and other coordination traffic across co-located ranges sharing the same physical nodes, rather than treating each Raft group as fully independent for network-efficiency purposes — a practical, systems-engineering answer to exactly the fan-out cost article 7.8 named abstractly.
FAQ
Does CockroachDB provide the exact same consistency guarantee as Spanner?
Very close, by design intent — CockroachDB targets serializable isolation with strong consistency guarantees comparable to Spanner's, though the specific external-consistency guarantee (ordered with true wall-clock time, not just internally-agreed order) is more tightly and more cheaply achieved by Spanner's TrueTime than by CockroachDB's NTP-derived bounds, exactly per this article's core trade-off.
Why does having millions of Raft groups matter more than having one giant one?
Sharding this way lets different ranges have independent leaders spread across the cluster, distributing both the coordination load and the ability to serve geographically-local reads/writes per range — a direct, practical instance of this series' repeated point that a single, monolithic consensus group doesn't scale to the throughput and geographic-distribution demands of a planet-scale database.
Is HLC unique to CockroachDB?
No — Hybrid Logical Clocks are a general technique used across several distributed systems needing both causal correctness and human/real-time-useful timestamps; CockroachDB is simply one of the most prominent, well-documented production users of the technique, making it a good concrete reference point for this series.
Takeaways
- Hybrid Logical Clocks combine article 2.1's physical time (human-useful, but drifts) with article 2.2's Lamport-clock causality tracking (correct, but not real-time-meaningful) into one timestamp format.
- Without TrueTime's hardware, CockroachDB derives uncertainty intervals from configured NTP clock-skew bounds — wider than Spanner's, costing more frequent conflict-resolution overhead under contention.
- Multi-Raft shards the keyspace into potentially millions of independently-replicated ranges, each its own Raft group (5.5-5.6) — directly motivating Phase 7's fan-out optimizations (PigPaxos, 7.8) at this scale.
- Spanner and CockroachDB make genuinely different, honest infrastructure-cost-vs-uncertainty-window trade-offs — neither is simply superior, echoing this series' consistent refusal to present any variant as a free upgrade.
References & further reading
- CockroachDB documentation — Architecture Overview — Multi-Raft, ranges, and the HLC-based transaction model described directly.
- Kulkarni et al. — Logical Physical Clocks (HLC, 2014) — the primary Hybrid Logical Clock reference.
- cvam.sight — Consensus 9.1: Spanner and TrueTime — the hardware-backed alternative this article's uncertainty-interval approach substitutes for.
- cvam.sight — Consensus 7.8: Matchmaker Paxos, PigPaxos, BPaxos & Rabia — the fan-out cost Multi-Raft's scale directly motivates addressing.