Time & Ordering
Reason about events when clocks disagree and messages arrive in different orders.
2–5 minute refresher
Wall clocks estimate when; logical clocks establish before and after
30second
refresher
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
- Use monotonic clocks for elapsed time and deadlines.
- Use NTP-synchronized wall clocks for approximate human time, never as a perfect oracle.
- Use Lamport timestamps to produce an order consistent with causality.
- Use vector clocks when the system must distinguish causally ordered updates from concurrent ones.
- Introduce consensus or a sequencer only where one authoritative total order is required.
Decision guide
Key trade-offs
| Choice | What you gain | What it costs |
|---|---|---|
| Physical clock | Human-readable time and simple expiry | Skew, jumps, and uncertain ordering |
| Logical clock | Causal reasoning without synchronization | Metadata and no wall-time meaning |
| Total order | Simple deterministic application | Coordination 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.