Wisdom Emmanuel Praise
ADR 06 · Real-time

CRDTs over locks for a shared canvas

Wired merges concurrent edits with Yjs, so nobody waits for anybody.

Context

Several people edit one canvas at the same time, and each should see the others' cursors and changes as they happen.

Options considered

OptionForAgainst
Locks per object (rejected)Easy to reason about.People wait for each other, and a dropped connection can leave an object locked.
Last write wins (rejected)The simplest to build.Concurrent edits silently overwrite one another.
Yjs CRDTs (chosen)Concurrent edits merge without conflicts and without a central arbiter.The document model has to be shaped for Yjs, and its history grows over time.

Decision

Wired uses Yjs (a CRDT) to merge concurrent edits, with Socket.IO and Redis carrying updates between clients.

Consequences

Better

  • Concurrent edits merge without conflicts.
  • Nobody has to wait for anybody else to finish.

Harder

  • The canvas data has to be modelled to fit Yjs.
  • The document's history grows and needs looking after.