How it works · 46 of 49 Advanced
How does Google Spanner use TrueTime clocks?
Clocks with error bars
Google Spanner: A database copied across datacentres must agree on the order of writes, but every machine's clock is a little off. Spanner's answer, TrueTime, does not pretend: asked the time, it returns an interval, earliest to latest, guaranteed to hold the true time. GPS receivers and atomic clocks in every datacentre keep that interval small, usually 1 to 7 ms. A write takes the latest end as its timestamp, then waits until the earliest end has passed it (commit wait, about twice the error) before anyone may see it. Any later write then gets a later timestamp, wherever on Earth it happens.
Loading the animation…
Say it like this Spanner's TrueTime admits each clock's error as an interval and makes every write wait until its timestamp has surely passed, about twice the error, so a write that starts later always gets a later timestamp anywhere in the world.
Under the hood — for builders
- The source, in its words
- Corbett, Dean et al., OSDI 2012: "The API directly exposes clock uncertainty, and the guarantees on Spanner's timestamps depend on the bounds that the implementation provides. If the uncertainty is large, Spanner slows down to wait out that uncertainty."
- Terms
- TT.now(): returns an interval [earliest, latest] "guaranteed to contain the absolute time". ε: half the interval's width, the error bound. Commit wait: hold a write's result until its timestamp has surely passed. External consistency: if write 1 finishes before write 2 starts, write 1's timestamp is smaller.
- Why the error is 1 to 7 ms
- Time masters in every datacenter (GPS, plus "Armageddon masters" with atomic clocks); a daemon on each machine polls them every 30 s and assumes 200 µs/s drift in between. So ε "is typically a sawtooth … from about 1 to 7 ms"; "ε̄ is therefore 4 ms".
- Run here: does a later write get a later stamp?
- 3 datacenters, each clock's ε on that sawtooth, its true offset anywhere within ±ε. 10,000 pairs: write 2 starts in another datacenter 0–5 ms after write 1 is visible. Rates are ours.
- Who used it first
- "Our initial customer was F1 … a rewrite of Google's advertising backend. F1 uses five replicas spread across the United States." Commit wait "is typically overlapped with Paxos communication".
- Measure it
- ε at the 90th, 99th, 99.9th percentile (the paper's Figure 6) · commit-wait time per write · masters unavailable, and how far ε jumps.
- Watch out
- The guarantee is only as good as ε: the paper saw ε rise for an hour when two time masters were shut down. Without such clocks, use a single ordering point or accept weaker order. Peer-reviewed, but by Google's own engineers.
- Sources
- James C. Corbett, Jeffrey Dean et al., "Spanner: Google's Globally-Distributed Database", OSDI 2012, read in session · clock-order simulation, Python, 19 Nov 2026.
What happens in the Google Spanner animation, step by step?
- Every clock is a little off. Stamp writes with plain clocks, and a later write in Asia can get an earlier stamp than one in the Americas.
- TrueTime returns an interval, earliest to latest, that holds the true time. GPS and atomic clocks at every site keep it about 1 to 7 ms wide.
- Your turn: the error is about 4 ms either way. How long does a write wait before anyone may see it?
- Commit wait: the stamp is the band's latest end, and the write waits until even the earliest end has passed it. About twice the error: 8 ms.
- Write 2 starts later, in Asia. Its stamp is past the true time, which is already past stamp 1: a later write gets a later stamp, on any continent.
- Worse clocks mean a wider band and a longer wait, never a wrong order. Next: Prime Video.
What everyday example explains Google Spanner?
Agreeing on time when every watch is a little off: you say "between 10:00:02 and 10:00:08" and wait until 10:00:08 has surely passed before you shout "done".
Why should a team care about Google Spanner?
Most databases spread across continents either give up a single order of writes or route every write through one place. Spanner pays a few milliseconds per write instead, and the cost is visible: better clocks, shorter waits.