CRDT Primer
Conflict-free Replicated Data Types — the foundation of real-time collaboration without a central authority.
A CRDT is a data structure that guarantees eventual convergence across replicas, no matter the order updates arrive. Two users can edit the same document offline, reconnect, and the system merges their changes deterministically — no conflicts, no locks, no rollbacks.
The two families
Op-based
Broadcast operations. Each replica applies the same ops in causal order. Requires reliable exactly-once delivery.
State-based
Send full or partial state. Merge via a commutative, associative, idempotent join. Tolerates duplication and reordering.
Key property: monotonic join
Every CRDT defines a join-semilattice. Merging two states produces a state that subsumes both. For a counter, the join is element-wise max. For a set, it is union with tombstone tracking. The math guarantees that after all messages are delivered, every replica holds the same value.
Common types
- G-Counter — increment-only, merge via per-replica max
- PN-Counter — positive/negative G-Counters, supports decrement
- G-Set — add-only set, union merge
- OR-Set — observed-remove set, tracks unique tags per element
- RGA — replicated growable array for collaborative text editing
Why Meridian uses CRDTs
Meridian's real-time canvas and document layers are built on Yjs — a production-grade CRDT library. Every keystroke, shape move, and property change is a tiny operation that merges deterministically. You get local-first latency with zero-conflict sync, even across spotty connections.
Next: Yjs integration recipe — wire CRDTs into a Next.js app with WebSocket sync.