Skip to content

Part 5 · Blueprint 30

Real-Time Collaborative Editing

15 min reading · Sources · Editorial review pending

Last arrival can erase an independently accepted edit.

More
20px
Reading list
Page details

Published date · Last edited:

Draft edition. Editorial review and supplementary reading recommendations are still being completed.

Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Consistency Models: CAP, PACELC & Linearizability, Idempotency Keys & Distributed Retries, Time, Clocks & Distributed Ordering: Lamport to TrueTime.

Sixty-second mental model

Problem: Last arrival can erase an independently accepted edit.

Use: Define operation meaning before choosing transformation or merging.

Design boundary: Let authorized users edit a shared document, including reconnects and concurrent changes. Choose one concrete edit model rather than saying CRDT or OT as a complete design. The first version uses an ordered operation history with revision-aware server validation; offline merge policy must be explicit.

Layer 1 · Intuition

Hypothetical scenario: Northwind is designing collaborative editing. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one edit means and which component owns the document operation history.

Think of two editors writing on copies that must later merge. Separate the requester from document operation history, then identify the retained evidence needed after failure.

Authority
The entitled state owner.
Invariant
A rule preserved across concurrency and failures.

Architecture and worked reasoning

Design boundary: Let authorized users edit a shared document, including reconnects and concurrent changes. Choose one concrete edit model rather than saying CRDT or OT as a complete design. The first version uses an ordered operation history with revision-aware server validation; offline merge policy must be explicit.

Responsibilities on the request path

Collaborative editing: responsibilities and request directionLet authorized users edit a shared document, including reconnects and concurrent changes. Choose one concrete edit model rather than saying CRDT or OT as a complete design. The first version uses an ordered operation history with revision-aware server validation; offline merge policy must be explicit.Editor sessionDocument sequencerOperation logSnapshot service
Let authorized users edit a shared document, including reconnects and concurrent changes. Choose one concrete edit model rather than saying CRDT or OT as a complete design. The first version uses an ordered operation history with revision-aware server validation; offline merge policy must be explicit.

Domain interface and access patterns

POST /documents/{id}/operations with client_operation_id and base_revision; GET /documents/{id}/operations?after_revision=N

operations(document_id, revision, client_operation_id, base_revision, payload); snapshots(document_id, revision, object_key); sessions(document_id, device_id, acknowledged_revision). Operation interpretation is part of the edit algorithm, not merely a JSON schema.

Workload and limiting resource

Choose 50 active editors each producing two operations/s: a hot document receives 100 operations/s regardless of total shard count. At 200 bytes/operation, one hour retains 100 × 3,600 × 200 = 72 MB before indexes and snapshots. Snapshots every 10,000 operations bound a normal replay suffix to roughly 10,000 operations, subject to retained-history and client-reconnect policies.

Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.

Mutation or publication path

Collaborative editing: mutation boundarySubmit an operation with client identity and base revision. Then: Validate/transform or reject according to the chosen edit algorithm. Then: Append the ordered operation and broadcast its committed revision.Step 1
Submit an operation with client identity and base revision.
Step 2
Validate/transform or reject according to the chosen edit algorithm.
Step 3
Append the ordered operation and broadcast its committed revision.
Submit an operation with client identity and base revision. Then: Validate/transform or reject according to the chosen edit algorithm. Then: Append the ordered operation and broadcast its committed revision.
  1. Submit an operation with client identity and base revision.
  2. Validate/transform or reject according to the chosen edit algorithm.
  3. Append the ordered operation and broadcast its committed revision.

Observation and recovery path

Collaborative editing: observation boundaryLoad a snapshot at a declared revision. Then: Replay its following operations. Then: Deduplicate reconnect overlap and reconcile local uncommitted edits explicitly.Step 1
Load a snapshot at a declared revision.
Step 2
Replay its following operations.
Step 3
Deduplicate reconnect overlap and reconcile local uncommitted edits explicitly.
Load a snapshot at a declared revision. Then: Replay its following operations. Then: Deduplicate reconnect overlap and reconcile local uncommitted edits explicitly.
  1. Load a snapshot at a declared revision.
  2. Replay its following operations.
  3. Deduplicate reconnect overlap and reconcile local uncommitted edits explicitly.

Failure that changes the decision

Hypothetical scenario: A client reconnects from a revision older than retained transformation history. Do not silently apply positions to a new snapshot; require a defined rebase/merge workflow or expose a recoverable conflict.

Attempt this decision before reading the explanation

Will putting operations in one total order automatically preserve user intent?

No. Concurrent insertion/deletion positions still need correct transformation or a data type with defined merge semantics. Ordering supports one history but does not by itself define the meaning of concurrent edits.

Supporting mechanism analysis

Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.

Hypothetical scenario. Priya and Dev edit a supplier policy while one laptop is offline; converging text must not silently approve the policy or restore revoked access.

In short. Choose replicated-operation semantics before applying concurrent offsets. Budget history against the supported offline interval.

Hypothetical scenario. Two colleagues edit the same sentence while disconnected. One inserts a word near the beginning; another deletes a character using its old position. When both reconnect, applying their raw offsets in arrival order removes a different character from the one the second person intended.

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.

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.

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.

A Conflict-Free Replicated JSON Datatype provides one concrete research model for nested replicated data. Its data structures and assumptions matter. Convergence in that model is not proof that every application-level constraint or user-intent expectation is preserved.

Collaborative editing needs an interpretation of operations under concurrency. If two clients edit by numeric offset against different histories, applying those offsets blindly can change a different character from the one the author intended. Operational transformation and conflict-free replicated data types offer different ways to reason about concurrent edits. The chosen model needs stable operation meaning, synchronization rules and a declared document object.

In a hypothetical history, the text is AB. One editor inserts X before B while another, still viewing AB, inserts Y after B. Simply replaying both old numeric offsets against each new string can misplace an insertion. A replicated-object design can attach an operation to a stable identifier or otherwise transform its interpretation against concurrent history. The point is to preserve the operation's meaning under the selected model, not to assume that arrival order expresses user intent.

History also consumes storage. Suppose ten active editors each create two operations per second, with an illustrative eighty-byte operation payload. The operation rate is 10 × 2 = 20 per second. Payload growth is 20 × 80 = 1,600 bytes per second, or 1,600 × 3,600 = 5,760,000 bytes per hour. Metadata, indexes, snapshots and replication add costs. This payload calculation is not a claim about a particular CRDT implementation's serialized size.

Compaction trades retained history against the needs of clients that can still return with older context. Define the supported offline interval and the resynchronization behavior when that interval is exceeded. An application that discards every obsolete-looking identifier can lose the information required to interpret a returning client's operations safely.

Finally, convergence is not authorization or business validity. Two clients can converge on text that contains incompatible approval statements. Keep authoritative publication or approval in a separate workflow, and check current permissions when an offline client returns. Causal context explains what history an operation saw; it does not grant the right to alter the shared policy now.

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.

Primary evidence for merge Northwind draft edits without merging authority: Replicated JSON has a concrete conflict-free research model and assumptions.

A merged document can converge while containing an invalid business state. Two people can independently add conflicting approval statements or change fields whose relationship must remain constrained. Separate collaborative text behavior from authoritative workflow decisions.

Presence and cursor positions are usually ephemeral observations. Do not retain them as durable document operations unless the product requires that history. A disappearing cursor does not establish that a person's last edit failed.

Layer 3 · Internals

Trade-offs and limits

ApproachProvidesRequires
Central transformation authorityCan sequence operations and transform against a controlled history.Offline divergence and replay require explicit transformation semantics.
Mergeable replicated operationsCan support independent accepted edits under chosen conflict rules.Metadata growth and domain semantics still need deliberate design.

Recovery decision

Hypothetical scenario: A client reconnects from a revision older than retained transformation history. Do not silently apply positions to a new snapshot; require a defined rebase/merge workflow or expose a recoverable conflict.

No. Concurrent insertion/deletion positions still need correct transformation or a data type with defined merge semantics. Ordering supports one history but does not by itself define the meaning of concurrent edits.

Write your design before revealing the review

Will putting operations in one total order automatically preserve user intent?

Evidence you can explain in your own design

Drafts and self-review are stored only in this browser. They are separate from reading completion.

Compare your decision

No. Concurrent insertion/deletion positions still need correct transformation or a data type with defined merge semantics. Ordering supports one history but does not by itself define the meaning of concurrent edits.

A client reconnects from a revision older than retained transformation history. Do not silently apply positions to a new snapshot; require a defined rebase/merge workflow or expose a recoverable conflict.

Check your understanding

Will putting operations in one total order automatically preserve user intent?

No. Concurrent insertion/deletion positions still need correct transformation or a data type with defined merge semantics. Ordering supports one history but does not by itself define the meaning of concurrent edits.

How would you recover from this failure: A client reconnects from a revision older than retained transformation history. Do not silently apply positions to a new snapshot; require a defined rebase/merge workflow or expose a recoverable conflict.

Start with the exact boundary that failed. Submit an operation with client identity and base revision. Validate/transform or reject according to the chosen edit algorithm. Append the ordered operation and broadcast its committed revision. Then recover evidence through the observation path: Load a snapshot at a declared revision. Replay its following operations. Deduplicate reconnect overlap and reconcile local uncommitted edits explicitly. Preserve the distinction between a confirmed state change and an unavailable response.

Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?

Choose 50 active editors each producing two operations/s: a hot document receives 100 operations/s regardless of total shard count. At 200 bytes/operation, one hour retains 100 × 3,600 × 200 = 72 MB before indexes and snapshots. Snapshots every 10,000 operations bound a normal replay suffix to roughly 10,000 operations, subject to retained-history and client-reconnect policies. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Let authorized users edit a shared document, including reconnects and concurrent changes. Choose one concrete edit model rather than saying CRDT or OT as a complete design. The first version uses an ordered operation history with revision-aware server validation; offline merge policy must be explicit.

Which component in this topology could be removed from a smaller first deployment?

Editor session, Document sequencer, Operation log, Snapshot service name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Submit an operation with client identity and base revision.

What evidence must a caller have before relying on the observation path?

Load a snapshot at a declared revision. Replay its following operations. Deduplicate reconnect overlap and reconcile local uncommitted edits explicitly. No. Concurrent insertion/deletion positions still need correct transformation or a data type with defined merge semantics. Ordering supports one history but does not by itself define the meaning of concurrent edits.

45-minute interview rubric

  1. 00–05: scope edit and document operation history.
  2. 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
  3. 12–28: draw document operation history, numbered writes and reads.
  4. 28–40: challenge recovery: Define operation meaning before choosing transformation or merging.
  5. 40–45: defend document_id placement, observations and remaining assumptions.

Go deeper

  • Introduction | Yjs Docs · Primary document · docs.yjs.dev. Define operation meaning before choosing transformation or merging. Verified 2026-10-26.

Decision log

Define operation meaning before choosing transformation or merging.

Preserve edit identity and document operation history ownership.

Revisit changed workload, observations or recovery objectives.