NotesSystem
Spanner
Also: Google Spanner · Cloud Spanner
Google's globally distributed SQL database. Its defining choice is TrueTime: clocks with an explicit, small error bound, waited out at commit so that transaction timestamps match real-time order across the planet.
Design choices
- TrueTime: GPS and atomic-clock time masters in every data centre;
TT.now()returns [earliest, latest]. ε was 1–7 ms (≈4 ms average) in 2012. - Commit wait: a read-write transaction's timestamp is TT.now().latest; the leader waits ≈ 2ε until that time has certainly passed before anyone can see the result. That gives external consistency: if T1 commits before T2 starts, T1's timestamp is smaller.
- Replication: each shard (split) is a Paxos group with a leader; commit wait overlaps Paxos replication.
- Transactions: read-write transactions use Two-Phase Locking at leaders and Two-Phase Commit across Paxos groups.
- Reads: MVCC versions stamped with TrueTime let read-only transactions and snapshot reads run lock-free at a timestamp on any sufficiently up-to-date replica.
Notable trade-offs
- Every read-write transaction pays commit wait; latency depends on the time infrastructure keeping ε small, and ε spikes when time masters fail.
- Cross-region writes pay Paxos round trips; strong guarantees cost latency, not correctness.
- Systems without atomic clocks (CockroachDB, YugabyteDB) approximate it with Hybrid Logical Clocks and read restarts; CockroachDB gives up linearizability for transactions on unrelated keys.