← Lessons

quiz vs the machine

Silver1080

Databases

Spanner TrueTime

How Google bounds clock uncertainty to give globally consistent timestamps.

4 min read · intro · beat Silver to climb

The Clock Problem

Distributed databases need to order transactions globally, but every machine has a slightly different clock. Ordinary clocks drift, so you cannot trust that one server time matches another. Spanner solves this with TrueTime, an API that exposes clock uncertainty instead of pretending the clock is exact.

What TrueTime Returns

TrueTime does not return a single number. It returns an interval with an earliest and latest bound around the real time.

  • The API gives earliest and latest possible times.
  • The true wall clock is guaranteed to be somewhere inside that interval.
  • The width of the interval is called epsilon, kept small using GPS and atomic clocks in each datacenter.

Commit Wait

To guarantee that a transaction with timestamp T is truly in the past before it becomes visible, Spanner makes the writer wait out the uncertainty. It picks a commit timestamp, then sleeps until even the latest bound has passed that timestamp. This is called commit wait and it makes timestamps globally meaningful.

Key idea

TrueTime exposes bounded clock uncertainty so Spanner can assign globally meaningful timestamps and order transactions across continents.

Check yourself

Answer to earn rating on the learn ladder.

1. What does the TrueTime API return?

2. Why does Spanner perform commit wait?