A magical sketchpad shared by artists around the world. Each artist has their own copy, draws whenever inspiration strikes, and somehow - without talking to each other, without a master artist coordinating - all their sketches eventually combine into one harmonious drawing. No fights over who drew what, no erased work, no conflicts. That’s CRDTs: data structures that let everyone work independently while guaranteeing they’ll eventually agree, like artists who can’t step on each other’s brushstrokes.
The Traditional Shared Canvas Problem
Five artists trying to collaborate on one painting, but they’re in different cities, each with their own canvas.
The Phone Coordination Approach
Artist A: “I’m painting a tree in the upper left.” Artist B: “Wait, I just put a cloud there!” Artist A: “Okay, I’ll move my tree to the right.” Artist C: “No! I’m putting a mountain on the right!” Artist D: “Can everyone just freeze for a second?” Artist E: “I already painted a sun where your mountain is going…”
Hours pass. More phone calls than painting. The masterpiece becomes a disaster of coordination overhead.
The Master Artist Approach
They appoint Artist A as the coordinator:
- Everyone sends their additions to Artist A
- Artist A decides what goes where
- Artist A sends back the official version
But now:
- Everything bottlenecks through Artist A
- If Artist A takes a coffee break, work stops
- Artists lose spontaneity waiting for approval
- A single point of failure ruins everything
The Conflict Resolution Nightmare
They try working independently and merging later:
Artist B’s canvas: Beautiful sunset with birds Artist C’s canvas: Night scene with stars Merge attempt: Day? Night? Dusk? Dawn? Birds flying in darkness?
Someone has to decide. Feelings get hurt. Art gets compromised.
Enter the Magical Sketchpad (CRDTs)
Now imagine each artist has a special sketchpad with magical properties:
This diagram requires JavaScript.
Enable JavaScript in your browser to use this feature.
The magic: Every addition is preserved. Nothing conflicts. Order doesn’t matter.
Types of Magical Sketchpads
The Grow-Only Sketchpad (G-Set)
Rules: You can only add, never erase.
Artist A adds: “Red circle” Artist B adds: “Blue square” Artist C adds: “Green triangle”
Final picture: Red circle + Blue square + Green triangle
Even if they add in different orders on their local sketchpads, the final result is identical. It’s like a collage where everyone’s contributions stick permanently.
The Add-Remove Sketchpad (2P-Set)
Two layers: “Added” and “Removed”
Artist A: Adds “tree”, later removes “tree” Artist B: Adds “house” Artist C: Adds “tree” (not knowing A removed it)
Final state:
- Added set: {tree, house, tree}
- Removed set: {tree}
- Visible: {house}
Once removed, always removed. You can’t un-erase. This prevents resurrection conflicts.
The Counter Sketchpad (G-Counter)
Each artist has their own counting section:
Tracking “brush strokes used”:
- Artist A’s count: 45
- Artist B’s count: 30
- Artist C’s count: 25
- Total strokes: 100
Each artist only increments their own counter. Total is always the sum. No conflicts possible.
The Advanced Counter (PN-Counter)
Two counters per artist: additions and subtractions
Artist A: +50 strokes, -5 (mistakes erased) Artist B: +30 strokes, -2 Artist C: +25 strokes, -0 Total: (50+30+25) - (5+2+0) = 98 strokes
Still no conflicts. Each artist tracks their own additions and subtractions.
The Observable Timeline (OR-Set)
Each element gets a unique timestamp:
Artist A at 9:00: Add “bird#A1” Artist B at 9:01: Add “bird#B1” Artist A at 9:02: Remove “bird#A1” Artist C at 9:03: Add “bird#C1”
Final state: {bird#B1, bird#C1}
Each bird has a unique identity. Removes only affect specific instances, not all birds.
The Collaborative Text (RGA)
Artists writing a story together:
Artist A types: “Once upon a time” Artist B inserts: “there was a dragon” (after “time”) Artist C inserts: “brave” (before “dragon”)
The magical sketchpad maintains position relationships:
- “brave” knows it comes before “dragon”
- “dragon” knows it comes after “brave”
- Order preserves even with concurrent edits
Real-World Magical Sketchpads
The Shopping Cart CRDT
Multiple devices, one shopping list:
Phone adds: “Milk” Tablet adds: “Bread” Laptop removes: “Milk” Watch adds: “Eggs”
Eventually, all devices show: {Bread, Eggs}
No matter the network delays or offline periods, everyone converges to the same cart.
The Collaborative Document
Google Docs-style editing:
User A types: “The cat sat” User B adds: “on the mat” User C inserts: “fat” between “The” and “cat”
Result: “The fat cat sat on the mat”
Even if edits happen simultaneously, the document remains coherent.
The Like Counter
Social media post tracking:
Server A: +100 likes Server B: +150 likes Server C: +75 likes
Total likes: 325
Each server counts independently, no coordination needed, eventual consistency guaranteed.
The Mathematics of Magic
CRDTs work because they follow mathematical rules:
Commutative: Order Doesn’t Matter
Drawing A then B = Drawing B then A Like addition: 3 + 5 = 5 + 3
Associative: Grouping Doesn’t Matter
(A + B) + C = A + (B + C) Merge any subsets first, result is the same
Idempotent: Duplicates Don’t Matter
Adding “bird” twice = Adding “bird” once Receiving the same update multiple times is safe
These properties guarantee convergence without coordination.
When CRDTs Shine
Offline-First Applications
Mobile apps that work without internet:
- Make changes offline
- Sync when connected
- No conflicts to resolve
- Everything merges automatically
Collaborative Editing
Multiple users, real-time collaboration:
- No locking needed
- No central coordinator
- Low latency (local edits)
- Automatic merging
Geo-Distributed Systems
Servers across continents:
- Each region operates independently
- No waiting for global consensus
- Eventually consistent
- Partition tolerant
The Tradeoffs of Magic
Space Complexity
CRDTs often use more memory:
- Tombstones for removed items
- Unique identifiers for everything
- Vector clocks or timestamps
- Historical metadata
Traditional set: [“apple”, “banana”] CRDT set: [(“apple”, id1, clock1), (“banana”, id2, clock2), (removed: “cherry”, id3, clock3)]
Semantic Complexity
Some operations don’t have obvious CRDT solutions:
- “Move” operations (vs. delete + add)
- Constraints (uniqueness, references)
- Complex invariants
- Business logic validation
Eventual Consistency
“Eventually” might not be fast enough:
- Banking: Need immediate consistency
- Inventory: Can’t oversell
- Reservations: No double-booking
CRDTs provide eventual consistency, not immediate.
Decision Rules
Use CRDTs when:
- Users work offline frequently
- Multiple devices need to sync
- You can tolerate eventual consistency
- Conflict resolution is complex
Don’t use CRDTs when:
- You need immediate consistency
- Storage is severely constrained
- Your operations aren’t commutative
- You need precise control over conflict resolution
CRDTs embody a beautiful principle: Design systems where cooperation is inevitable, not enforced.
Instead of preventing conflicts, make conflicts impossible. Instead of coordination, create structures that naturally converge. Instead of consensus, build agreement into the data itself.
The most elegant distributed systems aren’t those that resolve conflicts brilliantly - they’re those that make conflicts impossible. CRDTs offer a path to this elegance, where every participant can contribute freely, work independently, and trust that their contributions will merge into a consistent whole.
The sketchpad is magical not because it chooses whose art is better, but because it finds a way for all art to coexist.