Search DistillSys

Find a concept

Type at least two characters to search lessons, designs, papers, and interview prep.

Foundationsintermediate6 min read

Time & Ordering

Reason about events when clocks disagree and messages arrive in different orders.

2–5 minute refresher
Mental model

Wall clocks estimate when; logical clocks establish before and after

30second
refresher
Distributed nodes do not share a perfectly synchronized clock. Physical time is useful for deadlines and human meaning; logical time tracks causal order without pretending every event has one exact global position.

What problem does it solve?

Coordination, conflict resolution, snapshots, and debugging all need to answer whether one event could have influenced another. Clock skew and network delay make wall-clock timestamps alone unsafe for that job.

How it works

  1. Use monotonic clocks for elapsed time and deadlines.
  2. Use NTP-synchronized wall clocks for approximate human time, never as a perfect oracle.
  3. Use Lamport timestamps to produce an order consistent with causality.
  4. Use vector clocks when the system must distinguish causally ordered updates from concurrent ones.
  5. Introduce consensus or a sequencer only where one authoritative total order is required.
Decision guide

Key trade-offs

ChoiceWhat you gainWhat it costs
Physical clockHuman-readable time and simple expirySkew, jumps, and uncertain ordering
Logical clockCausal reasoning without synchronizationMetadata and no wall-time meaning
Total orderSimple deterministic applicationCoordination latency and bottlenecks
What happens if?

A clock jumps backward

Lease checks, last-write-wins conflict rules, and elapsed-time calculations can become unsafe. Use monotonic time for durations, attach uncertainty to physical timestamps, and fence authority instead of trusting the newest wall-clock value.

Where it appears

  • Spanner TrueTime
  • Dynamo vector clocks
  • Kafka partition offsets
  • Hybrid logical clocks
Senior interview modeWhen would you choose vector clocks over Lamport timestamps?Show answer
Choose vector clocks when detecting concurrency matters. Lamport timestamps can order events but cannot tell whether two events were causally independent; vector clocks can, at the cost of larger metadata.
#clocks#ordering#causality#timestamps