Friends writing a story together, each with their own copy. Alice adds a paragraph about dragons at the beginning while Bob deletes a sentence about knights in the middle and Charlie fixes typos at the end. When they share changes, chaos should follow—but it doesn’t. Operational Transformation (OT) resolves conflicting operations so everyone ends with the same text.
The Collaborative Writing Challenge
The Synchronization Problem
Alice types “Once upon a time” at position 0. Bob types “In a land far away” also at position 0. Whose text comes first? How to merge without losing either?
The Position Drift
Charlie wants to delete character at position 50. Alice inserts 10 characters at position 20. Charlie’s position 50 is now position 60. Delete targets wrong character.
The Transformation Magic
OT transforms operations to maintain consistency when concurrent edits conflict.
Basic Operations
Insert(position, text): Add text at position, shifts everything after rightward.
Delete(position, length): Remove characters, pulls everything after leftward.
Retain(length): Skip forward, no changes, used in operation sequences.
This diagram requires JavaScript.
Enable JavaScript in your browser to use this feature.
The Transform Function
When Alice inserts at position 5 and Bob deletes at position 10:
- Bob’s delete position shifts by Alice’s insert length if delete comes after
- For Alice’s perspective, the delete stays at 10 since it’s before her insert
- For Bob’s perspective, Alice’s insert shifts his target from 10 to 15
- Both apply transformed operations, same final document results
Operational Properties
Convergence: Apply A then B’ equals Apply B then A’, where A’ and B’ are transformed versions.
Reversibility: Every operation has an inverse. Transform preserves undo capability.
Real-World Systems
Google Docs
Every keystroke creates an operation. Client buffers group rapid edits. Server assigns global order, transforms and broadcasts to all clients. Clients see instant updates.
Code Editors
VS Code Live Share uses OT-based collaboration. Multiple cursors track positions, syntax awareness handles language-specific transforms. Remote pair programming feels local.
Collaborative Drawing
Move operations transform coordinates. Resize operations adjust dimensions. Layer changes require z-order management. OT extends beyond text.
Transformation Rules
Insert vs Insert
Both inserting at different positions: positions after other inserts shift accordingly. Both inserting at same position: tiebreaker rule (alphabetical by user ID).
Insert vs Delete
Insert before delete: delete position shifts by insert length. Insert after delete: insert position shifts by delete length. Insert in delete range: complex split case.
Delete vs Delete
Overlapping deletes require careful intersection computation. Avoid double deletion while preserving both users’ intents.
Common Challenges
Late Joiner
New user arrives at active session. Server sends current document state snapshot or replays recent operation history. Entry appears instant.
Offline Edit
User works without connection. Local changes stack up. On reconnect, transform against all missed operations. Automatic merge resolves conflicts.
Cursor Problem
Multiple cursors must transform like operations. Selection ranges (start and end) transform independently but consistently.
Performance Wall
Transforming n concurrent operations costs O(n). History grows unbounded. Garbage collection prunes old operations. Operation combining reduces transformation count.
When OT Applies
OT fits:
- Real-time collaborative editing
- Multi-user document systems
- Applications with frequent concurrent edits
OT adds complexity for:
- Simple single-user applications
- Systems where occasional conflict is rare
- High-latency environments where OT overhead exceeds benefit
Decision Rules
Use OT when:
- Multiple users edit same document simultaneously
- Conflict resolution must preserve intent
- Real-time responsiveness matters
- Server-centric architecture is acceptable
Consider CRDTs when:
- Peer-to-peer architecture is preferred
- Network partitions are common
- Server coordination is undesirable
- Operational transformation complexity is too high
Use locking when:
- Exclusive access is acceptable
- Collaboration requirements are minimal
- Simplicity matters more than features
The manuscript awaits. Multiple authors type. Their changes transform and merge. Everyone’s story converges.