Introduction
In our recent lessons, we have assembled the core components of a globally distributed, strongly consistent database. We began with Paxos for fault-tolerant replication within a shard, followed by two-phase commit (2PC) for atomic commitment across shards, and most recently, two-phase locking (2PL) for serializable isolation within each shard. We saw how Spanner combines these into a 2PC+2PL over Paxos leaders architecture. However, a crucial question remains: how do we order transactions that occur across different shards, potentially in different datacenters, in a way that respects real-world time?
This lesson addresses that question by introducing the final, and perhaps most innovative, component of Spanner's design: TrueTime. We will explore why traditional physical and logical clocks are insufficient for guaranteeing the strongest level of consistency, known as external consistency or strict serializability. You will learn how TrueTime's novel API, which explicitly models clock uncertainty, enables Spanner to assign globally meaningful timestamps. The central learning outcome is to explain the role of this high-precision clock source and its associated "commit wait" protocol in enabling externally consistent transactions, a feat that distinguishes Spanner from most other distributed databases.
The Challenge of Time and Causality
In a distributed system, achieving a consistent view of data is fundamentally a problem of ordering. For transactions, serializability ensures that there exists some serial order equivalent to the concurrent execution. However, it doesn't say that this order must match the real-world, wall-clock order of events.
External consistency (also called linearizability or strict serializability) is a much stronger guarantee. It requires that if transaction T1 commits before transaction T2 begins, then the serial order must place T1 before T2.
This seems simple, but it's incredibly difficult to achieve in a global system. Consider two transactions, T1 and T2, handled by different servers, potentially thousands of miles apart. A user's application observes that T1 has completed, and based on that result, initiates T2. This establishes a clear causal link: T1 happens-before T2. The problem arises from clock skew. If the server for T2 has a clock that is running slightly behind the server for T1, it might assign T2 a commit timestamp that is earlier than T1's timestamp.

You might think that logical clocks, like Lamport clocks, would solve this. However, they only track causality that is passed through direct messages within the system. They cannot capture "out-of-band" causality, such as the user in our example who connects the two transactions.
The following video from Martin Kleppmann provides an excellent explanation of why both standard physical clocks and Lamport logical clocks are insufficient for this task.
Distributed Systems 8.2: Google's Spanner
This excerpt from a lecture on distributed systems clearly articulates the problem of generating causally consistent timestamps at global scale.
Watch the section from "this works..." which explains why timestamps must be causally consistent and then demonstrates, with a concrete user-in-the-loop example, why Lamport clocks fail to capture all causal dependencies.
TrueTime: A Clock API with Bounded Uncertainty
Google's solution to this problem is not a perfectly synchronized clock, but rather a service and API called TrueTime that acknowledges and quantifies clock uncertainty. This is the conceptual breakthrough. Instead of pretending clocks are perfect, TrueTime provides a guarantee about their maximum error.
The core of the API is the TT.now() method. It does not return a single point in time. Instead, it returns an interval: [earliest, latest]. TrueTime guarantees that the absolute, real-world time of the TT.now() invocation lies somewhere within this interval. The width of this interval, latest - earliest, represents the clock uncertainty, denoted as .
To provide these guarantees, TrueTime is implemented as a robust, redundant service.

The uncertainty is derived from two main sources:
- The communication delay when a node contacts the time masters.
- The worst-case clock drift of the local quartz crystal clock on the server since its last synchronization. Servers sync with masters roughly every 30 seconds, causing to follow a "sawtooth" pattern, typically varying between 1ms and 7ms.
The seminal Spanner paper provides the definitive description of this system.
Spanner: Google's Globally-Distributed Database
Reading the original paper is essential for a Principal-level understanding. This section details the TrueTime API and its implementation.
Please read Section 3, titled "TrueTime" (pp. 5-6). Focus on understanding the API contract of TT.now(), the implementation using time masters and daemons, and how the uncertainty \epsilon is derived.
Achieving External Consistency with Commit Wait
Now we have an API that gives us a time interval [earliest, latest]. How does Spanner use this to assign timestamps that respect external consistency? The solution lies in a two-part protocol for assigning a commit timestamp, s, to a transaction T.
-
Timestamp Assignment (The "Start" Rule): When a transaction is ready to commit, the coordinator leader assigns it a commit timestamp by choosing . This chooses a time that is guaranteed to be at or after the real moment the timestamp was chosen.
-
Commit Wait Rule: After assigning the timestamp , the coordinator does not immediately make the transaction's writes visible. Instead, it waits until
TT.now().earliestis greater than . This step is the "commit wait."
Let's see why this works. The commit wait forces the system to pause until the real, absolute time has definitively passed the chosen commit timestamp . This ensures , where is the absolute time when T's commit becomes visible to other transactions.
Now consider our original scenario: T1 commits, and then a client observes this and starts T2.
- T1 gets timestamp and enters commit wait. It becomes visible only after absolute time has passed .
- T2 starts after T1 is visible. The absolute time of T2's start, , is therefore greater than .
- When T2 commits, it gets timestamp . This value is guaranteed to be greater than or equal to the absolute time when the timestamp was chosen, which is after T2 started. So, .
- By transitivity, we have , which gives us the required property: . External consistency is preserved.
This mechanism of using an uncertainty interval and enforcing a wait is the linchpin of Spanner's consistency model. The following video segment from one of the Spanner paper's authors provides an excellent visual explanation of this process.
Wilson Hsieh - Spanner: Google's Globally-Distributed Database - OSDI 2012
This presentation from the OSDI '12 conference, where the Spanner paper was published, explains the core mechanism.
Watch the segment from "across machines". Pay close attention to the visual depiction of how the timestamp s is chosen from the TrueTime interval and the crucial "commit wait" step that follows.
Performance Implications
A mandatory "wait" in a commit protocol sounds like a performance killer. However, its impact is carefully managed.
First, the uncertainty is kept very small—typically just a few milliseconds. The cost of the commit wait is on the order of , which amounts to less than 10ms in the common case.
Second, and more importantly from a system design perspective, the commit wait can be overlapped with other work. When a transaction commits, the coordinator leader must replicate the commit decision to the other replicas in its Paxos group. This replication involves network round-trips. Spanner initiates the Paxos replication in parallel with the commit wait. For a globally replicated system where network latency to other datacenters can be 100ms or more, the small commit wait is often entirely hidden by the much larger replication latency.
Wilson Hsieh - Spanner: Google's Globally-Distributed Database - OSDI 2012
Continuing with the OSDI '12 presentation, this part explains how the commit wait is made practical.
Watch the next section from "commit weight interacts". This demonstrates how the commit wait is overlapped with Paxos replication and 2PC, minimizing its impact on perceived latency. This is a critical design detail for building high-performance, strongly-consistent systems.
By keeping clock uncertainty low and overlapping the wait with existing network latency, Spanner provides external consistency without a significant performance penalty compared to systems with weaker guarantees.
Conclusion
In this lesson, we have uncovered the mechanism that allows Spanner to provide its strongest and most famous guarantee: external consistency. We saw that naive use of physical or logical clocks is insufficient to preserve causal orderings that happen outside the database system itself.
The key takeaways are:
- External consistency requires that the transaction serialization order respects the real-world (wall-clock) order of non-overlapping transactions.
- TrueTime is a clock API that solves this problem not by providing a perfect clock, but by exposing a bounded uncertainty interval
[earliest, latest]. - Spanner uses a two-part protocol: it assigns a commit timestamp from the future-most end of the interval () and then enforces a commit wait until the present-most end of a new interval has passed that timestamp ().
- This "commit wait" ensures that the absolute time advances past a transaction's commit timestamp before its effects are made visible, guaranteeing that commit timestamps correctly reflect the flow of real-world time.
- The performance overhead of the wait is minimized by keeping clock uncertainty low (via GPS and atomic clocks) and by overlapping the wait with the unavoidable network latency of replication protocols like Paxos.
We have now examined 2PC, 2PL, Paxos, and TrueTime in relative isolation. In our next lesson, we will synthesize this knowledge to analyze how Spanner implements a globally distributed read-write transaction from start to finish, seeing how all these components work together in concert.