watershed Collaborative data structures for Gleam

← watershed · JSON operational transform

One document.
Concurrent edits. One order.

The homepage starts with SharedMap: the server orders its operations, then the map resolves each key by that order. JSON OT also uses a sequencer, but concurrent document operations are transformed against one another instead of resolved per key. watershed’s json_ot kernel is a faithful port of the ottypes json0 algebra with the single-op-in-flight client protocol. Every client edits a shared JSON document optimistically, a central server sequences each op, and concurrent ops are transformed past one another. All replicas reach the same state, indices and all.

Operational transform, live

Three watershed documents share one JSON document over the ottypes json0 algebra with the single-op-in-flight client protocol. 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. Optimistic edits are drawn in magenta; server-sequenced state in ink.

Nudge the gauge.stage reading or flip its trend, rename the site, add or remove a surveyor, reorder the crew, stretch the link latency, then race two inserts at the same index. Ops address any depth: the gauge is nested inside an object, so a bump targets the path .gauge.stage. Numbers add commutatively; a rename is last-writer-by-sequencing; but the crew list is where OT earns its keep. Concurrent inserts have their indices transformed, so every replica converges to the same array (positions and all).

Client A

0 pending
"crew"
    "gauge"
    "stage"24
    "trend"steady
    "site"Mill Race

    Client B

    0 pending
    "crew"
      "gauge"
      "stage"24
      "trend"steady
      "site"Mill Race

      Client C

      0 pending
      "crew"
        "gauge"
        "stage"24
        "trend"steady
        "site"Mill Race
        Sequencer SN 0

          Converged replicas identical · nothing pending

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