Logical Clock
Three machines, three clocks, all wrong by different amounts and drifting at different rates. Nothing here tries to correct them. Instead each machine keeps a counter that is not a clock at all — it measures no duration, it cannot be compared to a second, and it only ever goes up. The rule is one line: carry your counter on every message, and on receiving one, jump past what it says. That is enough to guarantee that nothing ever appears to arrive before it was sent. It is not enough to tell you what happened first, and this page shows you exactly where that fails rather than mentioning it.
Three wrong clocks, and one order all three agree on
1 Three machines, three counters, ticking at rates that have nothing to do with each other
Three machines, and three wall clocks that disagree at every instant. These numbers are displayed and never used to order anything.
| machine | clock reads | drifting at | out by |
|---|---|---|---|
| alpha | 1050 | 1.00x | — |
| bravo | 996 | 1.11x | -55 |
| charlie | 1121 | 0.92x | +71 |
At the same instant the three clocks are 126 apart and getting further apart, because they tick at different rates. Nothing below uses any of these numbers.
2 Every message carries its sender's counter, and the receiver jumps past it
The run. A local event adds one; a send adds one and carries the number; a receive takes the larger of the two and adds one.
1
| machine | what happened | rule | counter |
|---|---|---|---|
| alpha | reads a key | +1 | 1 |
| bravo | reads a key | +1 | 1 |
| alpha | asks bravo for the lock | +1, and carries 2 | 2 |
| charlie | reads a key | +1 | 1 |
| bravo | hears alpha's request | max(2 carried, own) + 1 | 3 |
| bravo | tells charlie | +1, and carries 4 | 4 |
| alpha | writes | +1 | 3 |
| charlie | hears bravo | max(4 carried, own) + 1 | 5 |
| charlie | answers alpha | +1, and carries 6 | 6 |
| charlie | writes | +1 | 7 |
| alpha | hears charlie | max(6 carried, own) + 1 | 7 |
| bravo | writes | +1 | 5 |
3 Now every message arrives later than it was sent, on the numbers, on every machine
The guarantee, over every message in the run: received at a higher number than it was sent, on every machine, without the machines agreeing on what time it is.
| message | sent at | received at | higher? |
|---|---|---|---|
| alpha → bravo | 2 | 3 | yes |
| bravo → charlie | 4 | 5 | yes |
| charlie → alpha | 6 | 7 | yes |
All 3 messages arrive at a higher number than they left, and no machine had to know what time it was anywhere else.
4 Break ties by machine and the three of them agree on one order, without a clock between them
And the limit. Break ties by machine name and all three compute one order. It is an order, not the order: the pairs below are events that nothing connects, put in a sequence anyway.
| this | is ordered before | but actually |
|---|---|---|
| bravo reads a key (1) | alpha asks bravo for the lock (2) | neither caused the other |
| bravo reads a key (1) | alpha writes (3) | neither caused the other |
| charlie reads a key (1) | alpha asks bravo for the lock (2) | neither caused the other |
| charlie reads a key (1) | bravo hears alpha's request (3) | neither caused the other |
| charlie reads a key (1) | bravo tells charlie (4) | neither caused the other |
| charlie reads a key (1) | alpha writes (3) | neither caused the other |
| charlie reads a key (1) | bravo writes (5) | neither caused the other |
| alpha writes (3) | bravo tells charlie (4) | neither caused the other |
The first 8 of 15 pairs of events are ordered by their numbers while nothing connects them: no message runs between them in either direction. The order the three machines agree on is consistent, and it is not history.
These ran in this browser when the page loaded. Each claim, whether it held, and the number behind it.
| claim | held | measured |
|---|---|---|
| the run completes with every message delivered | yes | all 3 delivered |
| every one of 3 messages is received at a higher number than it was sent | yes | no message arrives before it was sent |
| and across all 45 ordered pairs, a cause always has the smaller number | yes | every one of them |
| a smaller number does NOT mean it happened first: 15 such pairs here | yes | unrelated events, ordered by number alone |
| one order over all 12 events, and no two of them compare equal, though 6 pairs share a number | yes | the tiebreak settles every one of them |
| the wall clocks are 126 apart at the same tick | yes | which is what the counters are for |
What is real here, and what is not
The counters are not clocks and the page never converts them to time
A Lamport counter has no unit. The difference between 4 and 7 is not three of anything — not seconds, not messages, not events on any one machine. It is only ever compared, never subtracted, and the page prints no elapsed time derived from one anywhere.
One fixed run, written down rather than generated
The twelve events are a script in the source, so the page and its tests are talking about the same run and the numbers below are reproducible. A randomly generated interleaving would demonstrate the same rule and would make every quantity on this page unquotable.
Messages here cannot be lost, delayed or reordered
Every send is delivered, and delivered in the order the script sets. That is not what a network does, and the difficulties that follow from it are most of why distributed systems are hard. The rule shown here survives all of that in reality; this page simply does not exercise it.
Vector clocks are what you need if you want the converse, and they are not here
The last panel is honest about the limit: a smaller counter does not mean it happened first. Recovering that requires a counter per machine rather than one number, which costs n numbers on every message and is a different machine. Saying Lamport clocks order events, full stop, is the mistake this panel exists to prevent.
Sources
- L. Lamport, Time, Clocks, and the Ordering of Events in a Distributed System, Communications of the ACM 21(7), July 1978, pages 558-565.
- F. Mattern, Virtual Time and Global States of Distributed Systems, 1989. Where the vector clock recovers the converse this page says is missing.
- Logical Art, the studio this belongs to.