watershed Collaborative data structures for Gleam

← watershed · Build guide / Step 03

Try two edits at once

Add notes from both tabs at the same instant and confirm both appear.

Surface sluice · or_map_set_json · or_map_entries

Add notes from both tabs at once

Open the board in two tabs. In each one, type a different note into Went well and click Add in both at the same moment.

Both notes show up, in both tabs, in the same order. Nothing is lost.

Each note uses a different key

Notes are keyed by note id in an OR-map, so two adds write two different keys — there’s nothing for them to collide over.

Store the board as a plain map keyed by column instead, and you’d get one note back, not two: a map with one key per column has one slot per column, so the second note overwrites the first — that’s what “last write wins” means. Keying by note id means there’s no shared slot to overwrite.

Run the same add on a controlled clock

Two watershed documents connect to the in-memory sluice. Click the add button to send one note from each board at the same time.

Magenta marks an edit that is waiting for the server. Once the server accepts it, the note turns black on both boards. Both notes remain.

Client A

0 pending

Went well

add-wins notes · signed vote tally

1 note

Client B

0 pending

Went well

add-wins notes · signed vote tally

1 note
Sequencer SN 0

    Converged all replicas identical · nothing pending

    Reset restores the starting board.