How Google Cloud Spanner Uses TrueTime for External Consistency
Learn how Google Cloud Spanner’s TrueTime uses GPS‑aided atomic clocks to represent time as an interval, enabling external consistency via the commit wait rule while avoiding a centralized timestamp oracle.
19 Sept 2026, 01:06 UTC

The Distributed Clock Problem
When a database spans multiple continents, each node’s clock drifts slightly. If two transactions are stamped with nearby times, you cannot rely on those stamps to decide which happened first without a trusted time source. Many systems solve this with a centralized timestamp oracle, but that creates a bottleneck and a single point of failure at global scale.
TrueTime: Time as an Interval
Google Cloud Spanner replaces the oracle with a service called TrueTime. TrueTime does not return a single timestamp; it returns an interval [earliest, latest] that bounds the true UTC time. The interval width, called ε (epsilon), reflects the maximum uncertainty from clock drift and measurement error. By exposing this uncertainty, Spanner can reason about ordering without needing a perfect clock.
Commit Wait and External Consistency
External consistency means that if transaction T1 commits before T2 starts, any client reading after T2 begins must see T1’s writes. Spanner enforces this with the "commit wait" rule:
- When a transaction is ready to commit, Spanner reads the current TrueTime interval and picks a commit timestamp
s = latest. - Before the transaction is made visible, Spanner waits until the
earliestvalue of the current TrueTime interval is greater thans. In other words, it waits out the uncertainty window. - After the wait, any subsequent transaction will inevitably receive a timestamp larger than
s, preserving the causal order globally.
This wait adds latency proportional to ε; better‑synchronized hardware (smaller ε) reduces the penalty.
Read Consistency Levels
Because Spanner knows the uncertainty interval, it can offer different read guarantees:
| Read Type | How It Works | Typical Latency | Consistency Guarantee |
|---|---|---|---|
| Strong Read | Chooses a read timestamp and waits until the current TrueTime earliest exceeds that timestamp, ensuring the read reflects all committed transactions. |
Higher (includes possible commit‑wait delay) | External consistency (latest committed data) |
| Stale Read | Selects a timestamp in the past that is already known to be stable; no additional wait is needed. | Lower | Consistent but may return slightly older data |
Worked Example: Node.js Client
The following snippet shows how to request a strong read using the Google Cloud Spanner Node.js client. The exact method names may vary across client versions; the code is illustrative and omits error handling and client‑setup details for brevity.
// Assume `spanner` and `instanceId`, `databaseId` are already configured
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const database = spanner.instance(instanceId).database(databaseId);
async function getBalanceStrong(accountId) {
// A read‑only transaction defaults to a strong read.
const [rows] = await database.runTransactionAsync(async (transaction) => {
const [rows] = await transaction.run({
sql: 'SELECT Balance FROM Accounts WHERE AccountId = @id',
params: {id: accountId},
});
await transaction.end();
return rows;
});
return rows;
}
// For a stale read you could specify an exact past timestamp:
// const options = {singleUse: {timestampBound: {exact: stamp}}};
Verification: You can observe the latency difference by timing a strong read versus a stale read (using an exact past timestamp) in a test environment. The strong read will typically show higher latency because it may need to wait for the TrueTime interval to advance past the chosen read timestamp.
Limitations and Practical Checks
The TrueTime mechanism depends on specialized hardware: each Spanner zone has time‑master machines equipped with GPS receivers and atomic clocks to keep ε small (typically a few milliseconds). If the hardware degrades and ε grows, the commit wait period lengthens, increasing write latency across the database. This hardware requirement means the exact TrueTime design cannot be reproduced on ordinary commodity VMs without similar synchronization sources.
To check whether your Spanner instance is experiencing higher-than‑expected uncertainty, you can monitor the metric spanner.googleapis.com/database/write_latency and compare it to the baseline; a sustained increase may indicate growing ε or other issues.
Closing Decision
If your workload needs globally distributed data with strict external consistency and you can accept the modest, predictable write latency introduced by commit wait, Spanner’s TrueTime approach offers a way to scale without a central timestamp oracle. The trade‑off is clear: invest in synchronized hardware (or use a managed service that provides it) to keep ε low, and you gain globally consistent reads and writes without a single point of failure for timestamp assignment.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.