Design a real-time collaborative document editor like Google Docs
by shadow5446
7
386
Staff level system design at Meta. They expect you to drive the conversation and make tradeoffs independently.
The core challenge is conflict resolution when multiple users edit simultaneously. I discussed two approaches: OT (Operational Transform) and CRDT (Conflict-free Replicated Data Types).
Went with CRDT because it's more naturally suited to distributed systems and doesn't require a central server for transformation. Used a tree-based CRDT where each character has a unique ID based on its position and the user's ID.
For the networking layer, used WebSockets for real-time updates with fallback to long polling. Each document has a collaboration server that maintains the current state and broadcasts operations to all connected clients.
Scaling was the main focus. A single document can have hundreds of concurrent editors. Discussed sharding by document ID and using a coordinator service for hand-off when a document moves between servers.
The cursor and selection sharing was a good detail to bring up. Each client sends cursor position updates that are rendered with user-specific colors.
Also discussed offline editing: queue operations locally and reconcile when reconnected. The CRDT properties guarantee eventual consistency without conflicts.
The interviewer pushed on performance: what if the document is 100 pages with hundreds of images? Discussed lazy loading of document sections and chunked syncing.