Skip to the content.

๐Ÿ”น What is CRDT?

CRDT (Conflict-free Replicated Data Type) is a family of data structures designed so that:

๐Ÿ‘‰ In short: With CRDTs, conflicts canโ€™t happen by design.


๐Ÿ”น Why CRDT?

In distributed systems (or collaborative editing apps like Google Docs, Figma, Notion):

CRDT solves this by making the data structure itself mathematically mergeable.


๐Ÿ”น Types of CRDTs

  1. Counter CRDTs โ†’ Distributed counters (increment/decrement).

    • Example: Like counts in Instagram (everyone tapping โค๏ธ concurrently).
  2. Set CRDTs โ†’ Distributed sets (add/remove elements).

    • Example: Online users list, tags.
  3. Register CRDTs โ†’ Single value that always converges (last-writer-wins).

    • Example: Profile picture updates.
  4. 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:

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


โœ… In summary: CRDT = special data structures for distributed systems where concurrent updates always merge safely, ensuring eventual consistency without conflict.