Tech●●●●●Difficulty 5 of 5

Why did Google put atomic clocks in its data centers?

To keep a bank transfer in the right order across the planet, Google had to outfit its data centers with atomic clocks.

▶ Start the story

Google put in its data centers so that machines on opposite sides of the planet could agree on what time it is, closely enough to put transactions in the right order. Spanner is Google's globally distributed SQL database, used for its ad business and for services such as Gmail and Google Photos. Its paper calls it the first system to distribute data at global scale and support externally-consistent distributed transactions.

means the system behaves as if all transactions ran one after another, even though Spanner runs them across many servers and sometimes several data centers. Take a bank customer who deposits money and then, afterwards, pays a bill. External consistency guarantees nobody will ever see the payment without the deposit that came before it.

Spanner does this with timestamps. On a single machine that is easy: a counter hands out increasing numbers. But in a system spread across the world, many servers must assign timestamps that agree. Spanner's answer is TrueTime, an API that exposes clock uncertainty, so each machine knows how far off its clock might be, and it can compute timestamps that are guaranteed to be greater than any generated before.

Why time is hard to share

One machine

  • A simple counter hands out timestamps
  • Trivial to keep in order

Servers worldwide

  • Each must assign timestamps that agree
  • Much harder to do efficiently

To make TrueTime work, Google had to outfit its data centers with special hardware, , along with GPS clocks. Machines then know the global time to within a few milliseconds, and Spanner waits out the remaining uncertainty for a few milliseconds before reporting a commit.

Quiz me

0/3

  1. 1.Why is handing out ordered timestamps trivial on one machine but hard across the world?
  2. 2.What is special about the TrueTime API?
  3. 3.Why does Spanner wait a few milliseconds before reporting a commit?

Recap

Spanner makes distributed time trustworthy by admitting clock uncertainty and waiting it out.

💡 A trick to remember it · Know how wrong your watch might be, then wait that long: the way to keep the order straight worldwide.

Surprising fact · Spanner waits a few milliseconds before reporting a commit, to wait out any uncertainty in the clock.

Sources (4)

No source, no claim. Every fact in this lesson (15 claims) cites at least one of these.

  1. [1]Spanner (database) · Wikipedia
  2. [2]Spanner: Google's Globally-Distributed Database · Google Research
  3. [3]Spanner: TrueTime and external consistency · Google Cloud Documentation
  4. [4]Life of Spanner Reads & Writes · Google Cloud Documentation
More lessons in 💻 Tech (3) See all tech lessons →

One more light on your map.

Get one lesson like this every day, about the things you love. Free, in two or five minutes.

Get the share card for this lesson ↗