watershed Collaborative data structures for Gleam

← watershed · Data structures / Coordination

Coordination

Deciding who owns what, and agreeing before acting.

The last family arbitrates decisions rather than merging values: who holds a resource, who runs a task, what everyone has agreed to. Reads here are often non-optimistic, because showing an outcome you might lose is worse than showing nothing.

They ascend from first-writer-wins ownership through versioned registers, FIFO queues, and task failover to a quorum-consensus map that will not commit a value until every required client signs off.

Skip past the interactive demo

Watch coordination converge

The structures from this family that fit the shared gauge rig run below on watershed’s Gleam kernels. Structures with dedicated interactions link to their own demos. Pending edits print in magenta; once the sequencer stamps an SN, every replica lands the same ink state. The picker switches among the loaded views, which share one ordered stream.

Nudge a value, race a concurrent write, or stretch the link latency to watch each merge rule hold.

  1. 1 · local edit prints in magenta
  2. 2 · the sequencer stamps it with an SN
  3. 3 · every client lands the same ink state
Data structure shown in all clients

Merge rule: first writer wins. A claim commits only if the slot is still unclaimed when the sequencer stamps it (or its reference SN matches the holder’s exactly). Nothing prints optimistically: a filed claim is invisible, even to you, until it round-trips as won or lost.

Client A

0 pending
Shared map replica on Client A
mill-race 24
kettle-run 61
low-ford 42
sandbags-placed 120
earthwork-balance · yd³ +44
fill Σ
74
cut Σ
30
inspection-count 18
A Σ
0
B Σ
0
C Σ
0
Claims replica on Client A
north-levee
spillway-gate
pump-house Survey
OR-map stockpile ledger replica on Client A
spoil-north 18
borrow-pit-7 -6
wash-fill 12
OR-set field marker roster replica on Client A
north-stake marked
sluice-tag marked
borrow-flag clear
G-set permanent benchmark registry replica on Client A
BM-17 recorded
BM-22 unrecorded
BM-31 unrecorded
2P-set retired marker ledger replica on Client A
stake-3 active
gate-pin unplaced
silt-flag retired
RegisterCollection replica on Client A
register atomic LWW revise
north-bench Survey Survey
gate-setpoint
pump-mode
OrderedCollection replica on Client A
sheet state op
queue grade-stakes, pump-check
held jobs none
PactMap replica on Client A
pact accepted pending op
datum-grid Survey datum
gate-policy
inspection-window
TaskManager replica on Client A
task assigned waiters op
sluice-inspection empty
pump-watch empty
crest-walk empty

Client B

0 pending
Shared map replica on Client B
mill-race 24
kettle-run 61
low-ford 42
sandbags-placed 120
earthwork-balance · yd³ +44
fill Σ
74
cut Σ
30
inspection-count 18
A Σ
0
B Σ
0
C Σ
0
Claims replica on Client B
north-levee
spillway-gate
pump-house Survey
OR-map stockpile ledger replica on Client B
spoil-north 18
borrow-pit-7 -6
wash-fill 12
OR-set field marker roster replica on Client B
north-stake marked
sluice-tag marked
borrow-flag clear
G-set permanent benchmark registry replica on Client B
BM-17 recorded
BM-22 unrecorded
BM-31 unrecorded
2P-set retired marker ledger replica on Client B
stake-3 active
gate-pin unplaced
silt-flag retired
RegisterCollection replica on Client B
register atomic LWW revise
north-bench Survey Survey
gate-setpoint
pump-mode
OrderedCollection replica on Client B
sheet state op
queue grade-stakes, pump-check
held jobs none
PactMap replica on Client B
pact accepted pending op
datum-grid Survey datum
gate-policy
inspection-window
TaskManager replica on Client B
task assigned waiters op
sluice-inspection empty
pump-watch empty
crest-walk empty

Client C

0 pending
Shared map replica on Client C
mill-race 24
kettle-run 61
low-ford 42
sandbags-placed 120
earthwork-balance · yd³ +44
fill Σ
74
cut Σ
30
inspection-count 18
A Σ
0
B Σ
0
C Σ
0
Claims replica on Client C
north-levee
spillway-gate
pump-house Survey
OR-map stockpile ledger replica on Client C
spoil-north 18
borrow-pit-7 -6
wash-fill 12
OR-set field marker roster replica on Client C
north-stake marked
sluice-tag marked
borrow-flag clear
G-set permanent benchmark registry replica on Client C
BM-17 recorded
BM-22 unrecorded
BM-31 unrecorded
2P-set retired marker ledger replica on Client C
stake-3 active
gate-pin unplaced
silt-flag retired
RegisterCollection replica on Client C
register atomic LWW revise
north-bench Survey Survey
gate-setpoint
pump-mode
OrderedCollection replica on Client C
sheet state op
queue grade-stakes, pump-check
held jobs none
PactMap replica on Client C
pact accepted pending op
datum-grid Survey datum
gate-policy
inspection-window
TaskManager replica on Client C
task assigned waiters op
sluice-inspection empty
pump-watch empty
crest-walk empty
Sequencer SN 0

    Loading booting watershed kernels…

    Latency and jitter affect simulated arrival order; animation speed changes playback only. “Ops in flight” counts every hop still travelling: one client → sequencer leg, then one sequencer → replica leg per client.

    Claims

    DDS
    claims_kernel

    First come, first served ownership of named slots (no takebacks).

    A claims register assigns exclusive ownership of named slots. The first client whose claim is sequenced becomes the holder; every later claim is refused against the sequenced holder and its reference sequence number.

    Reads are non-optimistic by design: a filed claim never shows as the holder until it wins, so the UI can never display a claim you might lose. Magenta annotates only the in-flight claim. There is no unclaim op; releasing means tearing off a fresh sheet.

    Best for

    • Exclusive resource ownership: locks, seat or room assignment, leader election
    • Uniqueness constraints (one owner per key, arbitrated by the server)
    • ‘First one wins, no takebacks’ allocation
    Merge rule
    the first client to claim a slot owns it; every later claim is refused
    Optimistic behavior
    a claim only shows as yours once it has actually won, never before
    Summary shape
    who owns what reloads intact
    Model
    Distributed data structure: converges by server order

    RegisterCollection

    DDS
    register_collection_kernel

    Single-value cells you can read as first-writer-wins or most-recent-wins.

    A register holds a single value with two read strategies. An atomic read resolves the first non-concurrent writer (a consensus-flavored pick). A last-write-wins read returns the most recent version by sequence number.

    Concurrent versions are retained with their sequence numbers, so either policy can be applied at read time. Writes stay invisible until sequenced, then resolve as atomic winners or as retained versions.

    Best for

    • Single-value cells that need a choice of conflict policy per read
    • Config or setpoint values where you sometimes want first-writer, sometimes latest
    • A coordination building block where retained versions matter
    Merge rule
    read the first uncontested write, or the most recent one (your choice, per read)
    Optimistic behavior
    writes stay hidden until confirmed, then settle as the winner or a kept version
    Summary shape
    every competing version is kept, so either read rule still works later
    Model
    Distributed data structure: converges by server order

    OrderedCollection

    DDS
    ordered_collection_kernel

    A shared queue where the first client to grab an item holds it.

    An ordered collection is a shared FIFO queue. Items are added, and clients acquire (dequeue) them; add, acquire, complete, and release are non-optimistic and resolve strictly in sequence order.

    When two clients race to acquire the same item, the first sequenced acquire holds it and the second resolves empty. The server order is the sole arbiter, so an item is never double-held.

    Best for

    • Work queues and job dispatch with exactly-one-owner semantics
    • Turn-taking and ordered task handoff between collaborators
    • Anything needing deterministic FIFO ordering across clients
    Merge rule
    items come out in the order the server received them; first to grab one holds it
    Optimistic behavior
    queue changes stay hidden until the server confirms them
    Summary shape
    the queue and who holds what reload intact
    Model
    Distributed data structure: converges by server order

    TaskManager

    DDS
    task_manager_kernel

    Task assignment with a volunteer queue and automatic failover.

    TaskManager builds on ordered semantics to coordinate who does what. Clients volunteer for named tasks; the first sequenced volunteer is assigned and later volunteers queue behind them in sequence order.

    If the assignee drops, the next queued volunteer takes over automatically. It is the coordination primitive for dividing exclusive work across an unreliable set of collaborators.

    Best for

    • Distributing exclusive tasks across peers (leader-per-task, sharded work)
    • Failover assignment where a backup should take over automatically
    • Collaborative apps dividing responsibilities across clients
    Merge rule
    the first client to volunteer gets the task; the rest wait in line
    Optimistic behavior
    volunteering only shows once it’s confirmed; one client wins and the rest queue
    Summary shape
    assignments and the waiting list survive reconnect
    Model
    Distributed data structure: converges by server order

    PactMap

    DDS
    pact_map_kernel

    A map where a value takes effect only after everyone required agrees.

    A pact map is the strongest coordination structure here: it reaches agreement before committing. Proposing a value and sequencing that set freezes the list of clients who must sign off, and each connected client auto-submits the accept ops it owes.

    The value becomes accepted only once the signoff list drains. Concurrent proposals for the same pact resolve to the first sequenced one; the competitor is dropped. The design is modeled after Fluid’s quorum-consensus primitive.

    Best for

    • Agreement before action: schema upgrades, feature-flag flips everyone must honor
    • Config that must be consistent across all clients before it takes effect
    • Decisions requiring explicit quorum rather than last-write-wins
    Merge rule
    a value takes effect only once every required client has signed off
    Optimistic behavior
    a pending proposal blocks competing ones until it’s accepted or dropped
    Summary shape
    accepted values and pending sign-offs save and restore together
    Model
    Distributed data structure: converges by server order