M.F. Miller Supply Co.
Back to Interactive Lab
rust-wasmstudio-demosstudio-wasm

Local-First Sync & Conflict Simulator

Lamport logical clocks, field-level auto-merge, and non-destructive conflict preservation across offline household devices in Rust & WebAssembly.

Initializing Rust/WASM…
Loading Rust/WASM synchronization engine…

Why Local-First Sync Cannot Rely on Wall Clocks

In a real household, two devices rarely agree on wall-clock time to the millisecond—and one of them is frequently offline in a basement, grocery aisle, or airplane seat. Relying on naive server timestamps risks silently overwriting a spouse's grocery update or losing a note written offline.

Instead, every operation in this simulator carries a monotonic Lamport logical clock tt and a replica identifier r∈{iphone,mac}r \in {\text{iphone}, \text{mac}}. Whenever a replica generates a local operation, it increments its clock:

tlocal′=tlocal+1t_{\text{local}}' = t_{\text{local}} + 1

Whenever a replica receives a remote operation with timestamp tremotet_{\text{remote}}, it advances its clock past both histories:

tlocal′=max⁡(tlocal,tremote)+1t_{\text{local}}' = \max(t_{\text{local}}, t_{\text{remote}}) + 1

Three Outcomes When Devices Reconnect

  1. Disjoint block edits & additions: Changes to separate blocks or newly added items merge automatically and sort deterministically by (createdLamport,blockId)(\text{createdLamport}, \text{blockId}).
  2. Orthogonal field edits on the same block: Text content and completion state carry independent field clocks. Checking off an item on Pocket iPhone while refining its wording on Kitchen Mac merges cleanly with zero conflict.
  3. Concurrent edits to the same text revision: When both replicas rewrite the same block from the same base revision, a total order over (t,r)(t, r) selects the canonical text identically on both devices—while the losing revision is preserved inline as a Conflict Copy so nothing written by a family member is ever silently erased.

After reconciliation, both devices compute an FNV-1a 64-bit fingerprint over their canonical block state. Matching fingerprints confirm exact byte-for-byte convergence without a central coordinator.