๐น What is CRDT?
CRDT (Conflict-free Replicated Data Type) is a family of data structures designed so that:
- They can be replicated across multiple nodes.
- Updates can happen independently and concurrently.
- When changes are merged, they always converge to the same result โ without needing a central server or transformation rules.
๐ In short: With CRDTs, conflicts canโt happen by design.
๐น Why CRDT?
In distributed systems (or collaborative editing apps like Google Docs, Figma, Notion):
- Multiple users edit the same data at the same time.
- Network delays mean operations arrive in different orders at different replicas.
- You need eventual consistency โ everyone sees the same state.
CRDT solves this by making the data structure itself mathematically mergeable.
๐น Types of CRDTs
-
Counter CRDTs โ Distributed counters (increment/decrement).
- Example: Like counts in Instagram (everyone tapping โค๏ธ concurrently).
-
Set CRDTs โ Distributed sets (add/remove elements).
- Example: Online users list, tags.
-
Register CRDTs โ Single value that always converges (last-writer-wins).
- Example: Profile picture updates.
-
Sequence CRDTs โ Ordered list (for collaborative text editing).
- Example: Each character gets a unique ID so insertions/deletions merge consistently.
๐น Example
Document = "hello"
๐ฉ User A inserts "X" at position 0.
๐จ User B inserts "Y" at position 5.
In a CRDT sequence:
"X"might get an ID like(0, A)"Y"might get an ID like(5, B)
Even if operations arrive in different orders, merging the IDs produces the same final string: "XhelloY".
No need to transform operations like in OT.
๐น CRDT vs OT
| Aspect | OT (Operational Transformation) | CRDT (Conflict-free Replicated Data Type) |
|---|---|---|
| How it works | Adjusts operations on-the-fly to avoid conflicts | Data structure itself guarantees merge without conflict |
| Server | Usually requires a central server to order ops | Works decentralized (peer-to-peer friendly) |
| Complexity | Complex transform rules (insert vs delete, etc.) | Simpler merges (mathematically defined) |
| Performance | Lower network overhead (since only ops are sent) | Can be heavier (more metadata per element) |
| Used in | Google Docs (classic) | Figma, Automerge, Yjs, Riak DB |
๐น Real-world Analogy
- OT = Referee watches everyoneโs moves and fixes conflicts live.
- CRDT = The game rules are designed so conflicts simply canโt happen, no referee needed.
โ In summary: CRDT = special data structures for distributed systems where concurrent updates always merge safely, ensuring eventual consistency without conflict.