How Spanner achieves global external consistency
understanding TrueTime and external consistency.
TrueTime gives bounded-uncertainty clocks via GPS and atomic sources, Spanner commit-waits out that uncertainty, and Paxos replicates each shard.
What's really being asked
This checks whether you understand the hard part of a globally distributed SQL database: ordering transactions consistently across regions despite clock skew, and the specific mechanism Spanner uses.
The full answer
TrueTime is Spanner's clock API. Instead of a single timestamp, it returns an interval with an explicit uncertainty bound, guaranteeing the true time lies within that window. It is backed by redundant GPS receivers and atomic clocks in every datacenter, keeping the uncertainty small, typically single-digit milliseconds. When Spanner commits a write transaction, it picks a commit timestamp and then performs a commit-wait: it deliberately waits until TrueTime guarantees the chosen timestamp is now in the past everywhere. This ensures that if transaction T1 commits before T2 begins, T1's timestamp is strictly smaller, which delivers external consistency, the strongest form, equivalent to a single global serial order. Each data shard is replicated across zones using Paxos, so a majority of replicas agree on each write, providing fault tolerance and consistent reads.
The mistakes people make
Saying ordinary NTP clocks are enough; they have unbounded skew and no uncertainty guarantee. Confusing external consistency with eventual consistency. Forgetting the commit-wait step, which is what actually converts bounded uncertainty into a correct ordering.
What usually comes next
What does commit-wait cost in latency. How does Paxos fit in. What is the difference between external and strict serializability. What happens if TrueTime uncertainty grows.
A concrete example
Two transactions on accounts in different continents must be globally ordered. Spanner stamps the first commit, waits out the few milliseconds of TrueTime uncertainty, then acknowledges. The second transaction, starting afterward, is guaranteed a later timestamp, so a reader anywhere sees them in the correct order.
Interview question
Why must Spanner perform a 'commit-wait' after choosing a transaction's commit timestamp?
- a.To batch multiple commits together and reduce Paxos overhead
- b.To wait out TrueTime's clock uncertainty so later transactions get strictly greater timestampsCorrect
- c.To synchronize all servers to a single NTP source before committing
- d.To allow read replicas to catch up before the write is visible
Why? this is the answer
Commit-wait pauses until TrueTime guarantees the timestamp is safely in the past, ensuring a global ordering and external consistency. It is not about replica lag or NTP synchronization.
Just read this? Test yourself on what you have been reading.
Read the original → docs.cloud.google.com
- #spanner
- #truetime
- #external-consistency
- #distributed-databases
- #paxos
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles