WebSocket Document Operations
SDD Classification: L3-Technical
Authority: Engineering Team
Review Cycle: Quarterly
Operational Transform Overview
How OT Works
- Local First: Operations apply locally immediately for responsiveness
- Server Transform: Server transforms operations against concurrent changes
- Broadcast: Transformed operations sent to all other clients
- Client Transform: Clients transform incoming operations against pending local ops
Operation Types
Insert Operation
Add content at a position:Delete Operation
Remove content from a range:Retain Operation
Keep content unchanged (used in compound operations):Format Operation
Apply formatting to a range:Sending Operations
Operation Message Format
Client Implementation
Operational Transform Algorithm
Transform Rules
Insert vs Insert
Insert vs Delete
Delete vs Insert
Delete vs Delete
Conflict Resolution
Version Conflict
When operations are based on outdated versions:Handling Conflicts
Rich Text Operations
Supported Attributes
Applying Formatting
Undo/Redo Support
Operation Inversion
Performance Optimization
Operation Batching
Combine rapid operations for efficiency:Debouncing Cursor Updates
Best Practices
Do
- Apply operations locally first - Immediate feedback improves UX
- Use base version - Always include version for conflict detection
- Batch rapid operations - Reduce network overhead
- Store operation history - Enable undo/redo functionality
- Handle offline gracefully - Queue operations for later sync
Don’t
- Don’t skip transformation - Always transform remote operations
- Don’t ignore acknowledgments - They confirm server state
- Don’t send empty operations - Filter no-ops before sending
- Don’t assume operation order - Network may reorder messages
- Don’t lose operations - Persist pending ops locally
Related Documentation
- WebSocket Overview - API overview
- Events - Event reference
- Presence - Cursor tracking
- Error Handling - Error codes
Document Status: Complete Version: 2.0