← The Books

Ordering Without Clocks

If no two computers agree on the exact time, how can they agree on what happened first? And when two events happen far apart, how can anyone tell whether one caused the other, or if they happened completely independently?

To find out, we travel to an ancient Greek island where three trading houses must keep their trades in order, even when heavy clouds make their sundials useless.

To find out, we follow the algorithms step by step. Three processes, each with its own unsynchronized clock, must put their events in an order that never places an effect before its cause.

After Leslie Lamport, Time, Clocks, and the Ordering of Events in a Distributed System, 1978 · Colin J. Fidge, Timestamps in Message-Passing Systems That Preserve the Partial Ordering, 1988 · Friedemann Mattern, Virtual Time and Global States of Distributed Systems, 1988

Before House 1's columned portico under an overcast sky: the accountant sits on a boulder reading a scroll, a clerk and a messenger argue in the portico, and two more messengers jog along the road towards a cart of amphorae
Where this book sits
Draws on
This book retells
Leads to

Each link shows how one paper built on an idea from another. Hover over or tap any link to read how.

a paper this book retells a paper retold in another book a paper outside the series

Under low cloud, the long sea cliff seen from the water: a pale wall of rock with scrub on its face, cypresses along the ring road on top, and a small messenger running along the edge
The ring road of ArcheThe model

Three houses, one narrow roadThree processes, one network

House 1, House 2, and House 3 sit along the coast of the island of Arche, separated by a steep central mountain. News travels between them only on written slips of papyrus, carried by messengers along a single coastal ring road.Three processes, P1, P2 and P3, run on separate machines. They communicate only by messages sent over a network.

No overtakingBy the law of the narrow road, no messenger may pass another. Slips sent from one house to another always arrive in the exact order they were sent.FIFO channelsMessages sent from one process to another always arrive in the exact order they were sent.
Unpredictable travel timeEvery slip eventually arrives, but a journey might take an hour or a day, nobody can put an upper limit on how long a messenger will take.Unbounded delayEvery message eventually arrives, but delivery might take a millisecond or a day, nobody can put an upper limit on how long a message will take.
No shared clockDuring the cloudy trading season, shadows vanish from the sundials, and each counting room's indoor water-clock keeps its own separate time.*No shared clockEach machine’s physical clock drifts and keeps its own separate time. Nothing synchronizes them.
The question

Which request was placed first?Which request was made first?

House 3 has grain in its storehouse, just enough for one of the other houses, though both need it. House 2 writes a request for the grain and sends a messenger down the road. Shortly after, knowing nothing of House 2's order, House 1 sends a messenger with a request of its own.P3 manages a resource that only one of the other processes can use at a time, though both want it. P2 makes a request and sends it as a message. Shortly after, knowing nothing of P2’s request, P1 sends a request of its own.

The houses have agreed on a fair rule: whichever request was placed first must be filled first. So House 3 has to figure out which request was written earlier. The most obvious way is simply to see whose messenger reaches the gate first.The processes have agreed on a fair rule: whichever request was made first must be granted first. So P3 has to figure out which request was made earlier. The most obvious way is simply to see whose message arrives first.

Looking out from inside House 3's dim gate passage under its ceiling beams: in the bright opening two messengers stand under the portico holding out their slips, a loader leans in the passage at the left, and the harbour with a moored boat lies beyond

The gate of House 3 who gets there first?The inbox of P3 which arrives first?

In this scene, House 2 always writes its request first. Choose whose messenger has the quicker legs.In this scene, P2 always sends its request first. Choose which message is delivered more quickly.

Judging by who reaches the gate first simply rewards whichever house hired the faster runner, regardless of who actually wrote their request first. House 3 might instead ask each house to write the time on its slip. That fails too: it would only compare readings from two indoor water-clocks that were never synchronized. Every obvious way of settling who came first relies on a shared clock that the island does not have.Judging by which message arrives first simply rewards whichever request travelled over the faster route, regardless of which was actually made first. P3 might instead ask each process to write the time on its message. That fails too: it would only compare readings from two physical clocks that were never synchronized. Every obvious way of settling which came first relies on a shared clock that the system does not have.

Yet the houses do not need to give up on fairness. They have been asking a question that nobody on Arche can answer (what happened first under the sun), while right beside it lies a simpler, more practical question that every house can answer.Yet the processes do not need to give up on fairness. They have been asking a question that nobody in the system can answer (what happened first in real time), while right beside it lies a simpler, more practical question that every process can answer.

A simpler question

What could have influenced what

The simpler question came from the accountants of the three houses, working it out together. Without the sun, no house can tell which of two independent requests happened first in absolute time. Fortunately, fair trade does not need absolute time, it only requires that a request never be filled before an earlier one that could have led to or influenced it.Without a shared clock, no process can tell which of two independent events happened first in real time. Fortunately, fair coordination does not need real time, it only requires that an event never be ordered before an earlier one that could have led to or influenced it.

And on Arche, tracking what could have led to what is completely straightforward, because news only travels by written slip. The accountant boiled this down to three clear rules. One event came before another in exactly these three cases:And tracking what could have led to what is completely straightforward, because processes influence each other only by sending messages. This gives three clear rules. One event happened before another in exactly these three cases:

Rule one

Same house, higher on the scrollSame process, earlier in its log

If two events happen in the same house, the one written higher up on its account scroll came before the one written below it.If two events happen at the same process, the one executed earlier happened before the one executed later.

Rule two

Sending comes before receiving

When one house sends a slip and another house receives that exact slip, sending the slip always came before receiving it.When one process sends a message and another process receives that exact message, the send happened before the receive.

Rule three

Chains of events count

If a first event came before some middle event, and that middle event came before a second, then the first came before the second.If a first event happened before some middle event, and that middle event happened before a second, then the first happened before the second.

Below is a record of one morning's business across all three houses. Click any two entries to see how the three rules tell whether one came before the other.Below is a record of one execution across all three processes. Click any two events to see how the three rules tell whether one happened before the other.

One morning on Arche click two entriesOne execution click two events

Each line follows one house through the morning. Each dot is an entry written on its scroll, and each curved arc is a messenger carrying a slip along the road.Each lane follows one process through the execution, with real time running left to right. Each dot is an event, and each arrow is a message sent from one process to another.

Choose any two dots. Did one come before the other?Choose any two dots. Did one happen before the other?

If none of the three rules connects two events, they are unrelated (or concurrent). That does not mean they happened at the exact same instant. It simply means neither event could have known about or influenced the other, because no chain of messengers connects them. Even if the sun saw one happen before the other, nothing in the houses' records can prove which came first.If none of the three rules connects two events, they are concurrent. That does not mean they happened at the exact same instant. It simply means neither event could have known about or influenced the other, because no chain of messages connects them. Even if real time had one happen before the other, nothing the processes record can prove which came first.

These three rules give us a solid definition of order, but clerks in a busy counting room cannot see all three scrolls at once. They need a simple way to calculate this order on the fly, so the accountant gave every counting room a single rising number.These three rules give us a solid definition of order, but a process cannot see every other process’s log at once. It needs a simple way to calculate this order on the fly, so each process keeps a single counter.

A counter that respects every chain

The tallyLogical clocks

The number is called the tally. Every counting room keeps a tally of its own, writes its current tally on every slip it sends out, and raises the number using two simple rules. Scroll slowly to watch the tallies rise across the morning's work.That counter is called a logical clock. Every process keeps a clock of its own, stamps its current value on every message it sends, and raises it using two simple rules. Scroll slowly to watch the clocks rise across the execution.

House 1's harbour under cloud, seen from the water: at the end of the stone pier the accountant hands a narrow slip to a messenger, the town's white houses and the long portico on the shore behind
1 · Start

The same morning, before numberingThe same execution, before numbering

Here are ten entries across the three scrolls, connected by three messenger slips on the road. None of the entries have a tally number yet.Here are ten events across the three processes, connected by three messages. None of the events has a timestamp yet.

2 · Rule one

Every new entry raises the tallyEvery new event raises the clock

Whenever a house records an entry on its own scroll, including sending a slip, it increases its tally by at least 1.Whenever a process executes an event of its own, including sending a message, it increases its clock by at least 1.

3 · Rule two

The tally rides on every slipThe clock rides on every message

When House 1 sends a slip to House 2, it stamps the slip with its current tally: 2.When P1 sends a message to P2, it stamps the message with its current clock value: 2.

4 · Rule two

The receiver jumps past the slipThe receiver jumps past the message

House 2's tally was at 1 when the slip marked 2 arrived. To make sure receiving gets a higher number than sending, House 2 jumps its tally past the slip to 3 before logging the arrival. A tally never goes backward.P2’s clock was at 1 when the message stamped 2 arrived. To make sure the receive gets a higher number than the send, P2 jumps its clock past the stamp to 3 before recording the receive. A clock never goes backward.

5 · On it goes

Each slip pulls the next house forwardEach message pulls the next process forward

House 3 stood at 2 when it received a slip marked 4, so its entry becomes 5. Later, House 1 stood at 2 and received a slip marked 6, jumping its tally straight to 7.P3’s clock read 2 when it received a message stamped 4, so its event becomes 5. Later, P1’s clock read 2 and received a message stamped 6, jumping its clock straight to 7.

6 · The promise

Along any chain, the numbers strictly rise

Follow the red chain of cause and effect from house to house: 1, 2, 3, 4, 5, 6, 7. Because of the two rules, any event that could have led to another is guaranteed to have a smaller tally.Follow the red chain of cause and effect from process to process: 1, 2, 3, 4, 5, 6, 7. Because of the two rules, any event that could have led to another is guaranteed to have a smaller timestamp.

7 · The catch

A smaller number does not prove a connection

Look at the two circled entries. No chain of slips connects them. Even though House 3's entry happened later in the morning by the sun, it carries 2 while House 2's carries 3. The tally assigns a sequence even where two events had nothing to do with each other.Look at the two circled events. No chain of messages connects them. Even though P3’s event happened later in real time, it carries 2 while P2’s carries 3. The clock assigns a sequence even where two events had nothing to do with each other.

So the tally respects every real chain of slips, but looking at two tally numbers alone cannot tell you whether the events were actually connected or completely unrelated. Our two competing requests for House 3's grain are just such an unrelated pair, and House 3 still needs a fair way to decide which one to fill first.So logical clocks respect every real chain of messages, but looking at two timestamps alone cannot tell you whether the events were actually connected or completely unrelated. Our two competing requests are just such an unrelated pair, and P3 still needs a fair way to decide which one to grant first.

One sequence for everyone

Breaking ties

Even if House 3 knows that two requests are unrelated, it still has to pick one to fill first. To avoid arguments, the houses need a single global sequence that decides between every pair of events, that every house calculates the exact same way, and that never contradicts a chain of slips.Even if P3 knows that two requests are concurrent, it still has to pick one to grant first. To avoid arguments, the processes need a single global sequence that decides between every pair of events, that every process calculates the exact same way, and that never contradicts a chain of messages.

An accountant created one with a simple tie-breaker. The rule of precedence: first compare the tallies, putting the smaller tally first; if the tallies are tied, the lower house number goes first, House 1 before House 2, and House 2 before House 3. Below, six entries reach the three houses in different orders, yet sort into the exact same list.A simple tie-breaker supplies one. The rule of precedence: first compare the timestamps, putting the smaller one first; if the timestamps are tied, the lower process number goes first, P1 before P2, and P2 before P3. Below, six events reach the three processes in different orders, yet sort into the exact same list.

Three houses, six entriesThree processes, six events

House 1's listP1's list
House 2's listP2's list
House 3's listP3's list

Precedence does not discover which of two unrelated requests was written first under the sun, nothing in the houses' scrolls could. Instead, it replaces an unanswerable question with a consistent rule that every house reads the exact same way. And it is fair in the only way the houses can verify: whenever one request could have led to another, they are filled in that exact order, and no house wins simply by hiring a faster runner.Precedence does not discover which of two concurrent requests was made first in real time, nothing in the processes’ logs could. Instead, it replaces an unanswerable question with a consistent rule that every process reads the exact same way. And it is fair in the only way the processes can verify: whenever one request could have led to another, they are granted in that exact order, and no request wins simply by travelling a faster route.

Now that the houses can agree on a single sequence of events without a shared clock, they can tackle a harder test: sharing a storehouse that only one house may use at a time, with no gatekeeper in charge to hand out turns.Now that the processes can agree on a single sequence of events without a shared clock, they can tackle a harder test: sharing a resource that only one process may use at a time, with no coordinator in charge to hand out turns.

Proof · precedence is a total order that preserves cause and effect

Write a → b when event a came before event b, and C(a) for the tally of a. The two rules of the tally guarantee the Clock Condition: if a → b, then C(a) < C(b). For an event a at house i and an event b at house j, we say a precedes b (a ⇒ b) if either (1) C(a) < C(b), or (2) C(a) = C(b) and i < j. Claim. ⇒ is a strict total order, and a → b implies a ⇒ b.Write a → b when event a happened before event b, and C(a) for the timestamp of a. The two rules of the timestamp guarantee the Clock Condition: if a → b, then C(a) < C(b). For an event a at process i and an event b at process j, we say a precedes b (a ⇒ b) if either (1) C(a) < C(b), or (2) C(a) = C(b) and i < j. Claim. ⇒ is a strict total order, and a → b implies a ⇒ b.

  1. Every pair can be compared (Total comparability). Take any two distinct events a and b. If their tallies differ, clause (1) decides which goes first. If their tallies are equal, they cannot have occurred at the same house (since Rule 1 gives every subsequent event at the same house a strictly higher tally). Thus they belong to different houses with different house numbers, and clause (2) decides between them.Every pair can be compared (Total comparability). Take any two distinct events a and b. If their timestamps differ, clause (1) decides which goes first. If their timestamps are equal, they cannot have occurred at the same process (since Rule 1 gives every subsequent event at the same process a strictly higher timestamp). Thus they belong to different processes with different process numbers, and clause (2) decides between them.
  2. No loops (Antisymmetry and transitivity). Ordering events by the pair (C(e), house) is a standard dictionary (lexicographical) order of two numbers, which is always strictly total and transitive.No loops (Antisymmetry and transitivity). Ordering events by the pair (C(e), process) is a standard dictionary (lexicographical) order of two numbers, which is always strictly total and transitive.
  3. Respects cause and effect (Consistency with causality). If a → b, the Clock Condition guarantees that C(a) < C(b). Precedence places a before b by clause (1) alone, without needing the tie-breaker. Hence a → b always implies a ⇒ b.∎
Putting the sequence to work

One storehouse, no gatekeeperOne resource, no coordinator

The island's common storehouse is carved into the rock beside the ring road, and its loading bay is narrow: only one house may load goods inside it at a time.A shared resource belongs to no particular process, and only one process may use it at a time (mutual exclusion).

A gatekeeper at the door who simply let in whoever arrived first would be fooled just like House 3's gate was, because a nearby request can beat an earlier one travelling a longer stretch of road. So there is no gatekeeper. Instead, each house keeps its own waiting list (or queue) of requests, sorted by precedence, and follows five simple rules. Scroll to watch what happens when two houses ask to use the storehouse at once.A coordinator that simply granted access to whichever request arrived first would be fooled just like P3’s inbox was, because a nearby request can beat an earlier one travelling a longer route. So there is no coordinator. Instead, each process keeps its own request queue, sorted by precedence, and follows five simple rules. Scroll to watch what happens when two processes ask to use the resource at once.

1 · Quiet

Three waiting lists, all emptyThree request queues, all empty

Every house keeps a waiting list of its own. Right now, nobody is asking to use the storehouse.Every process keeps a request queue of its own. Right now, nobody is asking to use the resource.

2 · To request

Two houses ask at the same timeTwo processes ask at the same time

House 1 logs a request under its tally of 2, puts it on its own waiting list, and sends copies to both other houses. At the same moment, knowing nothing of this, House 3 does the exact same thing under its own tally, which is also 2.P1 logs a request under its clock value of 2, puts it on its own queue, and sends copies to both other processes. At the same moment, knowing nothing of this, P3 does the exact same thing under its own clock, which is also 2.

3 · Not yet

Being first on your own list is not enoughBeing first in your own queue is not enough

House 3's request currently sits first on House 3's own waiting list, yet House 3 still may not enter the storehouse. An earlier request might still be on the road right now, inside a messenger's pouch.P3’s request currently sits first in P3’s own queue, yet P3 still may not enter. An earlier request might still be in transit right now.

4 · On receiving a request

Every waiting list comes out the sameEvery queue comes out the same

Each house adds the incoming request to its waiting list. Because both tallies tie at 2, House 1's request goes ahead of House 3's by house number, on all three lists.Each process adds the incoming request to its queue. Because both timestamps tie at 2, P1’s request goes ahead of P3’s by process number, in all three queues.

5 · The answer

Each house sends back a replyEach process sends back a reply

Whenever a house receives a request, it advances its tally and sends back an acknowledgment. Every reply is guaranteed to carry a tally higher than 2.Whenever a process receives a request, it advances its clock and sends back an acknowledgment. Every reply is guaranteed to carry a timestamp higher than 2.

6 · To enter

House 1 loads its goodsP1 enters the resource

A house may enter the storehouse only when its request stands first on its list and it has received a slip with a higher tally from every other house. House 1 meets both rules and goes inside. House 3 has heard from everyone too, but stands second on its list, so it waits.A process may enter only when its request stands first in its queue and it has received a message with a higher timestamp from every other process. P1 meets both rules and enters. P3 has heard from everyone too, but stands second in its queue, so it waits.

7 · To release

House 1 finishes upP1 finishes

When House 1 finishes loading, it removes its request from its own waiting list and sends a release slip to both other houses.When P1 finishes, it removes its request from its own queue and sends a release message to both other processes.

8 · On receiving a release

House 3's turnP3’s turn

Each house crosses House 1's request off its list. House 3's request now stands first, and since it has already heard from every other house, it can safely enter.Each process removes P1’s request from its queue. P3’s request now stands first, and since it has already heard from every other process, it can safely enter.

9 · Why it is safe

Never two houses at onceNever two processes at once

House 3 could not enter too early, because to enter it needed a slip from House 1 carrying a tally above 2. On a road where no messenger passes another, that slip could only arrive after House 1's tally-2 request, so House 1's request was already sitting on House 3's list, ahead of its own.P3 could not enter too early, because to enter it needed a message from P1 carrying a timestamp above 2. Since messages between two processes arrive in the order sent, that message could only arrive after P1’s timestamp-2 request, so P1’s request was already sitting in P3’s queue, ahead of its own.

With these rules, the houses safely share a storehouse using an order they all agree on, with no shared clock and no gatekeeper. Still, that order is built entirely from road slips, and a shortcut across the island shows how far it can drift from what the sun actually saw.With these rules, the processes safely share a resource using an order they all agree on, with no shared clock and no coordinator. Still, that order is built entirely from messages, and a channel outside the system shows how far it can drift from what real time saw.

Proof · two houses never use the storehouse at the same timeProof · two processes never use the resource at the same time

Let Ri be the request of house i, and C(Ri) the tally under which it was written. Rule 5 states that house i may enter the storehouse only when Ri stands first in its local queue (ordered by ⇒) and it has received from every other house at least one message carrying a tally strictly greater than C(Ri). Messages between any pair of houses arrive in the exact order sent (FIFO). Claim. No two houses ever hold the storehouse at the same time.Let Ri be the request of process i, and C(Ri) the timestamp under which it was written. Rule 5 states that process i may enter the resource only when Ri stands first in its local queue (ordered by ⇒) and it has received from every other process at least one message carrying a timestamp strictly greater than C(Ri). Messages between any pair of processes arrive in the exact order sent (FIFO). Claim. No two processes ever hold the resource at the same time.

  1. Suppose for the sake of contradiction that House 1 and House 3 are both inside the storehouse at the same time on requests R₁ and R₃. Since precedence is a total order, one request must precede the other; assume R₁ ⇒ R₃.Suppose for the sake of contradiction that P1 and P3 are both inside the resource at the same time on requests R₁ and R₃. Since precedence is a total order, one request must precede the other; assume R₁ ⇒ R₃.
  2. By Rule 5, before House 3 could enter, it must have received from House 1 some message carrying a tally T > C(R₃) ≥ C(R₁).By Rule 5, before P3 could enter, it must have received from P1 some message carrying a timestamp T > C(R₃) ≥ C(R₁).
  3. Because a house's tally only increases over time, House 1 must have sent its request R₁ (at tally C(R₁)) to House 3 before sending any message with the higher tally T. And because no messenger overtakes another on the coastal road, slips from House 1 to House 3 arrive in FIFO order.Because a process’s clock only increases over time, P1 must have sent its request R₁ (at timestamp C(R₁)) to P3 before sending any message with the higher timestamp T. And because messages are FIFO, those from P1 to P3 arrive in the order sent.
  4. Therefore, House 3 must have received R₁ before receiving the message with tally T. Since House 1 is still in the storehouse and has not yet sent a release, R₁ was sitting in House 3's queue when House 3 entered.Therefore, P3 must have received R₁ before receiving the message with timestamp T. Since P1 is still in the resource and has not yet sent a release, R₁ was sitting in P3's queue when P3 entered.
  5. Because R₁ ⇒ R₃, R₃ could not have been first in House 3's queue. This contradicts Rule 5, proving that both houses cannot be inside at once.∎Because R₁ ⇒ R₃, R₃ could not have been first in P3's queue. This contradicts Rule 5, proving that both processes cannot be inside at once.∎
Mount Phyle under cloud seen from out over the sea: the long wooded mountain rising to its summit, a trading town small on the shore at its foot
What the tally cannot seeWhat a logical clock cannot see

Shortcut over the mountainA channel outside the system

The shortcut goes straight over the mountain. A goatherd who knows the smugglers' tracks can scramble across in a couple of hours, with a bit of luck. Of course, the same goatherd might get lost for two days, or never come down at all, which is why no house trusts official business to the mountain path.*That shortcut is a channel outside the system: say, a person who tells a colleague by phone, or a result passed through an external database. It is often fast but unreliable, so no process trusts official business to it.

Still, word of mouth can travel with a goatherd, who carries no official slip. Suppose a trader at House 3 closes a sale after a busy morning and pays a goatherd to carry the news across the mountain to House 1, while the official slip takes the long way around the coastal road.Still, information can travel that way, without any official message. Suppose a user at P3 closes a sale after a busy execution and phones a colleague at P1 with the news, while the official message takes the long way around the network.

A sale at House 3 and a lucky goatherdA sale at P3 and an outside channel

House 3 has had a busy morning (high tally). House 1 has had a quiet one (low tally).P3 has had a busy execution (high clock). P1 has had a quiet one (low clock).

By its own rules, the tally system has done nothing wrong. Its rules only track official slips, and the goatherd carried none. As far as the houses' scrolls can tell, the sale at House 3 and the follow-up request at House 1 are completely unrelated, even though the sale directly caused the request, and ends up with a larger tally number than its own effect!By its own rules, the logical clock has done nothing wrong. Its rules only track official messages, and the outside channel carried none. As far as the processes’ logs can tell, the sale at P3 and the follow-up request at P1 are completely concurrent, even though the sale directly caused the request, and ends up with a larger timestamp than its own effect!

Outside shortcuts like the goatherd are one blind spot of the tally. But the clerk at House 2 has noticed another blind spot, and this one happens right on the coastal road itself.Outside channels are one blind spot of the logical clock. But there is another blind spot, and this one is right on the network itself.

Connected, or made in ignorance?Connected, or independent?

One number for each houseOne number for each process

The clerk of House 2 has a practical doubt that a single tally number cannot settle. The clerk looks at two entries marked 4 and 5. Either the event at 4 led to the event at 5, or each was written in complete ignorance of the other, and with single numbers both possibilities look identical.A practical doubt remains that a single timestamp cannot settle. Look at two events stamped 4 and 5. Either the event at 4 led to the event at 5, or each was made in complete ignorance of the other, and with single numbers both possibilities look identical.

A single counter cannot tell them apart because it squashes everything a house has heard into one number. When House 2 raises its tally past a slip's number, it forgets whose events it just learned about. Remembering that history takes one counter per house. So each house keeps a column of three rows (a vector clock): row by row, it records the latest count of entries it has heard about from House 1, House 2, and House 3. Three rules keep the column up to date:A single counter cannot tell them apart because it squashes everything a process has heard into one number. When P2 raises its clock past a message’s stamp, it forgets whose events it just learned about. Remembering that history takes one counter per process. So each process keeps a vector of three entries (a vector clock): entry by entry, it records the latest count of events it has heard about from P1, P2 and P3. Three rules keep the vector up to date:

Rule one

Count your own entriesCount your own events

Whenever a house logs an entry of its own, including sending a slip, it adds 1 to its own row in the column.Whenever a process executes an event of its own, including sending a message, it adds 1 to its own entry in the vector.

Rule two

Send the whole columnSend the whole vector

Every slip is stamped with the sender's complete three-number column as it stands right after that entry.Every message is stamped with the sender’s complete three-number vector as it stands right after that event.

Rule three

Keep the larger of each rowKeep the larger of each entry

On receiving a slip, a house compares its column with the slip's column, keeps the larger number in each row, and then adds 1 to its own row.On receiving a message, a process compares its vector with the message’s vector, keeps the larger number in each entry, and then adds 1 to its own entry.

The same morning, with columns click two entriesThe same execution, with vectors click two events

The dots show single tallies. Click any two entries to compare their full columns row by row. Try comparing the 2 on House 3's line with the 3 on House 2's.The dots show single timestamps. Click any two events to compare their full vectors entry by entry. Try comparing the 2 on P3’s lane with the 3 on P2’s.

Comparing two columns row by row settles the clerk's doubt completely. One entry came before another if and only if every number in its column is less than or equal to the corresponding row in the other's column (and the two columns are not identical). Two entries are unrelated if and only if one column is larger in one row while the other column is larger in another. Where a single tally could not tell coincidence from cause and effect, the column proves which is which.Comparing two vectors entry by entry settles the doubt completely. One event happened before another if and only if every entry of its vector is less than or equal to the corresponding entry of the other’s (and the two vectors are not identical). Two events are concurrent if and only if one vector is larger in one entry while the other is larger in another. Where a single timestamp could not tell coincidence from cause and effect, the vector proves which is which.

With columns, every connection that travels by slip is laid bare. Only what never went by slip remains unseen, and that brings us back one last time to the goatherd.With vectors, every connection that travels by message is laid bare. Only what never went by message remains unseen, and that brings us back one last time to the outside channel.

Proof · the column detects cause-and-effect and unrelated events exactlyProof · the vector detects cause-and-effect and concurrent events exactly

House i keeps a vector Vi with one slot for each house. Rule 1: on every local event (including a send), it increments Vi[i]. Rule 2: every message carries the sender's vector right after that increment. Rule 3: upon receiving a vector U, house j sets Vj[k] = max(Vj[k], U[k]) for every row k, and then increments Vj[j]. Let V(a) be the vector recorded at event a. We write V(a) ≤ V(b) when every row of V(a) is at most the corresponding row of V(b), and V(a) < V(b) when V(a) ≤ V(b) and the two vectors are not equal. Claim. a → b if and only if V(a) < V(b); consequently, a and b are unrelated (a ∥ b) if and only if neither V(a) ≤ V(b) nor V(b) ≤ V(a).Process i keeps a vector Vi with one entry for each process. Rule 1: on every local event (including a send), it increments Vi[i]. Rule 2: every message carries the sender's vector right after that increment. Rule 3: upon receiving a vector U, process j sets Vj[k] = max(Vj[k], U[k]) for every entry k, and then increments Vj[j]. Let V(a) be the vector recorded at event a. We write V(a) ≤ V(b) when every entry of V(a) is at most the corresponding entry of V(b), and V(a) < V(b) when V(a) ≤ V(b) and the two vectors are not equal. Claim. a → b if and only if V(a) < V(b); consequently, a and b are concurrent (a ∥ b) if and only if neither V(a) ≤ V(b) nor V(b) ≤ V(a).

  1. Forward direction (If a → b, then V(a) < V(b)). If a → b, there is a chain of local events and messages leading from a to b. By Rules 1–3, every step along this chain never decreases any row, and the final step at b strictly increases b's own row. Thus V(a) < V(b).Forward direction (If a → b, then V(a) < V(b)). If a → b, there is a chain of local events and messages leading from a to b. By Rules 1–3, every step along this chain never decreases any entry, and the final step at b strictly increases b's own entry. Thus V(a) < V(b).
  2. Reverse direction (If a ↛ b, then V(a) ≰ V(b)). Suppose a occurs at house i and did not come before b (a ↛ b). Then no chain of slips carrying news of a has reached b. Because row i only increases at house i (by Rule 1) and is only copied to other houses via messages (by Rules 2–3), the value of V(b)[i] can only reflect events at house i that came before b. Since a is not among them, V(b)[i] < V(a)[i], which means V(a) ≰ V(b).Reverse direction (If a ↛ b, then V(a) ≰ V(b)). Suppose a occurs at process i and did not come before b (a ↛ b). Then no chain of messages carrying knowledge of a has reached b. Because entry i only increases at process i (by Rule 1) and is only copied to other processes via messages (by Rules 2–3), the value of V(b)[i] can only reflect events at process i that happened before b. Since a is not among them, V(b)[i] < V(a)[i], which means V(a) ≰ V(b).
  3. Conclusion. Combining both directions shows that a → b if and only if V(a) < V(b), and two events are unrelated (a ∥ b) if and only if neither column is less than or equal to the other.∎Conclusion. Combining both directions shows that a → b if and only if V(a) < V(b), and two events are concurrent (a ∥ b) if and only if neither vector is less than or equal to the other.∎
The goatherd againThe outside channel again

Whose order do the houses keep?Whose order do the processes keep?

Because the three-number column is built solely from official slips, the goatherd escapes it too. Catching outside shortcuts like the goatherd requires numbers that rise along every path in the physical world, slip or no slip, and only physical clocks that tick in step with real time can promise that.Because the three-number vector is built solely from official messages, the outside channel escapes it too. Catching outside channels requires numbers that rise along every path in the physical world, message or no message, and only physical clocks that tick in step with real time can promise that.

In principle, such synchronized physical clocks can be built: each house keeps a steady clock that barely drifts, every slip carries the sender's clock reading, and any house that falls behind nudges its clock forward. As long as the houses' clocks never disagree by more than the goatherd's fastest sprint across the mountain, the goatherd can never arrive at a house at an earlier timestamp than when they set out.In principle, such synchronized physical clocks can be built: each machine keeps a steady clock that barely drifts, every message carries the sender’s clock reading, and any machine that falls behind nudges its clock forward. As long as the clocks never disagree by more than the fastest the outside channel can deliver, a message can never arrive with an earlier timestamp than when it was sent.

On cloudy Arche, however, water-clocks drift and no one can guarantee a maximum travel time for messengers along the road. So the houses rely on the tally and the column, and it is worth stating plainly what each one can and cannot see:In this system, however, physical clocks drift and no one can guarantee a maximum delivery time for messages. So the processes rely on the logical clock and the vector clock, and it is worth stating plainly what each one can and cannot see:

A stone sundial on its pillar on a bare headland under a grey overcast sky, casting no shadow; the cliff edge at the left, scrub and cypresses behind
The tallyLogical clock

Respects every chain of slipsRespects every chain of messages

Gives every house the exact same global sequence using just one number per event, but cannot tell by itself whether two events were connected or unrelated.Gives every process the exact same global sequence using just one number per event, but cannot tell by itself whether two events were connected or concurrent.

The columnVector clock

Reveals every chain of slipsReveals every chain of messages

Distinguishes connected events from unrelated ones with complete precision, at the cost of keeping one number for each house.Distinguishes connected events from concurrent ones with complete precision, at the cost of keeping one number for each process.

Neither

Sees what never went by slipSees what never went by message

Both tools track only the messages inside the system. Matching the order of the outside world requires synchronized physical clocks.

Even without a shared clock, networked machines can agree on a single order of events that never puts an effect before its cause.

A single counter per machine cannot tell related events from unrelated ones, but keeping one counter for every machine can.

Lamport's logical clocks, together with the vector clocks of Fidge and Mattern, remain the foundation for how distributed systems put events in order.

Setting Three Houses Keeping Order

The papers behind this book

The papers behind this book. Leslie Lamport, “Time, Clocks, and the Ordering of Events in a Distributed System,” Communications of the ACM 21, 7 (July 1978), 558–565. Colin J. Fidge, “Timestamps in Message-Passing Systems That Preserve the Partial Ordering,” Proc. 11th Australian Computer Science Conference (1988), 56–66. Friedemann Mattern, “Virtual Time and Global States of Distributed Systems,” Proc. Workshop on Parallel and Distributed Algorithms, North-Holland (1988), 215–226.

Lamport, L. Time, clocks, and the ordering of events in a distributed system. Commun. ACM 21, 7 (1978), 558–565.

Fidge, C. J. Timestamps in message-passing systems that preserve the partial ordering. Aust. Comput. Sci. Commun. 10, 1 (1988), 56–66.

Mattern, F. Virtual time and global states of distributed systems. In Parallel and Distributed Algorithms, M. Cosnard et al., Eds. North-Holland, 1989, pp. 215–226.