ReviseAlgo Logo
Beginner8 min readFoundations of Distributed Systems

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

Inbound Node Ingests request
Time & Ordering Engine Processes operations
Target Replica Updates state

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

1

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.

Example: Two servers synced to NTP at 10:00:00.000 may show 10:00:01.005 and 10:00:01.012 after 1 second — a 7ms discrepancy.
2

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.

Example: AWS EC2 instances synchronize to Amazon Time Sync Service, which uses GPS and atomic clocks for stratum 1 accuracy.
3

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.

Example: Google Spanner uses GPS and atomic clocks in every datacenter to bound clock uncertainty to ±7ms, enabling external consistency across globally distributed data.
4

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.

Example: Client sends request (A) → Server receives request (B) → Server processes (C) → Server sends reply (D) → Client receives reply (E). A → B → C → D → E.
5

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).

Example: Process P1 has counter 5, sends to P2 which has counter 3. P2 sets counter = max(3, 5) + 1 = 6. All subsequent P2 events have timestamps > 5.
6

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).

Example: With 3 processes: P1=[1,0,0] sends to P2=[0,2,0]. P2 updates to [max(1,0), max(0,2), max(0,0)] + increment own = [1,3,0].

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In
Time & Ordering - Module 1: Foundations of Distributed Systems | System Design | Revise Algo