Scrivio Interview library
InternalsAdvanced7 min read · updated 13 November 2026

Globally distributed databases must order transactions across continents without a single shared clock. One well-known design uses atomic clocks and GPS with explicit uncertainty intervals; others use hybrid logical clocks with a configured maximum clock offset.

How does commit wait with bounded clock uncertainty give externally consistent transactions, how does the hybrid-clock approach differ, and what does each require from your clock infrastructure?

With a time API that returns an interval [earliest, latest] guaranteed to contain true time, a transaction picks a commit timestamp no smaller than latest and then waits until earliest has passed that timestamp before making the commit visible, so any transaction that starts afterwards must get a larger timestamp; this commit wait equals the clock uncertainty, a few milliseconds with atomic clocks and GPS. Hybrid-clock databases such as CockroachDB do not wait at commit; instead a read that meets a value inside its uncertainty window (its start time plus the configured maximum offset) restarts at a higher timestamp, turning clock skew into retries. Both depend on healthy clocks, so time sources, offset monitoring and care with VM pauses become part of database availability.

Why this question is asked

External consistency, also called strict serializability, is the strongest promise a database can make: if transaction T1 commits before T2 starts, in real time, T2's timestamp is larger and T2 sees T1's effects. One machine gives this for free. A database spread across continents, with no shared clock, has to earn it. Interviewers ask this internals question to see whether we understand how clock uncertainty is turned into either waiting or retrying, and what that means for the clock infrastructure we run. In this answer, we will recap why plain timestamps are not enough, walk through commit wait, then the hybrid-clock approach, and compare what each demands from our clocks.

1A Quick Recap: Why Plain Timestamps Fail

Many distributed databases give each transaction a timestamp and use it to order transactions and choose which versions a read sees, a technique called multi-version concurrency control. If timestamps come from local wall clocks, a node whose clock is 5 ms behind can give a transaction that commits later a smaller timestamp than one that committed earlier on another node. A reader at a timestamp between the two would then see the later transaction but not the earlier one, which is impossible in real time and breaks external consistency.

The two designs we will look at accept that clocks are uncertain and handle that uncertainty explicitly, one by waiting at commit, the other by retrying reads.

2Commit Wait With Bounded Uncertainty

The first design, introduced by Google's Spanner with its TrueTime API, makes clock uncertainty explicit. Asking for the time returns an interval [earliest, latest], and the infrastructure guarantees that true time lies inside it. Each data center has GPS receivers and atomic clocks, and every server polls several of them, so the width of the interval, the uncertainty, is usually a few milliseconds.

When a transaction is ready to commit, it chooses a commit timestamp s no smaller than latest at that moment. Then it waits until earliest is greater than s, which means true time has definitely passed s on every clock in the system. Only then does it make the commit visible and release its locks. Any transaction that starts after this point reads the clock and gets an interval whose latest is beyond s, so it gets a larger timestamp and sees the commit. The waiting is the price, and it equals roughly twice the uncertainty bound in the worst case, typically a few milliseconds, which is why tighter clock synchronisation directly lowers write latency. The wait also overlaps with the replication round trip, so in practice much of it is hidden.

Java
// pseudo-code of commit wait with an uncertainty interval
TTInterval now = trueTime.now(); // [earliest=100.000, latest=100.007] (ms)
long s = now.latest(); // commit timestamp 100.007
replicateCommitRecord(s); // Paxos round, overlaps with the wait
while (trueTime.now().earliest() <= s) { // wait until true time is surely past s
sleepBriefly(); // about 7 ms here
}
makeVisibleAndReleaseLocks(s); // any later transaction gets a timestamp > s
Step throughCommit wait makes later transactions see larger timestamps
T1 leaderClock APIT2 (starts later)
now()
[100.000, 100.007]
choose s = 100.007, replicate
now() until earliest > 100.007
commit visible after about 7 ms
now()
[100.010, 100.017]: timestamp > s

7 messages in order. Play them, or step through them one at a time.

3The Hybrid-Clock Approach: Uncertainty Becomes Retries

Most databases do not have atomic clocks in every data center. CockroachDB, and designs like it, use hybrid logical clocks on ordinary NTP-synchronised machines, plus a configured maximum offset: an assumed upper bound on how far any two nodes' clocks can differ, 500 ms by default in CockroachDB (check your version).

They do not wait at commit. Instead, each transaction gets a read timestamp t from its gateway's clock and an uncertainty window from t to t + maximum offset. When a read finds a value with a timestamp inside that window, the database cannot tell whether that write happened before the transaction started in real time, since the writer's clock might simply have been ahead. To stay safe, it treats the value as possibly earlier: it restarts the read at a timestamp above that value, so the transaction will see it. Values above the window are clearly later and are ignored; values below are clearly earlier and are read.

So clock skew turns into occasional retries instead of a fixed wait on every write. Most transactions never meet a value in their window and pay nothing. Contended keys written just before a read pay a restart.

Commit wait vs uncertainty restarts
AspectCommit wait (TrueTime style)HLC + max offset (CockroachDB style)
Clock hardwareGPS + atomic clocks per data centerordinary NTP or PTP
Uncertaintya few ms, measured and boundedconfigured, 500 ms by default
Cost paidwait on every read-write commitread restarts on recent conflicting writes
If clocks exceed the boundguarantee breaks (bound must hold)node shuts down to protect consistency
Strongest guaranteeexternal consistencyserializable; not strictly linearizable for all cases

4When a Clock Goes Wrong

Both designs rest on the bound being true. In the commit-wait design, if a server's clock were outside its reported interval, a later transaction could get a smaller timestamp; the system relies on the time infrastructure to make that essentially impossible, and servers whose clocks misbehave are evicted.

In the hybrid-clock design, if a node's clock drifted beyond the maximum offset from its peers, the uncertainty window would no longer cover its writes and stale reads could occur. CockroachDB therefore checks clock offsets against other nodes continuously, and a node whose offset approaches the configured maximum relative to most of its peers shuts itself down rather than risk inconsistency. That turns a clock fault into an availability event, which is visible and recoverable, instead of a silent correctness bug.

It also explains why the maximum offset cannot simply be set very low to reduce restarts: set it below the real worst-case skew and nodes start shutting down, or worse, guarantees quietly break.

5What Each Demands From Clock Infrastructure

Both approaches need reliable time sources: several NTP or PTP servers per site, ideally with local reference clocks, rather than one public pool. Both need offset monitoring on every node with alerts well below the bound. And both need care with VM pauses and live migration, which can leave a guest clock seconds off when it resumes; a database node should not rejoin with an unchecked clock.

The practical consequence is organisational: clock health becomes part of database availability. The team running the database must own, or at least monitor, the time service with the same seriousness as disks and networks. Cloud providers now offer precise time services with bounded error, which makes tighter offsets and fewer restarts realistic.

6Follow-up questions

Why does a tighter clock bound make Spanner-style writes faster?

Because the commit wait is proportional to the uncertainty. With 7 ms of uncertainty a commit waits up to about 14 ms in the worst case; with 1 ms, it waits about 2 ms. Better synchronisation directly removes latency from every read-write transaction.

Why do read-only transactions at a fixed timestamp avoid restarts in CockroachDB?

A read at a timestamp sufficiently in the past, for example with follower reads, has no uncertainty about values written after it, because the whole uncertainty window is already closed. That is why historical reads are cheap and can be served by any replica.

Is an uncertainty restart visible to the application?

Often the database retries internally; when it cannot, for example after results have already been streamed to the client, the client receives a retryable error and must re-run the transaction, so applications should use retry loops for transactions.

7Conclusion

In this answer, we saw two ways to order transactions across continents without a shared clock. Commit wait uses an interval guaranteed to contain true time, picks a commit timestamp at the interval's latest and waits until its earliest has passed, so later transactions always get larger timestamps; tighter clocks mean shorter waits. The hybrid-clock approach skips the wait and instead restarts reads that meet values inside their uncertainty window, defined by a configured maximum offset, and nodes that drift too far shut down. Both make reliable time sources and offset monitoring part of database availability.

What to say in the interviewAbout 90 seconds aloud

Open with

Commit wait relies on a time API that returns an interval, earliest to latest, guaranteed to contain true time, which Spanner gets from GPS and atomic clocks in each data center.

Then, if they want more

A transaction picks a commit timestamp at least equal to latest, then waits until earliest has passed that timestamp before making the commit visible. After that wait, true time is definitely past the commit timestamp on every clock, so any transaction that starts later gets a larger timestamp and sees the commit, which gives external consistency.

The wait is about the clock uncertainty, a few milliseconds, so better clocks directly mean faster writes. The hybrid-clock approach, as in CockroachDB, runs on ordinary NTP clocks with a configured maximum offset, 500 milliseconds by default, though I'd check the version. It doesn't wait at commit.

Instead, each read has an uncertainty window from its timestamp up to timestamp plus max offset, and if it finds a value inside that window, it can't tell whether that write came before it in real time, so it restarts at a higher timestamp. Clock skew becomes retries rather than waits.

Both need the bound to really hold: reliable NTP or PTP sources, offset monitoring and care with VM pauses. CockroachDB shuts down a node whose clock drifts too far from its peers, so clock health becomes part of database availability.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How does commit wait with bounded clock uncertainty give externally consistent...": https://scrivio-interview-library.netlify.app/architecture/distributed-systems/0c96dff89c/