Time & Ordering
Why standardized physical time fails in distributed networks — covering NTP clock synchronization, GPS boundary clocks, and how global event scheduling remains fundamentally complex.
What you'll learn
- Clock Drift
- NTP (Network Time Protocol)
- GPS & Atomic Clocks
- Happens-Before Relationship
- Lamport Timestamps
- Vector Clocks
TL;DR
Why standardized physical time fails in distributed networks — covering NTP clock synchronization, GPS boundary clocks, and how global event scheduling remains fundamentally complex.
Visual System Topology
Time & Ordering Execution Topology
Concept Overview
Time and ordering are fundamental challenges in distributed systems. Unlike a single machine where a global clock determines the sequence of operations, distributed systems have multiple clocks that drift apart, cannot be perfectly synchronized, and may even run at different rates.
The problem: if service A writes X=5 at 10:00:00.000 on its clock, and service B writes X=7 at 10:00:00.001 on its clock, which write should win? The answer is undefined unless the clocks are perfectly synchronized — which they cannot be in practice.
Clock synchronization (NTP, PTP, GPS clocks) reduces drift but cannot eliminate it. Network Time Protocol keeps server clocks within ~100ms of each other on a LAN; GPS boundary clocks achieve ~1μs accuracy. But even 1ms of uncertainty is enough to cause ordering ambiguity for high-frequency financial transactions. This is why distributed systems use logical clocks (Lamport timestamps, Vector clocks) that track causal ordering of events rather than wall-clock time.
Key Architectural Pillars
Clock Drift
Physical clocks naturally drift due to temperature, manufacturing tolerances, and quartz crystal imperfections. Typical server clocks drift ~10ms/day without synchronization. NTP corrects drift periodically, but between sync cycles, clocks drift apart.
NTP (Network Time Protocol)
The standard internet protocol for clock synchronization. NTP clients query time servers hierarchically (stratum 0 = atomic clocks, stratum 1 = GPS servers, stratum 2 = NTP servers). Achieves ~1-50ms accuracy on the internet, ~0.1-1ms on LAN.
GPS & Atomic Clocks
Stratum 0 time sources with nanosecond accuracy. Used in financial trading systems and Google's TrueTime API (Spanner). GPS satellites carry atomic clocks and broadcast time signals; GPS receivers achieve ~100ns accuracy.
Happens-Before Relationship
Leslie Lamport's 1978 formalization: event A "happens-before" event B (A → B) if: (1) A and B are in the same process and A occurred first, (2) A is the send of a message and B is the receive of that message, or (3) there exists C such that A → C and C → B. Events not related by → are concurrent.
Lamport Timestamps
A logical clock that assigns a monotonically increasing integer counter to each event. Rules: (1) increment counter on each local event; (2) on send, attach the counter; (3) on receive, set counter = max(local, received) + 1. Lamport timestamps preserve happens-before order: if A → B, then L(A) < L(B). But L(A) < L(B) does NOT imply A → B (concurrent events may have any order).
Vector Clocks
An array of counters, one per process. On event: increment own counter. On send: attach the full array. On receive: for each position, take the max. Vector clocks capture full causal history: V(A) < V(B) iff A happened-before B. V(A) and V(B) are incomparable (concurrent) iff neither V(A) ≤ V(B) nor V(B) ≤ V(A).
