Sweaty Imposter

CRDT (Conflict-Free Replicated Data Type)

TechniqueDistributed SystemsSeniorStaffUpdated
Data types whose merge function is commutative, associative, and idempotent, so any two replicas converge to the same value without coordination.

When to Use CRDT (Conflict-Free Replicated Data Type)

Collaborative editing, offline-first apps, shopping carts, presence counters. When you need multi-writer convergence without server-side conflict resolution.

In Practice

Redis CRDTs (Enterprise active-active), Riak data types (counters, sets, maps), Automerge / Yjs in Figma and Linear-style editors, Apple Notes sync.

Sketch

Python

# G-Counter (grow-only CRDT counter)
class GCounter:
    def __init__(self, node): self.node = node; self.counts = {}
    def inc(self):
        self.counts[self.node] = self.counts.get(self.node, 0) + 1
    def value(self):
        return sum(self.counts.values())
    def merge(self, other):  # commutative, idempotent
        for n, v in other.counts.items():
            self.counts[n] = max(self.counts.get(n, 0), v)

How CRDT (Conflict-Free Replicated Data Type) Comes Up in Interviews

Scenario

Mobile app lets users add to cart offline on multiple devices. When devices reconnect, both sets of items must end up in the cart without losing any.

A CRDT (specifically an OR-Set or 2P-Set) merges concurrent edits by construction: union the adds, respect the removes, and any pair of replicas converges. The original Dynamo paper used exactly this for Amazon's cart.

G-Counter, PN-Counter, OR-Set, LWW-Element-Set, and RGA (for text) are the building blocks. Yjs and Automerge bundle them for collaborative documents.