← Lessons

quiz vs the machine

Gold1480

Databases

Clock Skew Handling

Bounding clock error with uncertainty windows and read restarts.

5 min read · core · beat Gold to climb

When Clocks Disagree

Servers use hybrid logical clocks or wall clocks to timestamp writes, but those clocks drift apart. If skew is unbounded, two writes could be misordered and consistency breaks. Distributed SQL systems assume a maximum clock offset and handle the rest.

The Uncertainty Window

When a transaction reads at timestamp T, any value written within T plus the max offset might actually be in its past on another node. This span is the uncertainty window.

  • If a read finds a value inside its uncertainty window, it cannot tell if that value came before or after.
  • The transaction performs a read restart, bumping its timestamp above the ambiguous value.
  • After the restart the ambiguity is gone and the read proceeds.

Keeping Skew Bounded

Nodes run NTP or better, and the cluster monitors offset. If a node drifts beyond the configured maximum, it removes itself rather than risk serving misordered data.

Key idea

By assuming a bounded clock offset and restarting reads that land in the uncertainty window, distributed SQL preserves correct ordering despite skew, and a node that drifts too far removes itself.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the uncertainty window?

2. How does a transaction resolve a value inside its uncertainty window?

3. What does a node do if its clock drifts beyond the maximum offset?