Skip to main content
← CONCEPTS / DISTRIBUTED SYSTEMS & STORAGE
An end-to-end domain learning journey

CRDTs & Conflict-Free
Replicated Data.

CRDTs (Conflict-free Replicated Data Types) are replicated data structures whose concurrent updates commute or form a mathematical join-semilattice, guaranteeing every replica converges to the exact same state without coordination or consensus.
Start the journey7 sections· Last modified Oct 23, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When concurrent writes contend on shared state, CRDTs eliminate consensus round-trips for local-first apps and geo-distributed active-active stores by trading coordination latency for metadata overhead (vector clocks, tombstones, or per-element IDs).

TL;DR30-second simplified summary
▾

Core Mechanics: Traditional replication relies on consensus (Raft/Paxos) to agree on a global total order of writes.

Visual & Structural Flow: Depicts Active-Active CRDT Gossip & Semilattice Merge (Replica Mumbai -> Replica Frankfurt -> Replica Virginia -> Converged State); Concurrent Remove & Re-Add Across Partitioned Replicas (Replica R1 -> Async Gossip -> Replica R2); CRDT Element & Causal Compaction State Machine (LIVE ELEMENT -> TOMBSTONED -> COMPACTED).

Trade-Offs & Production: Choose between shipping full state, causal operations, or compact deltas depending on network reliability and object size. In production, CRDTs move through active writes, delta replication, and causal-barrier compaction.

Failure Modes & Application: Compare CRDTs against Raft consensus, multi-master split-brain recovery, and PACELC consistency-latency trade-offs.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Distributed & Application Caching
Caching keeps a reusable copy of data so an application can avoid repeating a database query, calculation, or network call. It can make responses faster and reduce database load. The trade-off: the copy may be out of date.
Full walkthrough · 7 stages
01
STAGE 01 · WHAT IT ISL4 · FUNDAMENTALS

What are CRDTs (Conflict-Free Replicated Data Types).

Why this matters: The mechanism: understand how CRDTs (Conflict-Free Replicated Data Types) works from first principles.

Traditional replication relies on consensus (Raft/Paxos) to agree on a global total order of writes. CRDTs invert the problem: instead of agreeing on when operations happened, design the data structure so order does not matter.

A state-based CRDT (CvRDT) forms a bounded join-semilattice (S, ⊔) whose merge operator ⊔ is associative, commutative, and idempotent (A ⊔ A = A). Any two replicas receiving the same updates—in any order, with any duplicates—mathematically converge to Strong Eventual Consistency (SEC).

Leaderless Convergence

Active-Active CRDT Gossip & Semilattice Merge

Replica MumbaiLocal write 0ms (tag_1)Replica FrankfurtConcurrent write (tag_2)Replica VirginiaMerges R1 ⊔ R2Async delta gossip

Every replica accepts local writes at 0 ms and converges deterministically via associative, commutative, idempotent merges.

02
STAGE 02 · WHY WE NEED ITL4 · FUNDAMENTALS

Why we need CRDTs (and How OR-Sets Prevent Lost Re-Adds).

Why this matters: The problem: see what breaks without CRDTs under real concurrency or scale.

Consensus protocols require 50–150 ms WAN quorum round-trips and stall during network partitions.

Collaborative editors (Yjs, Automerge) and active-active carts need 0 ms local writes—even offline.

OR-Set Add-Wins Merge

Concurrent Remove & Re-Add Across Partitioned Replicas

Replica R1Async GossipReplica R21. Initial: {(milk, tag_1)}; offline2. Remove milk -> tombstone(tag_1)3. Remove tag_1 + re-add (milk, tag_2)4. Ship delta tombstones={tag_1}5. Merge: adds \ tomb = {(milk,tag_2)}

Tagging every add with a unique ID ensures R1's stale remove cannot erase R2's concurrent re-add.

Engineering Decision Framework
Problem
How to implement CRDTs & Conflict-Free Replicated Data without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When concurrent writes contend on shared state, CRDTs eliminate consensus round-trips for local-first apps and geo-distributed active-active stores by trading coordination latency for metadata overhead (vector clocks, tombstones, or per-element IDs).
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When CRDTs & Conflict-Free Replicated Data experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

Real-Time Collaborative Rich Text (Yjs / YATA)

50 concurrent editors type offline/online; Yjs encodes insertions with (clientId, clock) and left/right origin pointers, merging 10,000+ out-of-order updates in <5 ms in-browser.

Active-Active Shopping Cart in Redis Enterprise

Using an OR-Set CRDT with vector clocks across Mumbai and Frankfurt, concurrent add(SKU-A) and remove(SKU-B) merge deterministically after link flaps.

03
STAGE 03 · WHERE IT IS USEDL5 · APPLIED DESIGN

Where CRDTs Shine (and Where Consensus Is Mandatory).

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Think of Where CRDTs Shine (and Where Consensus Is Mandatory) as the intuition layer for CRDTs & Conflict-Free Replicated Data: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

CRDTs guarantee convergence, not human intention or global scarcity invariants.

ChoiceWhat it buysWhat it costs
Use: Local-First Editors, Carts, Counters & Presence0 ms local write latency, offline-first operation, 100% AP availability under partitions.Metadata overhead (vector clocks, tombstones, per-char IDs).
Avoid: Negative Bank Balances & Unique UsernamesUse Raft/Paxos consensus or single-leader serialization for strict global invariants.Two replicas concurrently decrementing a `PN-Counter` from 1 can drive it to -1.
Avoid: High-Churn Delete Sets Without Epoch GCRun causal-barrier compaction or epoch snapshots before tombstones OOM.Aggressive tombstone pruning before offline clients sync causes zombie resurrection.
04
STAGE 04 · HOW IT IS MANAGEDL5 · APPLIED DESIGN

How to manage Replica IDs, HLCs & Tombstone Compaction.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

1.

Unique replicaId: Generate a cryptographically random 64/128-bit clientId per tab/instance—never reuse userId or hostnames. 2. Hybrid Logical Clocks (HLC): Never use raw Date.now() in LWW-Registers; an NTP-skewed client will silently overwrite all newer edits.

Design Trade-Off

How to manage Replica IDs, HLCs & Tombstone Compaction

Before · Seq Scan + Unbounded Bloat
  • Implicit cast breaks B-Tree
  • Deadlock or XID wraparound risk
  • Long tx blocks VACUUM
After · Indexed Plan + Bounded MVCC
  • Index-only scan in <2 ms
  • Deterministic lock ordering
  • Autovacuum keeps bloat flat
# Join-semilattice PN-Counter & OR-Set merge primitives (Python)
class PNCounter:
    def __init__(self, replica_id: str):
        self.id = replica_id
        self.p: dict[str, int] = {}
        self.n: dict[str, int] = {}

    def inc(self, delta: int = 1) -> None:
        self.p[self.id] = self.p.get(self.id, 0) + delta

    def dec(self, delta: int = 1) -> None:
        self.n[self.id] = self.n.get(self.id, 0) + delta

    def value(self) -> int:
        return sum(self.p.values()) - sum(self.n.values())

    def merge(self, other: 'PNCounter') -> None:
        for k, v in other.p.items():
            self.p[k] = max(self.p.get(k, 0), v)
        for k, v in other.n.items():
            self.n[k] = max(self.n.get(k, 0), v)
05
STAGE 05 · ALTERNATIVESL6 · SCALE & TRADE-OFFS

Alternatives: CvRDT vs. CmRDT vs. Delta-CRDT vs. Consensus.

Why this matters: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Think of Alternatives: CvRDT vs. CmRDT vs. Delta-CRDT vs. Consensus as the intuition layer for CRDTs & Conflict-Free Replicated Data: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Choose between shipping full state, causal operations, or compact deltas depending on network reliability and object size.

Component Topology

Alternatives: CvRDT vs. CmRDT vs. Delta-CRDT vs. Consensus

Client TxingressQuery PlannercomputeWAL BufferstorageStorage PagescontrolSQL queryappend redocheckpoint flush
ChoiceWhat it buysWhat it costs
CvRDT (State-Based)Tolerates dropped, duplicated, and reordered packets over plain HTTP/gossip.Bandwidth scales as O(full state size) on every sync.
CmRDT (Op-Based)Tiny operation payloads (`insert(pos, 'a')`).Requires reliable causal broadcast—cannot drop or reorder causal dependencies.
Delta-CRDT (δ-CRDT — Yjs / Riak / Automerge)Ships small idempotent state fragments; combines tiny payloads with loss-tolerant gossip.Requires tracking anti-entropy delta intervals per peer.
06
STAGE 06 · PRODUCTION ARCHITECTUREL7 · STAFF / PRINCIPAL

Production Architecture: Tombstone Lifecycle & Causal GC.

Why this matters: Production architecture: see how the components compose end to end under real load.

Think of Production Architecture: Tombstone Lifecycle & Causal GC as the intuition layer for CRDTs & Conflict-Free Replicated Data: Production architecture: see how the components compose end to end under real load.

In production, CRDTs move through active writes, delta replication, and causal-barrier compaction. Never purge tombstones until all active replicas acknowledge the causal version vector—and force stale offline clients (>30 days) to re-bootstrap from a fresh epoch snapshot.

Tombstone Lifecycle

CRDT Element & Causal Compaction State Machine

Observed remove(tag)All peers ACK vectorRe-add with new tag_2LIVE ELEMENTUnique (replica, seq) taTOMBSTONEDRetained for anti-entropCOMPACTEDBelow causal frontier

Tombstones prevent zombie resurrection during late syncs and are safely reclaimed only after crossing the cluster's causal frontier.

07
STAGE 07 · PROBLEMS SOLVED & FURTHER DEEP DIVEL7 · STAFF / PRINCIPAL

Problems solved & Related Concepts.

Why this matters: Applied problems: connect these internals to concrete system design and debugging scenarios.

Think of Problems solved & Related Concepts as the intuition layer for CRDTs & Conflict-Free Replicated Data: Applied problems: connect these internals to concrete system design and debugging scenarios.

Compare CRDTs against Raft consensus, multi-master split-brain recovery, and PACELC consistency-latency trade-offs.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does an LWW-Register CRDT using raw client `Date.now()` timestamps fail in production, and how do you fix it?

Recommended Learning Flow