We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
This idea carries a full system design question on its own. Each walks through the full answer.
System Design Masterclass · Consistency Models
Free preview: the first 2 parts of this 8-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Consistency Models
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
What if your data structure could merge itself automatically, without coordination, and always converge to the correct result? No conflicts. No locks. No . Just mathematics guaranteeing convergence.
CRDTs. Conflict-free Replicated Data Types, are data structures where concurrent updates always merge deterministically. Two replicas can accept writes independently, never communicate, and when they exchange state, they converge. Guaranteed.
The trick is algebraic structure. CRDTs use semilattices, partially ordered sets where every pair has a least upper bound. The merge is commutative, associative, and . These properties mean merging in any order, any number of times, produces the same result.
Redis Enterprise uses CRDTs for active-active geo-. Riak used them extensively. Figma uses CRDTs for collaborative design. Apple CloudKit uses them for cross-device sync.
State-based CRDTs (CvRDTs), replicas exchange their full state and merge it. The merge function must be commutative, associative, and .
Operation-based CRDTs (CmRDTs), replicas exchange operations. Delivery must be reliable and causal, but operations are commutative.
| CRDT Type | Operations | Merge Strategy |
|---|---|---|
| G-Counter | Increment only | Max per node |
| PN-Counter | Increment and decrement | Two G-Counters (pos, neg) |
| G-Set | Add only | Set union |
| OR-Set | Add and remove | Tag-based (observed remove) |
| LWW-Register | Set value | Keep highest timestamp |
| LWW-Map | Set key-value pairs | LWW per key |
G-Counter example: Each of N nodes maintains its own counter. To increment, a node increments only its own entry. To read the total, sum all entries. To merge, take the element-wise maximum. Concurrent increments never conflict because each node writes to a different position.
The metadata overhead: A G-Counter for 1000 nodes carries 1000 integers. An OR-Set carries unique tags for every add operation. CRDTs trade metadata size for coordination freedom.