Live on Product Hunt Intraface launched today. Less steering, more vacations. See the launch
Start for free

What is operational transformation?

Operational transformation (OT) is a technique for letting several people edit one document at the same time. Each edit is an operation with a position, like insert this text at character 9. When an edit made against an older copy arrives, OT transforms it, shifting its position by the edits it crossed, so every copy ends up identical.

Part of Glossary: the terms behind MCP, coding agents and shared pages, defined plainly.

How it works

Two editors send positioned operations to a server, which orders them, transforms the late one, and sends each editor what it missed.JohnLuizshifts each edit bythe edits it crossedserver, revision logsame texton every screen1. delete chars 9-111. insert 'IT' at 02. delete, shifted by 22. insert 'IT' at 03. replay the log
  1. Every edit is an operation with a position: insert this text at 9, delete characters 9 to 11, apply bold from 10 to 20.

  2. Your editor applies your operation at once and sends it to the server. Typing never waits on the network.

  3. The server applies operations in the order it receives them, numbers each one as a revision, and forwards it to the other editors.

  4. An operation made against an older revision is transformed against everything that landed since, so it still hits the characters it meant.

    In Google Docs, a delete at 9-11 that crossed an insert of two characters at 0 becomes a delete at 11-13.

  5. Every editor applies the same transform to incoming edits. When all changes have reached everyone, every copy reads the same.

Source: Google Drive blog: What's different about the new Google Docs: Conflict resolution

Example: Google Docs

Google's own walkthrough starts with a document that reads EASY AS 123. John changes 123 to ABC, which his editor records as a handful of small operations, one of them a delete of characters 9 to 11. At the same time Luiz types IT at the start of his copy. If Luiz applied John's delete as sent, he would remove the wrong characters, because his document has two extra characters John never saw.

So Luiz's client transforms John's operation first: shift it right by two, then apply it. The server does the same job for the other direction. When Luiz's insert reaches the server it is checked against every revision committed since Luiz last synced, shifted as needed, and stored as the next revision. Both editors finish on the same text, and the server keeps the whole revision log rather than the final characters.

The post also shows the quieter cases. A bold applied to 10-20 that crosses an insert of three characters at 15 widens to 10-23. An italic and a colour change over overlapping ranges need no transform at all, because text can be both.

Operational transformation versus a publish queue with versions

OT works on single operations inside one live document. A publish queue works on whole publishes. Each author edits a complete copy, then submits the whole thing, and the service applies submissions one at a time against the current version. There is no transform step. Either a publish touches files nobody else changed since, in which case it lands as the next version, or it collides on a file and the author pulls the new version and redoes the edit.

Intraface is the second kind. Its agents merge per file, never per keystroke, and every version is a thing you can open and diff. The trade is latency for legibility: OT gives you a cursor you can watch move; versions give you a history you can read.

Where it came from

The idea is from Ellis and Gibbs, "Concurrency Control in Groupware Systems", SIGMOD 1989. Their dOPT algorithm let each site execute an operation immediately, send it with a priority to every other site, and transform incoming operations that had crossed local ones, using a transformation matrix defined per pair of operation types. The goals were responsiveness and no locks, and they pointed out that the behaviour users want here is not serializable: there may be no single order of operations that explains every screen, yet all screens agree.

Common mistakes

  • Treating OT as a library you drop in. The transform functions are specific to your operation set. Add a new operation type and you owe a transform for every pairing.
  • Skipping the server. Fully distributed OT exists, but the proofs are hard. Google Docs, like most products, uses a server as the single orderer and keeps the client logic small: one change in flight at a time, the rest queued.
  • Reaching for OT when the unit of change is a file. If people hand over finished edits rather than typing together, you want versions and a rebase step, not character transforms.

FAQ

Does Google Docs use operational transformation?
Yes. Google described it in 2010: every edit is an InsertText, DeleteText or ApplyStyle change, the document is a revision log of those changes, and each client transforms incoming changes so they make sense against its local copy. The server does the same for changes that arrive against an older revision.
Why is operational transformation hard to get right?
The transform has to be defined for every pair of operation types, and it has to give the same answer at every site. Ellis and Gibbs noted in 1989 that the algorithm must know the semantics of the operations. Most products avoid the hardest part by routing every edit through one server that fixes the order.
Do coding agents need operational transformation to share a page?
No. Agents do not type into the same text box at once; each pulls a copy, edits it and publishes a whole new version. A publish queue with per-file merging and a rebase when two agents change the same file covers that case without transforming single characters.

Stop sending HTMLover Slack.

Create an account in a minute, connect your coding agent, and make your first board.