Solving the Global Clock Problem: How Spanner Uses TrueTime for External Consistency
Distributed clocks drift, leading to data inconsistency. Discover how Google Spanner uses TrueTime and 'commit wait' to achieve global external consistency.
15 Sept 2025, 06:00 UTC

The Problem: The Impossible Clock
In a globally distributed database, the biggest enemy is time. If a user in Tokyo updates a record and a user in New York reads it a millisecond later, the system must guarantee the New York user sees the update. However, in a distributed system, there is no such thing as a single "global clock." Hardware clocks on different servers drift at different rates, meaning Server A might think it is 10:00:00.001 while Server B thinks it is 09:59:59.998.
If you rely on these drifting clocks to timestamp transactions, you risk out-of-order writes. A transaction that happened logically later could be assigned an earlier timestamp, breaking external consistency (the guarantee that if transaction T2 starts after T1 completes, T2's timestamp is greater than T1's).
The TrueTime Approach
Google Spanner solves this by treating time not as a single point, but as an interval. Instead of returning a single value, the TrueTime API returns a range: [earliest, latest]. This interval represents the window of uncertainty—the maximum possible drift between the local clock and the actual absolute time.
TrueTime achieves this tight window by deploying specialized hardware—GPS receivers and atomic clocks—within Google's data centers. While standard NTP (Network Time Protocol) can have offsets of tens or hundreds of milliseconds, TrueTime keeps the uncertainty window significantly smaller.
The Commit Wait: Trading Latency for Consistency
To ensure linearizability (the strongest consistency model), Spanner uses a mechanism called Commit Wait. The logic is simple but strict: a transaction cannot be visible to clients until the system is absolutely certain that the current absolute time has passed the transaction's commit timestamp.
If a transaction is assigned a timestamp S, the server waits until TrueTime.now().earliest > S before releasing the commit. This ensures that any subsequent transaction will inevitably receive a timestamp greater than S, regardless of which data center it hits.
Practical Example: Read-Only Snapshots
One of the most powerful outcomes of this architecture is the ability to perform consistent, lock-free read-only transactions across the globe. Because every piece of data is versioned with a TrueTime timestamp, you can request a "snapshot read" at a specific time.
Consider a global inventory report: instead of locking every row in every region (which would crash performance), Spanner allows you to read data as it existed at timestamp T. Since the system knows exactly when T occurred relative to all other writes, it can serve the read from the nearest replica without communicating with the Paxos leader or acquiring locks.
Trade-offs and Limitations
The TrueTime model is not a silver bullet; it involves specific engineering costs:
- Latency Floor: Every write transaction is penalized by the commit wait. If the clock uncertainty window is 7ms, the minimum write latency is at least 7ms. If the hardware fails or drifts, latency increases.
- Hardware Dependency: This architecture is nearly impossible to replicate on commodity cloud hardware. Without atomic clocks and GPS, the uncertainty window would be too wide, making commit waits prohibitively slow.
- Single-Row Bottlenecks: While Spanner scales horizontally, a single row's write throughput is limited by the Paxos leader's capacity and the network round-trip time required for consensus.
Verifying Consistency
To verify that a Spanner instance is maintaining external consistency, engineers typically monitor the TrueTime uncertainty window. If the window expands beyond a specific threshold, the system may experience increased latency as the commit wait period lengthens to compensate for the drift. You can observe this behavior by comparing the timestamps of sequential writes across different geographic regions to ensure they are strictly monotonically increasing.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.