Problem
Design the architecture for a real-time collaborative text editor where multiple users can edit the same document simultaneously, similar to Google Docs. Changes from one user should appear on all other users' screens within 200ms.
Requirements
- Concurrent Editing: Multiple users can type in the same document at the same time without conflicts or data loss.
- Conflict Resolution: When two users edit the same region of text simultaneously, the system must deterministically resolve the conflict and converge to the same state on all clients.
- Cursor Presence: Show other users' cursor positions and selections in real-time.
- Offline Support: Users can continue editing while disconnected. Changes are synced when they reconnect.
- Version History: Maintain a history of all changes for undo/redo and version browsing.
- Permissions: Support view-only, comment-only, and edit access levels per document per user.
Constraints
- Up to 50 concurrent editors per document.
- Document size up to 1 MB of text.
- Changes must propagate to all connected clients within 200ms (excluding network latency).
- The system must handle network partitions gracefully (no data loss).
- Server memory per active document should not exceed 50 MB.
What to Design
- Your choice of conflict resolution algorithm (OT vs CRDT) with justification
- The client-server communication protocol
- How cursors and selections are represented and broadcast
- The offline sync and reconnection strategy
- How version history is stored and accessed