Notesdistributed🌱 seedling
TrueTime
Also: TrueTime API · Commit Wait · External Consistency · ClockBound · Bounded Clock Uncertainty
A clock API that returns an interval [earliest, latest] guaranteed to contain true time. By waiting out the interval's width at commit, a database makes timestamp order match real-time order everywhere.
Why it exists
Wall-clock timestamps are wrong by an unknown amount, so two transactions can get timestamps in the wrong real-time order. Making the error known and small lets you correct for it.
How it works
- Reference clocks: GPS receivers plus atomic clocks per data centre (different failure modes). Machines poll several masters and reject outliers (Marzullo's algorithm).
- Uncertainty ε grows between polls at an assumed worst-case drift (200 µs/s in Spanner) and shrinks at each sync.
- Commit: pick s = TT.now().latest, then commit-wait until TT.now().earliest > s (≈ 2ε) before making the transaction visible.
- Guarantee (external consistency): if T1 commits before T2 starts in real time, s1 < s2, with no communication between them. Snapshot reads at a timestamp can then be served lock-free from any up-to-date replica.
Trade-offs
| Gains | Costs |
|---|---|
| real-time ordering across the globe | every read-write transaction waits ≈ 2ε |
| lock-free consistent snapshot reads | special time infrastructure; ε spikes when time masters fail |
| catches causality outside the system | correctness depends on the bound actually holding |
In practice
- Spanner (2012): ε was a 1–7 ms sawtooth, ~4 ms average; commit wait ~5 ms in single-replica tests, overlapped with Paxos.
- AWS: Time Sync (microsecond accuracy on supported EC2 instances, 2023) with ClockBound exposing error bounds; Aurora DSQL (2024) chooses transaction start times from it.
Pitfalls
- Using the midpoint of the interval as "the time": the whole point is the bounds.
- Assuming NTP's reported offset is a guaranteed bound. It's an estimate unless the daemon tracks worst-case error.
Connections
- Learn first
- Happens-Before
- Contrasts with
- Hybrid Logical Clock
- In real systems
- Spanner
Recall
These cards are also in your review deck, scheduled with spaced repetition.