Is a CRDT enough to synchronize offline edits across devices?

A conflict-free replicated data type (CRDT) is a family of data structures designed so independently edited replicas converge when they receive the same updates. That does not mean an entire application automatically provides offline synchronization, privacy, or data ownership. Shapiro et al., CRDT paper

Decide these points before choosing a design

  • 1. Define the meaning of the data. A cart quantity that can be added, a tag set with additions and removals, and text edits in one document need different conflict semantics. Decide whether “last write wins” is acceptable and what deletion concurrent with an edit should mean.
  • 2. Match the replication style to the data flow. The 2011 paper distinguishes state-based CvRDTs, whose state merge follows a monotonic semilattice condition, from operation-based CmRDTs, whose concurrent operations must commute under delivery assumptions. State exchange/merge and operation delivery have different implementation requirements; the labels are not interchangeable recipes.
  • 3. Test disconnection, duplicate delivery, and reordering. On two devices, add one list item on A and mark a different item complete on B, disconnect, then reconnect. Deliver the same update more than once and in different orders; verify the resulting state still matches the product’s intended semantics.
  • 4. Specify what happens when edits target the same field. Ink & Switch’s Automerge example says changes to different objects can merge, while concurrent edits to the same property can leave values for the app or user to resolve. “Conflict-free” does not mean every semantic disagreement disappears.

Example: an offline task list

Suppose devices A and B share a list, then go offline. A adds “buy groceries”; B marks “laundry” complete. A CRDT can preserve both independent changes when the devices reconnect. If both devices instead rename the same task differently, the application must decide whether to choose one, show both versions, or ask the user. The right rule depends on what the task represents.

Work that remains outside the CRDT

A CRDT provides data-type replication and merge rules; it does not supply network transport, peer discovery, authentication, authorization, encryption, durable storage, backups, schema compatibility, or account recovery. Ink & Switch notes that a CRDT does not specify how edits travel between users and does not claim its libraries fully realize local-first ideals. Change-history growth and safe garbage collection also need separate design decisions.

Sources