What is Spanner's TrueTime and how does it enable external consistency?

Answer

TrueTime is Google's globally synchronized clock API used internally in Cloud Spanner to achieve external consistency (the strongest consistency guarantee — stronger than linearizability). TrueTime exposes the current time as an interval [earliest, latest] with a known error bound (typically under 7ms), based on GPS and atomic clocks in every Google data center. Spanner uses this to implement commit wait: before committing a transaction, the database waits until the commit timestamp is safely in the past (beyond TrueTime's uncertainty). This guarantees that any subsequent read on any replica will see the committed data. External consistency means: if transaction T2 starts after T1 commits (in real-world time), T2 always sees T1's writes — even across continents. This eliminates the need for distributed coordination protocols like 2PC for certain operations and is what enables Spanner's globally-consistent, serializable transactions.