tezvyn:

How Spanner achieves global external consistency

AI-drafted, machine-checkedSource: interviewintermediate
WHAT IT TESTS

understanding TrueTime and external consistency.

OUTLINE

TrueTime gives bounded-uncertainty clocks via GPS and atomic sources, Spanner commit-waits out that uncertainty, and Paxos replicates each shard.

WHAT THIS TESTS 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.

A GOOD ANSWER COVERS 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.

COMMON WRONG ANSWERS 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.

LIKELY FOLLOW-UPS 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.

ONE 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.

Read the original → docs.cloud.google.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.