Advanced Distributed Systems #clocks #Lamport #vector-clocks #TrueTime

Distributed Clocks

5 exercises — master distributed clock vocabulary: why wall clocks fail for ordering, Lamport timestamps and their limits, vector clock causality detection, Hybrid Logical Clocks (HLC) in CockroachDB and YugabyteDB, and Google Spanner's TrueTime with commit wait.

0 / 5 completed
Distributed clock quick reference
  • Wall clocks (NTP) — ±1-100ms typical uncertainty; clock drift between syncs; leap second issues; do NOT use for event ordering.
  • Happens-before (→) — A→B means A causally precedes B; captured by logical clocks.
  • Lamport timestamp — counter incremented before each event; on receive: max(local, received)+1. If A→B then L(A) < L(B). Reverse NOT guaranteed — cannot detect concurrency.
  • Vector clock — vector of counters (one per node). Can detect concurrent events: incomparable vectors = concurrent. O(n) space cost.
  • HLC — (physical_time, logical_counter). Stays within ε of NTP; Lamport-style causal ordering. Used in CockroachDB, YugabyteDB.
  • TrueTime (Spanner) — GPS + atomic clocks; returns interval [earliest, latest]; ε ≈ 7ms.
  • Commit wait — Spanner waits until TT.now().earliest > commit_timestamp before acknowledging; ensures external consistency.
1 / 5

A junior engineer asks: "Why can't we just use the system timestamp (Date.now()) on each server to determine the order of events in a distributed system?"