Notesreplication🌱 seedling
CRDT
Also: Conflict-Free Replicated Data Type · Convergent Replicated Data Type · Strong Eventual Consistency
A data type whose replicas can be updated independently and always merge to the same result, because its merge is commutative, associative and idempotent. Conflicts are resolved by construction, not by application code.
Why it exists
Hand-written sibling merges are error-prone, and Last Write Wins loses data. A CRDT bakes a correct merge into the type, so any replica can accept writes offline and converge later.
How it works
- State-based: replicas exchange whole states and merge (e.g. per-slot max); operation-based: they broadcast operations that commute.
- G-counter: one slot per replica, each replica increments only its own, merge = per-slot max, value = sum. A PN-counter pairs two.
- OR-set (observed-remove): each add gets a unique tag; a remove deletes only the tags it saw, so a concurrent re-add survives.
- Sequence CRDTs give each character a unique ordered ID so concurrent inserts interleave deterministically: collaborative text.
Trade-offs
| Gains | Costs |
|---|---|
| convergence without coordination | metadata (IDs, tombstones, per-replica state) |
| offline and multi-leader friendly | can't enforce invariants (balance ≥ 0, uniqueness) |
| no lost concurrent updates | merge semantics may surprise users |
In practice
- Riak shipped counters (1.4), then sets and maps (2.0); Automerge 3.0 (2025) cut memory use by over 10× by keeping history compressed at runtime.
- Figma uses CRDT-inspired, server-authoritative LWW per property rather than true CRDTs.
Pitfalls
- An LWW register is technically a CRDT: convergent, yet it still drops one of two concurrent writes.
Connections
- Part of
- Write Conflict
- Contrasts with
- Last Write Wins
Recall
These cards are also in your review deck, scheduled with spaced repetition.