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.

machineclock readsdrifting atout by
alpha10501.00x
bravo9961.11x-55
charlie11210.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

machinewhat happenedrulecounter
alphareads a key+11
bravoreads a key+11
alphaasks bravo for the lock+1, and carries 22
charliereads a key+11
bravohears alpha's requestmax(2 carried, own) + 13
bravotells charlie+1, and carries 44
alphawrites+13
charliehears bravomax(4 carried, own) + 15
charlieanswers alpha+1, and carries 66
charliewrites+17
alphahears charliemax(6 carried, own) + 17
bravowrites+15

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.

messagesent atreceived athigher?
alpha → bravo23yes
bravo → charlie45yes
charlie → alpha67yes

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.

thisis ordered beforebut 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.

Each claim, whether it held, and the values behind it
claimheldmeasured
the run completes with every message deliveredyesall 3 delivered
every one of 3 messages is received at a higher number than it was sentyesno message arrives before it was sent
and across all 45 ordered pairs, a cause always has the smaller numberyesevery one of them
a smaller number does NOT mean it happened first: 15 such pairs hereyesunrelated events, ordered by number alone
one order over all 12 events, and no two of them compare equal, though 6 pairs share a numberyesthe tiebreak settles every one of them
the wall clocks are 126 apart at the same tickyeswhich 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