CRDTs: Syncing Data Without Locks or Conflicts
CRDTs are data structures where updates can be applied in any order and reach the same state, avoiding locks. They enable offline editing in collaborative apps and distributed databases.
WHY IT EXISTS In distributed systems, keeping data consistent across multiple computers is hard. Traditional methods use locks or consensus algorithms, which reduce availability and performance, especially if replicas can go offline. CRDTs were invented to provide strong eventual consistency without this expensive coordination.
THE MENTAL MODEL Think of a CRDT as a data structure with special operations that are mathematically designed to not conflict. Instead of a generic set(value) operation, you have specific ones like add(element) or increment(). These operations are commutative, meaning their application order doesn't matter. No matter when or in what sequence replicas receive updates, they all eventually converge to the identical state, conflict-free by design.
HOW IT WORKS CRDTs work because their update operations are guaranteed to produce the same result regardless of order. For example, a Grow-Only Set (G-Set) is a simple CRDT that only allows additions. To merge two G-Set replicas, you simply take the union of their elements. Since you can't remove elements, there's no possible conflict to resolve. Other CRDTs for lists, counters, and registers use similar mathematical properties to ensure convergence without needing a central coordinator to resolve disputes.
WHEN TO USE IT Use CRDTs when you need high availability, low-latency writes, and offline-first capabilities. They are a natural fit for collaborative applications (like Google Docs or Figma), distributed counters (like social media likes), multi-player game state, and chat applications where any user can send a message at any time, even with a spotty connection.
WHEN NOT TO USE IT Avoid CRDTs when you require strict, immediate consistency or need to enforce complex business rules. For example, guaranteeing a username is unique across a whole system cannot be solved with a simple CRDT set, as two users could independently claim the same name on different replicas. These scenarios still require traditional coordination mechanisms or transactional guarantees.
ONE CANONICAL EXAMPLE A G-Counter (Grow-Only Counter) is a basic CRDT. Each replica in the system maintains its own counter. To increment the global count, a replica simply increments its local counter. The total value is the sum of all local counters across all replicas. When replicas sync, they share their values, and everyone can calculate the same total sum. No increment is ever lost, and all replicas eventually agree on the final count.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.