Three ways shared data can agree

When people change the same shared data at the same time, every copy must reach the same result. The lessons cover three approaches: combine changes with a safe rule, put changes in one order, or rewrite changes so they still fit together.

CRDT

Conflict-free replicated data type

Combine changes without depending on one shared order.

A CRDT gives each copy enough information to combine work safely. Changes can arrive late, out of order, or more than once and still produce the same result.

Each CRDT has its own combine rule. Counters keep the highest known counts, sets keep addition and removal evidence, registers compare times or keep competing answers, and sequences give each item a stable identity.

In the lessons, the hikers exchange notes without a ranger station.

Trade-off: It tolerates unreliable delivery, but may keep extra history to make that safe.

DDS

Distributed data structure

Put every accepted change in one shared order.

A DDS sends every change to a sequencer. The sequencer numbers the changes, and every connected copy applies them in that order. In the lessons, the ranger station is the sequencer.

Each structure still needs a rule for the numbered list. A map may keep the last numbered value, while a claim may keep the first accepted owner.

Some DDS structures show a change before the sequencer numbers it; others wait. “Before the sequencer replies” below compares them.

Trade-off: The rule is often simple, but the sequencer must be available.

OT

Operational transform

Rewrite changes so they still make sense together.

OT adjusts one change against another change made at the same time. If Alice inserts text earlier in a line, Bob's insert position moves. OT shifts Bob's change to the new position before it applies.

JsonOt uses OT for paths in a JSON document. RichTextOt uses it for text, formatting, and embedded content. Both also need a sequencer, so every copy transforms changes in the same order.

Trade-off: It needs shared order for agreement, recent operations for transforms, and a correct rule for each pair of change types.

Side by side

None of these approaches is best everywhere. The useful question is what the data must survive and what service the application already has.

Question CRDT DDS OT
How copies agree Combine changes with a safe rule Apply one numbered list Rewrite changes before applying them
Needs shared order No Yes Yes
Local change before shared order Yes; no shared order needed Depends on the structure Yes; the edit stays pending
Late or repeated delivery The combine rule handles it The sequencer numbers changes; copies reject repeated numbers The client buffers and transforms changes
Typical cost Extra counts, identities, or removal history Little extra state; changes wait for the sequencer Buffered edits and recent operations

Before the sequencer replies

A DDS or OT change is final only after the sequencer numbers it. Until then, the author's copy holds it as pending. Structures differ in what the author sees in the meantime.

With JsonOt or RichTextOt, Alice sees her edit at once. Her client sends one edit at a time and holds later edits until the sequencer numbers the first. When Bob's numbered edit arrives, her client transforms it and her pending edits so both fit the document. If the sequencer stops replying, Alice still sees her pending edit, but it does not become shared.

SharedCounter, SharedMap, and SharedDirectory also show pending changes. Claims, RegisterMap, and FifoWorkQueue wait for a number before their readable state changes. TaskManager tracks a pending volunteer but waits for a number to assign the task. PactMap waits for a number to show a proposal, then for the required signoffs before anyone can read the new value.

Which one to use

  1. Use a CRDT when changes may happen offline or arrive late, out of order, or more than once.
  2. Use a DDS when a sequencer already orders changes and the rule needs one owner, one worker, or one winning value.
  3. Use OT when edits change positions inside JSON, text, or formatted content.

How multiplayer rooms work explains how one room service supports both CRDT merging and DDS sequencing.