Designing a Collaborative Document Editor (Google Docs) for System Design Interviews
2 views
"Design Google Docs" is a favorite senior-level system design question because it tests real-time communication, conflict resolution and storage design together. Here is a clear way to approach it.
Clarify the scope
Ask how many concurrent editors a single document supports (say up to 100), whether offline editing is required, and what features matter: live cursors, comments, version history and sharing permissions. Agree that low-latency local typing matters most; every keystroke should appear instantly for the person typing.
Real-time transport
Clients keep a WebSocket connection to a collaboration server. All editors of the same document should be routed to the same server, for example by consistent hashing on document ID, so that one process can order operations for that document.
The heart of the problem: concurrent edits
If two users type at the same position simultaneously, naive "last write wins" corrupts the text. Two families of solutions exist:
- Operational Transformation (OT): each edit is an operation (insert "a" at 5). The server orders operations and transforms incoming ones against those already applied, so positions stay correct. Google Docs historically used OT.
- CRDTs: each character gets a unique, ordered identifier, so replicas converge without a central transformer. CRDTs make offline editing and peer-to-peer sync easier at the cost of extra metadata.
You do not need to implement either in detail, but explain the trade-off clearly; that is what interviewers listen for.
Storage and history
Persist the operation log to durable storage, and periodically write snapshots so loading a document does not require replaying millions of operations. Version history becomes a list of snapshots plus operation ranges.
Presence and cursors
Cursor positions and "who is viewing" are ephemeral; broadcast them over the same WebSocket but never persist them.
Permissions and scale
An access control service checks view, comment and edit rights on connect. Most documents are idle most of the time, so collaboration servers only hold active documents in memory and evict idle ones.
Failure handling
If a collaboration server dies, clients reconnect, are routed to a new owner, which loads the latest snapshot plus log, and clients resend unacknowledged operations.
Interview tips
Lead with requirements, name OT versus CRDT early, and spend your time on ordering and convergence. Practice explaining it in plain words. Linkjob AI (https://linkjob.ai) offers real-time help during live technical interviews, which can be handy when a follow-up about offline conflicts catches you off guard.