System Design Cases
Lamport Clocks
logical scalar clock для causality + LWW conflict resolution
Lamport logical clocks
Lamport clocks assign integers to events so that causal order is respected without requiring synchronized wall clocks.
Happens-before
The relation a -> b holds when:
- both events occur in one process and a is earlier;
- a sends a message and b receives it;
- or transitivity connects them.
Concurrent events have neither a -> b nor b -> a.
Clock rules
Each process stores a local counter C.
- Before each local event or send: increment C.
- Send the new value with the message.
- On receiving timestamp T: set C = max(C, T) + 1.
The clock condition is one-way:
a -> b implies L(a) < L(b)
The converse is false. L(a) < L(b) does not prove that a caused b. Equal values on different processes may also be concurrent.
Total order is a policy
Sorting by (L(event), processId) creates a deterministic total order. The process-ID tie-break is arbitrary for concurrent events. It can support deterministic replay or queue ordering, but it does not establish real-time precedence and it is not a consensus protocol.
Vector clocks retain enough per-participant information to detect concurrency, at metadata cost proportional to the tracked participant set. They still need a separate conflict policy.
Hybrid logical clocks
An HLC combines a physical-time component with a logical counter. It can stay close to wall time while preserving causal monotonicity, subject to the implementation's clock assumptions. It is not proof of perfectly synchronized global time.
Persist a stable node/process identity and the last emitted clock across restart when monotonicity across restart is required. Detect counter overflow and corrupted future timestamps.
Diagram scenarios
The animation covers send/receive updates, the one-way clock condition, concurrent events, deterministic tie-breaking, and the HLC boundary.