All projects

Shared editing that survives a broken network

Sync Lab

A collaboration engine, the kind behind Google Docs or Figma, written from scratch. A laptop, a phone and a tablet edit one list over a network you can slow down, break and cut with scissors. The text merges with a CRDT, no Yjs and no Automerge.

Role
Idea, algorithm, network simulation, interface and tests.
Stack
  • TypeScript
  • React 19
  • Vite
  • CRDT
  • fast-check
  • Vitest
  • Motion
Live
sync-lab-oktawian.vercel.appgithub.com/mauupa0/sync-lab-crdt
Sync Lab website

Problem

Shared editing looks simple until two people type in the same spot while packets get lost. I wanted to write the merging myself and prove that every copy always ends up with the same text.

What I built

  • An RGA sequence CRDT: Lamport ids, tombstones for deleted characters and vector clocks.
  • A causal delivery buffer, a duplicate filter and retransmission of whatever the other side has not acknowledged.
  • A simulated network on a virtual clock: delay, loss, duplicates, partitions and a Chaos scenario, repeatable per seed.
  • A three-step story played on the real engine: two people type in the same spot, a cable gets cut, it comes back and nothing is lost. Then the visitor takes over.
  • A replay timeline: devices, cables and vector clocks show any past moment, rebuilt from the operation journal instead of stored snapshots.
  • A Break the algorithm button: it switches the tie-break off in the running engine and shows the copies drifting apart for good, PL against LP.

By the numbers

random edit interleavings, 0 divergent
10,000
Chaos scenarios converged
300/300
tests, including property tests
44
overlapping frames in the button and packet collision test
0

Decisions that mattered

My own CRDT instead of a library

An insert names the character it follows, so colliding edits keep their intent. Concurrent inserts in one spot are ordered by the Lamport counter, and ties by the device id.

Properties instead of examples

fast-check generates thousands of random edit histories delivered in random order with duplicates. Every copy has to end identical, and an insert between two characters has to stay between them.

A negative control that shows the bug

A script removes the device id tie-break. The convergence test fails at once and shrinks the case to two edits: Laptop types L, Phone types P, and the copies end up as PL and LP. Then the script restores the file and checks its hash.