Unit 1 of 12 · about 4 hours · explain, measure
Wall and monotonic clocks, drift, skew, backward jumps and synchronization uncertainty
Ordering by wall timestamps is the most common silent-loss bug in this section. Clocks look simple until a step, a pause or a skew window reorders two writes.
You'll be able to
- Explain when to use a wall clock and when to use a monotonic clock, and why monotonic readings cannot be compared across nodes.
- Derive drift accumulation from a parts-per-million rate and state skew, backward jumps and NTP error sources for a given setup.
- Treat a clock reading as an interval with stated uncertainty and say what ordering it cannot support.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Unreliable clocksDDIA 2e - Chapter 9 The Trouble with Distributed Systems
Chapter 9, Unreliable Clocks (p. 358), Monotonic Versus Time-of-Day Clocks (pp. 359-360), Clock Synchronization and Accuracy (pp. 360-361), Relying on Synchronized Clocks with Figure 9-3 (pp. 362-364), Clock readings with a confidence interval (pp. 364-365)
- Clock synchronisation and monotonic clocksCambridge Concurrent and Distributed Systems Notes (Kleppmann) - Time, Clocks and Ordering
Section 3.2, Slides 52 to 59: NTP request and response stamps, skew estimate, slew and step thresholds, Java currentTimeMillis versus nanoTime example; Exercise 7
- Why wall-clock time failsHLD Handbook - Clocks, Failure Detection and Consistent Hashing
Theory, Why wall-clock time fails: quartz drift, NTP skew range, leap-second cases and VM pauses; Common Pitfalls warnings on
ORDER BY created_atand leap-second timing codeUse as review after DDIA and the notes. Treat its cloud skew ranges and TrueTime bounds as reported figures from its cited sources, not targets you must reproduce.
Focus on
- A time-of-day clock reads wall time and can step backward. A monotonic clock measures elapsed time on one node and its absolute value is meaningless elsewhere.
- Drift is a rate error in one clock. Skew is the difference between two clocks at one instant. NTP estimates skew under a symmetric-delay assumption that queueing can break.
- NTP slews below 125 ms by varying the rate up to 500 ppm, steps between 125 ms and 1,000 s by resetting the clock, and panics at or above 1,000 s, leaving the fix to an operator. A step is a backward jump for wall readers.
- A reading is an interval, not a point. DDIA builds this from drift since last sync plus server uncertainty plus round-trip time.
Common mistakes · 3
- Comparing monotonic readings from two nodes. They start from unrelated boot points, so the comparison is meaningless even when each node is correct.
- Using a wall clock for elapsed time. A step or leap second can make the difference negative or inflated; use a monotonic source for intervals.
- Reading a synced timestamp as exact. NTP estimates its own error, but common clock APIs return a point with no error bound, so design the consumer to tolerate the full skew window.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why can a causally later write get the smaller timestamp even when clock skew is under 3 ms?Answer
The skew only has to exceed the real gap between the writes. In DDIA Figure 9-3 the skew is under 3 ms, yet x = 1 is stamped 42.004 s and the later increment 42.003 s, so last-write-wins drops the increment.
2.What is the difference between drift and skew?Answer
Drift is one clock running fast or slow over time. Skew is the difference between two clocks read at the same instant.
3.When does NTP slew, step or refuse?Answer
Slew below 125 ms by adjusting the rate, step between 125 ms and 1,000 s by resetting the clock, and panic at or above 1,000 s, leaving the fix to an operator.
4.Why is a clock reading better described as an interval?Answer
Quartz drift since last sync, server uncertainty and network delay each add error. The true time lies somewhere in the resulting range, and digits below that width carry no meaning.
Practice
- Building Distributed Systems Timekeeper PH-1: Read System Clock and Detect Backward Jumps
Task PH-1: sample the system clock in a loop and record backward jumps
Keep the jump log. It is the evidence you cite when you claim wall time moved backward on your machine.
- Building Distributed Systems Timekeeper PH-2: Implement Monotonic Clock Wrapper
Task PH-2: wrap the system clock so the result never decreases and state what is lost
State the loss in your own words: the wrapper hides the step but keeps no wall meaning, so it cannot order events across nodes.
You're done when
You derive both drift numbers without notes and your wrapper log shows a backward wall step that the monotonic path hides with the loss stated.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 11 more in the section
- DDIA 2e - Chapter 9 The Trouble with Distributed SystemsMartin Kleppmann and Chris Riccomini · primary
Read clocks, pauses, unreliable networks, partial failures and knowledge limits. For each failure, record what a node observes, what is true globally and what action is safe under that uncertainty.
- Cambridge Concurrent and Distributed Systems Notes (Kleppmann) - Time, Clocks and OrderingUniversity of Cambridge (Martin Kleppmann) · support
Use Chapter 3 (physical clocks, NTP and monotonic clocks, happens-before) and Section 4.1 (Lamport and vector clocks with worked examples) as the derivation workbook: work Exercises 7 to 13. Each section marks where its public lecture video starts.
- HLD Handbook - Clocks, Failure Detection and Consistent HashingHLD Handbook · required
Read Part 3 clocks and ordering, failure detection and consistent hashing. Use its exercises to compare assumptions, then verify claims against your own histories.
Also in this section
- Time, Clocks, and the Ordering of Events in a Distributed System (Lamport, 1978)Leslie Lamport · required
Read the partial ordering and logical clocks sections: happens-before, the Clock Condition, rules IR1 and IR2, and the total order. Its ties are broken arbitrarily, so the total order is not causality.
- Logical Physical Clocks and Consistent Snapshots (Kulkarni et al., 2014)University at Buffalo · support
Read the hybrid logical clock algorithm and its bounds; the paper reports the logical counter staying well below its proved bound in practice, so measure your own.
- SWIM: Scalable Weakly-consistent Infection-style Process Group Membership (Das et al., 2002)Cornell University · support
Read the direct and indirect probing detector, infection-style dissemination, the suspicion mechanism and incarnation numbers. Suspicion timeouts depend on the workload.
- The phi Accrual Failure Detector (Hayashibara et al., 2004)JAIST · support
Read how phi is computed from the heartbeat inter-arrival history and how a threshold trades detection time for false suspicion. Its normal approximation misleads under bursty delay, so test with pause traces too.
- How to Do Distributed Locking (Kleppmann, 2016)Martin Kleppmann · required
Read the process-pause, network-delay and fencing-token sections with DDIA 2e Chapter 9 "Distributed Locks and Leases". Treat the Redlock critique as dated to 2016; the lasting lesson is that the storage service must reject a write that carries an older token.
- Building Distributed Systems - The TimekeeperBuild Distributed Systems · optional
Only the first three tasks are free (clock reads and backward jumps, a monotonic wrapper, a split-brain lease). Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.
- Building Distributed Systems - The GossiperBuild Distributed Systems · optional
Only the first three tasks are free (basic broadcast, tree topology, random gossip). Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.
- Gossip Glomers - Unique IDs and BroadcastFly.io and Jepsen · required
Each challenge runs locally under Maelstrom (v0.2.4; the pages were tested on 0.2.3) with its checker and, where the page says so, the partition nemesis; keep the run directory as the history. Do challenge 2 (unique IDs under partition with total availability) and 3a to 3c (broadcast, then with partitions). A pass shows uniqueness or convergence in that run, not ordering or recency.
- MIT 6.5840 - Failure and Paper Discussion LensMIT PDOS · support
Use the RPC, GFS, Raft and consistency lectures to identify which timing assumptions affect progress and which invariants must not depend on time. Do not start the Raft lab yet.
- Replicated Log and Stream Processor - Time and Membership SliceRoadmap-Final · support
Add incarnation IDs, logical timestamps, gossip membership, suspicion metrics and fenced ownership. Retain seeds and minimized traces for every false-failure or stale-actor case.
- AlgoMaster System Design practice - clock, gossip and lease drillsAlgoMaster · support
Use only the named problems: Advance a Lamport Logical Clock, Compare Two Vector Clocks, Update a Vector Clock on Receive, Advance a Hybrid Logical Clock, Simulate Gossip Rumor Spread and Implement a Lease Lock with Fencing Tokens. Each states its function signature and checks small deterministic cases.