Structures

Complexity Introductory

LWWRegister

Alice, Bob, and Carol need one status for the Eagle Creek trail. Alice reports open while Bob reports closed. Carol may receive either report first, but every notebook must choose the same answer.

A stamped closed-gate report in one display clip, with an open-gate report set aside and a mechanical stamp nearby.

What makes a report last?

Alice writes on her trail report. Bob writes on his. A last-writer-wins register compares the timestamp on each report, not the order in which Carol receives them. With those times, she chooses Bob's report even if Alice's note arrives last.

Carol only needs to know which timestamp is greater. The demo shortens the watch times to 1 and 2: Alice's report gets 1 and Bob's gets 2. Each number shows when a hiker wrote the report by their own watch, not whether Bob had seen Alice's report.

WriterValueTimestamp
Alice · ATrail open1
Bob · BTrail closed2
WinnerTrail closed2 is greater
Carol gets the same winner even if the trail delivers Alice's report last.

An LWW register needs no sequencer: writers attach their own timestamps. If two writes have the same timestamp, the greater writer ID breaks the tie, so every notebook chooses the same value.

One trail-status line

Choose one trail report

Alice stamps her report 1 and Bob stamps his 2. Later delivery cannot replace a greater timestamp.

Conflict rule Use the greatest timestamp.

Alice

No status received

No status

Field note trail-status: Trail open timestamp 1 · writer A

Bob

No status received

No status

Field note trail-status: Trail closed timestamp 2 · writer B

Carol

No status received

No status

Field note No note in this race Carol observes delivery

Trail relay Does not choose by arrival order 0 writes shared

Decision evidence No stamped write yet.

  1. No writes shared yet.

Enable JavaScript to run the demo. The race and expected result remain in the lesson.

Race Alice's open report against Bob's closed report.

One answer or both reports?

Start with no report. Alice writes Trail open while Bob writes Trail closed.

Selecting one answer and retaining concurrent alternatives are different policies, not different levels of correctness.

NotebookLWWRegisterMvRegister
Alice empty empty
Bob empty empty
Carol empty empty

Ready: both paths have the same starting input.

Inspect the decision evidence

LWWRegister

Winning timestamp: 0; writer: none.

MvRegister

Current write identities: [[],[],[]]

Enable JavaScript to run the comparison. The starting state and expected lesson remain above.

Two limits

The rule gives every notebook one answer, but it cannot show whether Alice and Bob disagreed. If both reports are valid evidence, choosing a winner discards one of them.

The clock also decides what "last" means. If Bob's watch runs fast, his earlier report can look later and win.

The next lesson, MvRegister, keeps both reports when neither writer saw the other's.

Sources and implementation

Sources: Watershed's LWWRegister kernel defines the timestamp-and-writer comparison. The last-writer-wins register is described in A comprehensive study of Convergent and Commutative Replicated Data Types.

Implementation: The demo calls the Watershed kernel through the site's Gleam toolkit, using integer timestamps. The trail relay carries notes without ordering them.