Partial order

Territory: Mechanisms

Follow causal paths without forcing independent events into a shared sequence.

Complexity Intermediate 6 min read Lab available

A report envelope lies between two trail rocks; a third rock holds a separate notebook with no connecting message.

An earlier click does not send information

Alice (A) writes a trail report and sends a copy to Bob (B). While the message waits, Carol (C) writes a separate report and sends no message to Alice or Bob. Then Bob receives Alice’s message.

Bob learns about Alice’s report. Bob has no news of Carol’s report, even though you clicked Carol’s control before delivering the message to Bob.

As in Local history, each hiker stands for a replica: a computer with its own record. Hikers learn about events at other replicas only through messages. Your clicks do not give them a shared record.

Follow the arrows

The lab uses short names for these events:

  • a1: A writes its report.
  • b1: B receives A’s message.
  • c1: C writes its report.

An arrow connects an event to one that follows it. A’s report comes before B receives the copy, so the lab shows a1 -> b1. No arrow connects c1 to either event.

The lab calls an arrow an edge. A path is one or more arrows that you follow in their direction. A path shows how information could pass between events.

Alice (A)
A includes a1 in message m1 for B.
Bob (B)
B receives m1 as b1. The lab records a1 -> b1.
Carol (C)
c1 has no edge to or from either event.
The order of these rows adds no arrows. Neither A nor B has learned about c1 in this run.

A partial order records which events must come before others. Some pairs have no order between them. Here, a1 must come before b1, but there is no path between c1 and b1 in either direction.

We call this ordering rule happens-before:

  1. At one replica, an earlier event happens before a later event.
  2. Sending a message happens before receiving that message.
  3. You can follow a chain of these connections. If one event comes before a second, and the second comes before a third, the first comes before the third. The name for this rule is transitivity.

As in Local history, the lab records the send action without a separate event name. The arrow a1 -> b1 includes A writing the report, sending it, and B receiving it. Sending counts as an event in the full happens-before model.

A path shows that information could pass between events. The application need not use that information. B might receive A’s report and then do an unrelated calculation. The receive still happens before that calculation.

Compare three pairs of events

Use Guided run and its Next: button for these five steps. Choose Reset lab first if you have used other controls.

  1. Record a1 at A.
  2. Send m1 from A to B. B has not received anything yet.
  3. Record c1 at C. C sends no message.
  4. Deliver m1. B records the receive as b1 and learns about a1.
  5. Compare a1 / b1, b1 / c1, and c1 / c1.

Before step 5, look for a path in each pair. Also check whether both names refer to the same event.

Step 5 adds results without creating an event or sending a message. Read all three results in Lesson controls. The Event comparison panel shows only the last pair, c1 / c1.

Without JavaScript, the lab shows three empty starting histories. You can follow the example in the figure above and the results below without using the controls.

Complexity Intermediate

Partial order lab

Alice (A)

Visible value
No local values
Local history
No local events
Observed events
No events observed
Predecessors
No predecessors

No events observed

Bob (B)

Visible value
No local values
Local history
No local events
Observed events
No events observed
Predecessors
No predecessors

No events observed

Carol (C)

Visible value
No local values
Local history
No local events
Observed events
No events observed
Predecessors
No predecessors

No events observed

Queued messages

No queued messages

Each replica starts with an empty local history. No messages have been delivered.

Invariant checks

  • Local history is ordered: yes
  • Observed events have causal paths: yes

No path means neither event comes before the other

After delivery, you can follow the arrow from a1 to b1. The message has no record of c1, and C has received nothing from B. You cannot follow a path from b1 to c1 or from c1 to b1.

We call these two different events concurrent. Neither happens before the other. Concurrent events do not have to occur at the same instant. You clicked C’s control first, but no message connected its report to B’s receive.

PairResultEvidence
a1 / b1beforem1 provides a path from a1 to b1.
b1 / c1concurrentNo path in either direction.
c1 / c1equalBoth names identify the same event.
Compare b1 / a1 in the reverse direction to get after. Comparing an event with itself gives equal.

Equal means the same event. Two events with the same value or time are still different events. Concurrent means two different events with no path between them.

Formal note: strict and non-strict partial orders

Happens-before is a strict partial order: an event cannot happen before itself. If you include equality, you get a non-strict partial order. The lab reports equality as a separate result so you can tell “same event” from “comes before.”

To follow a longer path, choose Send from B to C after the guided run. Deliver the new message. It includes what B learned about a1. C’s new receive follows b1, which follows a1. A’s report reaches C through B, without a direct message from A.

C’s earlier event c1 stays concurrent with b1. A later receive does not change what C knew at that earlier event.

Break it: sort the buttons

Suppose you add an arrow from c1 to b1 because you clicked C’s control first. You would claim a connection that did not happen. B received only A’s message.

You can list the events in a single sequence for display. This is a total order: each pair of different events has an order. Each list below puts a1 before b1, as required:

  • a1, c1, b1
  • c1, a1, b1
  • a1, b1, c1

Choosing a list does not add a path between events. To check happens-before, follow the order at each replica and the messages between replicas. An event’s position in a list is not enough.

What a path check assumes

The lab stores the events and their arrows in an event graph. More events need more storage. Following a long path can take more work than checking one arrow.

In this lab, you can inspect the complete record of events and messages. Real logs may have gaps. If a log has no record of a message, someone may still have sent it. Before calling two events concurrent, you need enough information to rule out a path in both directions.

You can see all three hikers’ panels to study the example. Each hiker has only the information from its own events and the messages it receives.

Field notes

Use these rules when comparing two events:

Same event?                  equal
Path from first to second?   before
Path from second to first?   after
Different events, no path?   concurrent

Check for the same event first. Follow arrows in their direction. Two events can both follow an earlier event without a path between them. Sharing that earlier event does not put them in order.

Lamport’s Time, Clocks, and the Ordering of Events in a Distributed System defines happens-before and shows how to extend it to a total order. Choosing an order for display does not create communication between events.

Read Local history for the difference between what happened at a replica and what it knows. Lamport clocks shows how a replica can number events while keeping happens-before order.