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.
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.
| Writer | Value | Timestamp |
|---|---|---|
| Alice · A | Trail open | 1 |
| Bob · B | Trail closed | 2 |
| Winner | Trail closed | 2 is greater |
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
Field note trail-status: Trail open timestamp 1 · writer A
Bob
No status received
Field note trail-status: Trail closed timestamp 2 · writer B
Carol
No status received
Field note No note in this race Carol observes delivery
Decision evidence No stamped write yet.
- 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.
| Notebook | LWWRegister | MvRegister |
|---|---|---|
| Alice | ||
| Bob | ||
| Carol |
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.