Skip to content

Collaborative editing: represent concurrent work

10 min reading

A design that states merge, ordering and history assumptions

Page details

System Design · Compose complete systems

10 min reading · 25 min with practice

Sources

Published · Last edited:

Prerequisite: Dispatch under stale data and contention. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. Two Northwind colleagues edit a training draft while one laptop disconnects. Dev stores whichever full document arrives last. Priya shows an independent accepted edit disappearing when the older laptop returns.

Maya: “Both people intended valid work.”

Dev: “We need to define what each editing operation means before deciding how to combine it.”

Choose operation identity and a synchronization model for the shared draft. Raw positions can become ambiguous when another edit changes the text; merging the resulting text also does not approve the business policy it describes. The selected editor cohort is a new capacity exercise, not a staff count.

This case designs a shared text document with reconnect and versioned history. Scope includes concurrent edits, synchronization, document permissions and recovery. Rich layout, spreadsheet formulas and arbitrary embedded applications are excluded. Their operation semantics need separate design.

The required contract is not merely that every client eventually displays identical bytes. The system also needs a meaningful interpretation of concurrent operations, durable accepted edits and an authority boundary for who may change the document.

What did each person intend to change?

Replacing the whole document with the last arriving version is simple, but can erase another person's valid changes. A wall-clock comparison does not establish user intent, especially when devices are offline or clocks disagree.

Sending raw position edits is also insufficient because positions move as other edits apply. A reconnecting client needs the context against which its operation was defined. Treating every edit as an isolated database update hides the shared-history problem.

Decide first whether simultaneous editing is truly required. A single-owner edit or explicit version-conflict workflow can be a better product for documents where silent merging is unacceptable. Collaboration machinery is justified by the intended interaction, not by the presence of a text field.

Choose operation semantics and a sync model

Operational transformation adjusts operations against concurrent history under a specified algorithm. A conflict-free replicated data type defines state or operation behavior with convergence properties under its model. Neither name is a complete implementation specification, and mixing pieces casually can break the intended guarantees.

Concurrent operations need shared interpretation and permissionTwo document replicas produce edits from a known history. A synchronization boundary validates identity and operation context before applying the chosen merge model and distributing accepted history.Replica A + contextReplica B + contextValidate + mergechosen operation modelAccepted historyand snapshots

Yjs documentation describes shared data types and synchronization. It supplies one maintained implementation to evaluate against the selected plain-text model. Its merge behavior does not grant document access or approve the resulting business text.

Use stable document and operation identities. Persist accepted history and checkpoint state according to the chosen synchronization protocol. Clients reconnect with the required history position or causal evidence, not merely a full text blob whose origin is unknown.

Work one concurrent insert under an explicit editing rule

Hypothetical scenario. Begin with text AB. Client X inserts x between A and B while disconnected client Y inserts y at the same gap. A central OT design transforms a later positional operation against the accepted concurrent operation. The transform and server ordering policy must be specified; the letters alone do not determine whether the visible result is AxyB or AyxB.

Work one concurrent insert under an explicit editing rule — selected design evidence
OperationIdentity / referenceSelected interpretation
Insert xX:1 after element AConcurrent sibling
Insert yY:1 after element AConcurrent sibling
Tie ruleX before YDeterministic toy order
DeleteTarget element identityPreserve object of deletion
The two inserts are concurrent; a declared transform or merge rule must explain their final order.The two inserts are concurrent; a declared transform or merge rule must explain their final order. Common base AB to Replica X: insert x: same predecessor A; Common base AB to Replica Y: insert y: same predecessor A.Replica X: insertxCommon base ABReplica Y: insertysame predecessor Asame predecessor A
The two inserts are concurrent; a declared transform or merge rule must explain their final order. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

For a toy sequence-CRDT rule, each insertion names its predecessor element and stable actor/counter identity. Both x and y name A. Choose a deterministic sibling order by actor identity, with X before Y, giving AxyB at both replicas once they have the same operations. This selected toy rule illustrates tie-breaking, not a complete production CRDT algorithm.

A delete should name the intended element under the chosen model, not blindly reuse a stale character position. Convergence requires compatible operation meaning, unique identities and complete permitted delivery. It does not establish that the merged sentence preserves intent, that every edit was authorized or that a business document remains valid.

Work through a position conflict and history budget

Hypothetical scenario. Start with the three characters A,B,C at zero-based positions 0,1,2. One editor inserts X before A, producing X,A,B,C. Another editor, still viewing the original, intends to delete B at position 1. Applying its raw offset to the updated text deletes A instead. The example demonstrates why context and operation interpretation matter; it is not an implementation of either OT or a CRDT.

Under a model that preserves the intended target, inserting X and deleting B can produce X,A,C. The precise result for concurrent inserts, deletes and nested edits must be defined by the selected algorithm. Do not infer every rule from this one intuitive example.

Choose 100 concurrent editors generating two operations per second each. The service receives 100 × 2 = 200 operations per second. At a chosen 100 bytes of logical operation payload, that is 20,000 bytes per second. One hour of uncompressed retained operations is 20,000 × 3,600 = 72,000,000 bytes, or 72 MB, before metadata, indexes and replicas.

If each accepted operation is broadcast to 99 other editors, live delivery can reach 200 × 99 = 19,800 operation deliveries per second. Batching can reduce message overhead, but does not remove the logical operations recipients must interpret.

Choose a snapshot every 10,000 operations. At 200 operations per second, that count is reached in 10,000 ÷ 200 = 50 seconds under the constant-rate example. Snapshotting cannot discard history still required by offline clients unless the protocol defines a safe rebase or resynchronization path.

In the wild: shared types have a documented merge model

Yjs describes shared types and document updates for collaborative applications. Use its actual supported object model and provider behavior rather than assembling an informal algorithm from timestamps and offsets. The documentation does not establish Northwind’s permission or durable-acceptance policy.

Last arrival erases a different accepted draft

Hypothetical failure scenario. Two editors start with the same document, make independent changes and reconnect in a different order. The server replaces the whole object on every arrival. All readers eventually agree, but one editor’s valid work disappears. Identical final bytes did not satisfy the intended collaboration contract.

Choose explicit operation semantics or reject incompatible versions deliberately. The product can prefer a version-conflict workflow where silent merging is unacceptable. A maintained replicated-object implementation is useful only when its semantics match the required document operations, including deletion and undo.

Keep approval outside text convergence

The collaborative draft is one object. Publication or policy approval is another authoritative transition with its own permissions and expected revision. Two merged statements can contradict each other even when every replica converges correctly. A readable result does not certify a business decision.

Record accepted edits durably under the selected service contract and keep connection presence disposable. A cursor disappearing does not prove an edit failed. The next page tests offline clients against history compaction, access revocation and restoration rather than treating a snapshot as the entire protocol.

Challenge the proposed mechanism

Deterministic tie-breaking produces the same toy order from the same admitted operations.Deterministic tie-breaking produces the same toy order from the same admitted operations. Replica X to Merge authority: 1 · X:1 after A; Replica Y to Merge authority: 2 · Y:1 after A; Merge authority to Replica X: 3 · ordered sibling set; Merge authority to Replica Y: 4 · same permitted set.Replica XMerge authorityReplica Y1 · X:1 after A2 · Y:1 after A3 · ordered sibling set4 · same permitted set
Deterministic tie-breaking produces the same toy order from the same admitted operations. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

Apply x then y and y then x. What must a model answer show?

Reveal the design reasoning

Carry identities and causal context, execute the selected rule in both orders and derive the same permitted state. Then name an intent or authorization limitation that convergence does not solve. Do not infer a full CRDT proof from one example.

Decision and reconsideration: Choose an explicit editing object and merge semantics. Test operation reorder, duplication and intent limits independently.

Defend edit interpretation

  1. An insertion shifts the original deletion offset. What must the protocol preserve?

    Retain operation context

    The intended target under the selected operation model. Applying an obsolete numeric offset directly can delete another character.

  2. Every replica agrees on conflicting approval statements. Did convergence validate the policy?

    Separate document and authority

    No. Convergence governs accepted object updates. Approval and business invariants require their own authoritative workflow.

  3. May a snapshot discard every older identifier immediately?

    Account for returning replicas

    Only if the chosen synchronization protocol establishes that the context is no longer needed or defines a safe resynchronization path. Snapshot creation alone does not prove that.

Consider what happens when the connection closes immediately after a user types a sentence. The local interface can show the edit without claiming the service has stored it. A separate acknowledgement can identify the durable update boundary. On reconnection, the client resends stable update identities or synchronizes through the library’s documented protocol; it must not turn an uncertain acknowledgement into a new independent edit. Presence follows a different contract: an old cursor location may expire without recovery. Keeping those contracts distinct lets the interface tell the user whether work is local, synchronized or awaiting durable confirmation. None of these states implies that a reviewer approved the text.

The baseline explains concurrent operations under retained context. Page 56 lets an editor remain offline while that context and their permission change, requiring an explicit support and resynchronization policy.

Northwind decision log

Choose operation meaning before synchronizing concurrent edits.
Keep durable draft history separate from permission and approval.
Next, bound offline support and recover compatible replica context.

Go deeper: concurrency and replicated objects