Distributed nodes have no shared wall clock, yet they must agree on what happened before what. Lamport's answer: give each node a counter. Increment it on every local event; stamp every message you send; on receive, set your counter to max(local, message) + 1. The result is a logical clock where a → b (a happened-before b) always implies LC(a) < LC(b) — a consistent order of causality built from nothing but counters and messages.
THE TECHNIQUE on receive: LC = max(local, msg) + 1 ; a→b ⇒ LC(a)<LC(b)
Run two processes exchanging a message; give the receiver some head-start local events, and watch the receive stamp always land strictly after the send — causality preserved with no synchronized time: live demo
HISTORY & CREDIT Leslie Lamport, 1978
“To order events across machines you need synchronized clocks.” — no; you need only counters and the messages you already send. Physical clocks drift and disagree; the logical clock never claims real time, only causal order — and that is all consensus ever needs. cited
1978 · Leslie Lamport — “Time, Clocks, and the Ordering of Events in a Distributed System”: the happened-before partial order and the logical clock. One of the most-cited papers in all of computing. 1988 · Fidge & Mattern — vector clocks extend it to capture concurrency exactly (Lamport's scalar clock only preserves one direction of the implication). now · every ordered log, every causal store, every version-vector rests on this counter.
The deepest lesson is the arrow's direction: a→b forces LC(a)<LC(b), but not the reverse — a smaller stamp does not prove causality. The clock is honest about exactly what it can and cannot know. Lamport 1978
RECOMMEND FOR I-13 receive stamped strictly after send, computed
On the canonical compiler, a message sent at logical time 2, received by a node whose local clock was at 1, is stamped max(1,2)+1 = 3 — strictly after the send:
$ i13 run lamport.i13 # P1 sends at LC=2 ; P2 had done 1 local event
p2_recv = 3 -- max(local 1, msg 2) + 1
ordered = 1 -- receive (3) strictly AFTER send (2): happened-before preserved
Recommend: the Lamport clock is LIT for I-13 — verified a receive event stamps to 3 = max(1,2)+1, strictly greater than the send stamp 2, so send → receive is preserved in the logical order. Pure counters and max, no shared clock — the foundation every other dart in this batch stands on.