Clocks lie and processes freeze
Everything in this tier so far has been about machines disagreeing. This lesson is about why they disagree, and it comes down to two facts that sound like excuses until they cost you a weekend: your clocks are lying, and your processes stop dead without warning. Consensus protocols, consistency models and retry policies are all responses to those two facts.
There are two clocks, and confusing them is a bug
A time-of-day clock is what new Date() gives you — the machine's opinion of what time it is in the real world. It is corrected by NTP, and correction means it can jump, forwards or backwards. A monotonic clock only ever moves forward at a steady rate, but its absolute value means nothing; it might count from the last boot.
Use the wrong one for a duration and you get a bug you will never reproduce:
start = timeOfDayClock() // 10:00:00.000 ... work happens; NTP steps the clock back 30 ms ... end = timeOfDayClock() // 09:59:59.990 elapsed = end - start // -10 ms
A negative duration. Feed that to a timeout, a rate limiter or a cache TTL and the behaviour is nonsense — on one machine, roughly once a week, never in staging. Measure elapsed time with a monotonic clock. Use the time-of-day clock only to show a human a date, or to stamp a record.
Clock skew: two machines never quite agree
Well-synchronised servers in one datacenter sit a few milliseconds apart. A machine with broken NTP, a blocked port or a saturated CPU can drift by seconds, and absolutely nothing announces this. Now recall last-write-wins: two conflicting writes arrive, keep the one with the later timestamp. Under skew, "later" quietly means "written by whichever machine's clock runs fast". The other write is destroyed — no error, no conflict, no log line. It is the most popular way to lose data while believing the system is healthy.
The fix is to stop asking timestamps to order events, because ordering is not what they do. Use something that does: a version number issued by a single leader, a per-key sequence, or explicit conflict detection that hands both versions back to the application to resolve. There is a third road — keep clock error bounded with atomic clocks and GPS, then deliberately wait out the uncertainty window before committing, so a commit provably follows every earlier one. It works, and the hardware bill tells you what real ordering costs.
Your process can freeze for ten seconds
A thread does not run continuously. It can be suspended mid-function for an amount of time that would embarrass you:
- A garbage collector stop-the-world pause — milliseconds usually, seconds on a large heap.
- The hypervisor suspending your VM to live-migrate it to another host.
- The OS paging memory to disk, or a noisy neighbour stealing your CPU.
- A
SIGSTOP, or a laptop lid closing.
Here is the part that matters: the paused process cannot tell that it was paused. It resumes on the very next line as though nothing happened, still holding beliefs that expired while it was gone. That is the reason distributed locks are so much harder than they look:
node A takes a 10-second lease on the shard node A pauses 15 seconds (garbage collection) lease expires; node B takes it and starts writing node A wakes, still believing it holds the lease, and writes
Two writers, no error anywhere. The fix is a fencing token: the lock service issues a number that only ever increases, the writer sends it with every write, and the storage layer refuses any token below the highest it has already accepted. A wakes up holding token 33, storage has seen 34, A's write is rejected. Notice what actually changed — the storage stopped trusting the writer's belief about time, which was the only belief that was ever wrong.
Partial failure, and the three meanings of a timeout
On one machine a function either runs or it doesn't. Across a network there is a third outcome, and it defines the whole field. When a request times out, exactly one of these is true and you cannot tell which:
- It never arrived.
- It arrived, succeeded, and the response was lost on the way back.
- It arrived and is still running — it might finish a second from now.
So a timeout does not mean "it failed". A timeout means "I have no information." Retrying the first case is correct; retrying the second charges your customer twice. Since you cannot distinguish them, you stop trying to and make the retry safe instead — which is why idempotency keys show up in every serious API, and why "exactly once" is marketing for "at least once, plus a deduplication key".
Treating a timeout as a failure and writing compensating logic on top of it. The payment call times out, so you mark it failed and issue a refund — while the original charge quietly succeeds, and your refund lands before it does. Reconcile against the downstream system's actual state; never against your assumption about it.
Every mechanism in this tier is a response to this lesson. Consensus exists because no single node's view of who leads can be trusted. Bounded staleness exists because you cannot know how far behind a replica is without asking it. None of it is academic — it is simply what honesty about clocks and pauses forces you to build.
Going deeper
- Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport, 1978
Why physical time cannot order distributed events, and what to use instead. Foundational, and shorter than most of what cites it. - Spanner: Google’s Globally-Distributed Database Corbett et al., OSDI 2012
What it costs to make physical time trustworthy: atomic clocks, GPS, and an API that returns an interval rather than an instant.