watershed Collaborative data structures for Gleam

← Maps · SharedDirectory

Folder identity
survives the race.

SharedMap resolves a flat set of keys. SharedDirectory is the recursive version: a map at every node plus named child folders, modeled after Fluid Framework’s design. The hard part is hierarchical identity, not storage. A folder can be created by two clients at once, deleted, and recreated under the same path, and every replica must still agree on which folder is which. watershed’s directory_kernel models that identity explicitly and converges.

A shared folder tree, live

Three watershed documents share one SharedDirectory, a recursive SharedMap where every folder holds its own key/value readings and a set of named child folders. One client creates it and shares the handle; the others resolve it. They talk to one sluice, the in-memory server that ships in the library. It runs the production client runtime without a network backend. Local edits are drawn in magenta until the sluice stamps them; server-sequenced state is ink.

Add folders and readings on any client, delete a folder, or press Race the same folder: all three clients create /kettle-run at the same instant. The three ops merge into a single folder (whose creator set records every author), rather than duplicating. That hierarchical-identity merge is exactly what a flat map can’t do, and it survives delete-then-recreate races too.

Client A

0 pending

Client B

0 pending

Client C

0 pending
Sequencer SN 0

    Converged all trees identical · nothing pending

    Latency and jitter affect simulated arrival order; animation speed changes playback only.