Structures

Complexity Advanced

RegisterMap

The ranger station returns. Each notebook now holds several named lines: trail status, radio channel, gate code. Alice and Bob submit conflicting trail reports without seeing each other, while Carol changes the radio channel. The ranger numbers all three writes, and the conflict on one line does not disturb the others.

Two bookmarks reach different stamped gate reports retained in separate layers of one file drawer.

One shared record, several independent lines

A RegisterMap stores a register under each key. A trail application can keep trail-status, radio-channel, and gate-code in one structure while the kernel resolves writes for each key separately.

This matters when a client can submit a write from an old view. A normal last-writer-wins map would let any later-sequenced write replace the earlier value. RegisterMap can retain that later write without treating it as the accepted answer. A reader can ask for one of two values. The atomic value is the accepted answer: a write replaces it only if its writer had seen it. The latest value is the most recently numbered write.

The sequence numbers record what a writer knew

Each write carries a reference sequence number: the last accepted sequence number that the writer had observed. The sequencer then gives the write its own sequence number. These two numbers let the kernel distinguish a newer informed write from a later-arriving stale write.

Write Last sequence seen at submit Assigned sequence Atomic read Latest read
Alice: trail-status = Trail open01Trail openTrail open
Bob: trail-status = Trail closed02Trail openTrail closed
Carol: radio-channel = Channel 403Channel 4Channel 4
Carol: trail-status = Inspect bridge34Inspect bridgeInspect bridge
The two read columns apply to the key in that row. A conflict on trail-status does not affect radio-channel.

Alice's write creates the atomic value at sequence 1. Bob's write arrives later, but its reference is still 0. It becomes the latest version at sequence 2, but it cannot replace the atomic value. Carol's radio update creates a separate register under another key.

After Carol has observed sequence 3, she can submit Inspect bridge for trail-status. Her reference covers the current atomic winner, so the write at sequence 4 becomes both the atomic and latest value. The kernel also removes the older versions that Carol had observed.

Several named station lines

Protect one line while another changes

Alice and Bob race stale trail reports while Carol updates radio-channel. Then Carol submits a caught-up trail-status write.

Conflict rule Atomic changes when a writer has seen its current winner; latest uses the greatest sequence number.

Alice

No status received

No lines

Field note trail-status: Trail open last sequence seen: 0

Bob

No status received

No lines

Field note trail-status: Trail closed last sequence seen: 0

Carol

No status received

No lines

Field note radio-channel: Channel 4 last sequence seen: 0

Ranger sequencer Assigns sequence numbers 0 writes shared

Decision evidence No sequenced versions yet.

  1. No writes shared yet.

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

Race two unconfirmed trail reports while Carol updates another line.

The reader must choose a policy

Which read to use depends on the application. An atomic read protects an accepted answer from writers who never saw it. A latest read shows the most recent report, even a stale one.

RegisterMap is closest in shape to a map of registers, but its reference sequence number adds conditional-write behavior. Neither read policy merges values or exposes causal siblings like an MvRegister.

The ranger station must be reachable

This is a sequenced distributed data structure, not a CRDT. If the sequencer is unavailable, new writes cannot receive the ordering evidence that both read policies require.

The next lesson, SharedMap, keeps the ranger station but uses one simple rule: the last numbered change to each line wins.

Sources and implementation

Sources: Watershed's register_collection_kernel defines sequenced writes and atomic and latest read policies.

Implementation: The demo calls the Watershed kernel through the site's Gleam toolkit, which numbers the writes in place of the ranger station.