CRDTs for Conflict-Free Replication: Mathematics Prevents Data Conflicts
ScaleDojo
•
May 11, 2026
•
2 min read
•426 words
Figma: 10 Million Designers, Zero Merge Conflicts
When two designers edit the same Figma file simultaneously from different continents, their changes merge automatically - no conflicts, no 'your version vs their version' dialog. Figma achieves this using CRDTs (Conflict-free Replicated Data Types), mathematical data structures that guarantee any two replicas will always converge to the same state, regardless of the order updates arrive. Apple Notes, Redis Enterprise, and Riak all use CRDTs for the same reason: coordination-free convergence.
Why Regular Data Structures Break
The Concurrent Update Problem:
Counter = 10 (replicated to Server A and Server B)
Server A: counter += 1 -> counter = 11
Server B: counter += 3 -> counter = 13
(both happen concurrently, no coordination)
Merge? What is the correct value?
- Last-Write-Wins: 11 or 13 (one increment lost)
- Max: 13 (Server A's increment lost)
- Neither is correct! Answer should be 14 (10+1+3)
G-Counter CRDT Solution:
Each replica maintains its own count vector:
Server A: {A: 0, B: 0} -> {A: 1, B: 0}
Server B: {A: 0, B: 0} -> {A: 0, B: 3}
Merge: take MAX of each entry:
{A: max(1,0), B: max(0,3)} = {A: 1, B: 3}
Global count = sum of all entries = 1 + 3 = 4
Plus original 10 = 14. Correct!
This works because:
- Commutative: A merge B = B merge A
- Associative: (A merge B) merge C = A merge (B merge C)
- Idempotent: A merge A = A
CRDT Types for Different Use Cases
CRDT Catalog:
Type Use Case How It Works
---------------- ------------------- --------------------------
G-Counter View counts, likes Per-replica counter, sum all
PN-Counter Up/downvotes Two G-Counters (P minus N)
LWW-Register User profile fields Timestamp wins on conflict
G-Set Tag collections Add-only set, union to merge
OR-Set Shopping cart Add/remove with unique IDs
(Observed-Remove) per operation
RGA Collaborative text Unique ID per character,
(Replicated editing position-based insertion
Growable Array)
Real-world usage:
- Figma: custom CRDTs for vector graphics
- Apple Notes: CRDTs for multi-device sync
- Redis Enterprise: CRDT counters and sets
- Riak: native CRDT maps, sets, counters
- SoundCloud: CRDT sets for playlist sync
Interview Tip
CRDTs are the answer when asked 'how do you handle concurrent writes without coordination?' Show the G-Counter example to demonstrate the core idea: each replica tracks its own state, merge takes element-wise MAX, global value is the sum. The key trade-off: CRDTs only work for data types where operations are commutative, associative, and idempotent. Arbitrary operations (like 'set value to X') need LWW or consensus instead.
New levels, features, and one concept worth knowing - straight to your inbox.
Enjoyed this content?
Your support keeps us creating free resources
We put a lot of hours into researching and writing these guides. If it helped you, consider buying us a coffee. Every bit goes toward keeping ScaleDojo's content free and growing.
$
One-time payment via Stripe. ScaleDojo account required.