Back to the map

Module 13 · Distributed fundamentals · Lesson 18 of 18

Operational transformation

How Google Docs keeps everyone's edits consistent: transform each incoming operation against the concurrent ones so it applies correctly at a different position. The transform function, the central server that imposes a total order.

DeepShould-knowSenior 12 minVideoPro Updated Nov 2026

The video walkthrough is part of Pro.

See what Pro includes
Video walkthrough · 2:45 · narrated, with captions

Why it matters

Two people type into the same document at the same time. Alice inserts a word at position 5; Bob deletes the character at position 2. If each client applies the other's operation literally, Alice's insert lands one position off on Bob's screen and the documents diverge forever. Operational transformation is the technique that adjusts operations for what happened concurrently, and it has run Google Docs, Office online and many editors for two decades. It is the classic contrast to CRDTs and a favourite way to test whether you understand concurrent editing.

The idea

Each edit is an operation with a position: insert(pos, text) or delete(pos, length). When a client receives an operation that was generated concurrently with operations it has already applied, it transforms the incoming operation against each of them so that its position accounts for their effect, then applies it. The transform function T takes two concurrent operations and returns a version of the first adjusted for the second.

Alice: insert(4, 'X')ABCDE → ABCDXEBob: delete(1)ABCDE → ACDEsend insert(4,'X')send delete(1)Alice applies delete(1)ABCDXE → ACDXEBob transforms: insert(3,'X')ACDE → ACDXET(insert(4), delete(1)) = insert(3): the insert shifts left because a character before it was removedboth documents: ACDXE
Alice and Bob edit 'ABCDE' concurrently. Each transforms the other's operation against their own before applying, and both converge on 'ACDXE'.

The two properties

Convergence: all clients that have applied the same set of operations, in any order, end up with the same document. Intention preservation: each operation's effect on the final document matches what the user meant (Alice's X should appear between D and E regardless of Bob's deletion). Transform functions are defined for every pair of operation types, insert against insert, insert against delete and so on, and getting them right for all cases is notoriously subtle; the research literature is full of published transforms later shown to be wrong in three-way concurrent scenarios.

The central server

The practical fix for that subtlety is architecture: route all operations through a server that imposes a total order. Each client sends its operations to the server and holds them in a pending buffer; the server applies them in arrival order, transforming each against operations it has accepted since the client's last known state, and broadcasts the result. Clients transform incoming server operations against their pending local ones. With a single ordering point, only pairwise transforms are needed and the hard multi-way cases disappear. This is the Jupiter model that Google Docs and most production OT systems use.

Operational transformationCRDT sequences
CoordinationCentral server for ordering (in practice)None; peer-to-peer and offline work natively
Operation shapePosition-based; transformed against concurrent opsIdentifier-based; each item has a unique position id
MetadataSmall: just the operationLarger: position ids and tombstones per character
Correctness burdenTransform functions must be right for all pairsMerge is correct by construction; complexity is in id schemes and garbage collection
Offline and long disconnectsHarder; long pending buffers and server stateNatural; merge whenever reconnected
Rich text and structureMature (Google Docs, Quill's Delta)Maturing (Yjs, Automerge handle rich text and JSON)
Used byGoogle Docs, Office online, Etherpad, Quill-based editorsFigma multiplayer, Apple Notes, many offline-first apps

Practical details

Operations are usually expressed as compact deltas (retain n, insert text, delete n) that compose and transform cleanly. Clients keep a revision number and the server rejects or transforms operations based on the revision they were generated against. Undo must transform the inverse operation against everything since. Cursors and selections are transformed too, which is why a collaborator's cursor stays on the right character while you type above it. Presence, comments and formatting are separate streams layered on the same ordering.

Choosing between OT and CRDTs

With a reliable server and clients that are mostly online, OT is compact, mature and well understood. For peer-to-peer, offline-first or very large documents where a central ordering point is unwanted, CRDTs remove the coordination and the transform correctness problem at the cost of metadata. Several modern editors have migrated to CRDTs; several of the largest still run OT. Both achieve the same user-visible goal: everyone converges and nobody's edit is lost.

Operational transformation · Backplane