Operational Transformation
What You'll Learn
You'll learn how Operational Transformation (OT) enables multiple users to edit the same document simultaneously without conflicts by transforming operations based on what others have done.
The Core Idea
Imagine two people editing the same Google Doc at the exact same moment. User A types "Hello" at position 0 while User B simultaneously deletes characters 5-10. Without coordination, these operations would produce different final states on each client.
Operational Transformation solves this by transforming each user's operation against concurrent operations from others, preserving everyone's intent even when the document state has changed.
Instead of resolving conflicts after they happen (like Last-Write-Wins), OT transforms operations as they arrive so they apply correctly to the current state.
How It Works
When you perform an operation (insert, delete, format), it's sent to other clients. But before applying a remote operation, each client transforms it against operations that happened concurrently:
- User A inserts "Hi" at position 0
- User B (unaware) inserts "Yo" at position 0
- When B receives A's operation, it transforms: "insert at 0" becomes "insert at 2" (after "Yo")
- When A receives B's operation, no transformation needed—it happened first
The transformation function adjusts positions, lengths, and targets to maintain what each user meant to do, not just what they literally typed.
Why It Matters
OT is the engine behind real-time collaborative tools. It's more complex than CRDTs but can handle any document structure (text, formatting, spreadsheets) without metadata overhead. The tradeoff: transformation functions must correctly handle every operation pair—a challenging mathematical requirement.
Key Takeaway: Operational Transformation preserves user intent in collaborative editing by dynamically adjusting operations based on concurrent changes, enabling seamless real-time collaboration without conflicts.