Skip to the content.

CRDT (Conflict-Free Replicated Data Types) – Deep Dive

Overview

CRDTs are data structures designed for distributed systems that allow concurrent updates without requiring coordination or locking, while guaranteeing eventual consistency.
They are widely used in collaborative applications, distributed databases, and edge computing.


1. Key Concepts

Concept Description
CRDT Data type that can be replicated across nodes, allowing conflict-free concurrent updates.
Convergence All replicas converge to the same state, eventually, without coordination.
Commutativity Operations are order-independent; different replicas apply them in any order and still converge.
Idempotency Applying the same update multiple times does not change the outcome.
Eventual Consistency System guarantees that replicas will eventually converge to the same value.

2. CRDT Types

2.1 State-based (Convergent Replicated Data Type – CvRDT)

Example: G-Counter (Grow-only Counter)

Node A: 3
Node B: 2
Merge: max(A, B) = 3+2 = 5

2.2 Operation-based (Commutative Replicated Data Type – CmRDT)

Example: PN-Counter (Positive-Negative Counter)


3. Common CRDT Structures

CRDT Type Description
G-Counter State-based Grow-only counter (only increments)
PN-Counter State-based Counter supporting increments & decrements
G-Set State-based Grow-only set
2P-Set State-based Two-phase set (add/remove with tombstones)
OR-Set State-based Observed-remove set (supports concurrent adds/removes)
LWW-Register State-based Last-Write-Wins register
RGA Operation-based Replicated growable array (text editing)
MV-Register State-based Multi-value register (captures concurrent updates)

4. CRDT Properties

  1. Convergence: All replicas eventually reach the same state.
  2. Commutativity: Merge of operations yields the same result, regardless of order.
  3. Idempotency: Reapplying the same operation/state does not change the final result.
  4. Monotonicity (for state-based CRDTs): State only grows (or progresses) to guarantee convergence.

5. Conflict Resolution in CRDTs


6. Use Cases


7. Advantages


8. Limitations


9. Example: G-Counter

State:

Node A: {A: 3, B: 0, C: 0}
Node B: {A: 0, B: 2, C: 0}
Node C: {A: 0, B: 0, C: 1}

Merge Function: element-wise max

Merged State: {A:3, B:2, C:1} → Value = 3+2+1 = 6

10. Best Practices


References

```