0%
System requirements
Functional
Capacity estimation
Users and Sessions
API design
REST (Control Plane)
Database design
Operation Log
High-level design
Client Layer
Request flows
Real-Time Concurrent Editing
Detailed component design
Operational Transformation (OT)
Trade-offs and tech choices
OT vs CRDT
Failure scenarios
Server Crash
Future improvements
Rich Text CRDT
System requirements
Functional
Capacity estimation
Users and Sessions
API design
REST (Control Plane)
Database design
Operation Log
High-level design
Client Layer
Request flows
Real-Time Concurrent Editing
Detailed component design
Operational Transformation (OT)
Trade-offs and tech choices
OT vs CRDT
Failure scenarios
Server Crash
Future improvements
Rich Text CRDT
Two people type into the same paragraph at the same instant. One adds a sentence, the other deletes a word. The core challenge of Google Docs is not building a text editor; it is merging those concurrent edits without losing either person's work.
The numbers below drive every architectural choice. Pay attention to ops/sec, it tells us why we need a specialized conflict-resolution algorithm instead of database locks.
The API splits into two channels: REST for infrequent control actions and WebSocket for the continuous stream of edits. Sending an HTTP request per keystroke would add 50-100ms of overhead per edit, unacceptable for real-time typing.
The database follows an event-sourcing pattern. Instead of storing the latest text and overwriting on every keystroke, we store the stream of operations that produced it. This gives us revision history, offline merge capability, and crash recovery for free.
Event sourcing inverts the typical database model. In a traditional approach, the document text is the primary data and history is a derived feature. In event sourcing, the operation log is the primary data and the current document text is derived by replaying operations. This inversion makes every feature that depends on history (versioning, undo, merge) a natural consequence of the storage model rather than an afterthought.
The architecture has four layers, each with a distinct responsibility. The client holds a local copy and applies edits instantly. The collaboration server merges operations from all connected clients. A PubSub bus synchronizes servers across regions. The storage layer persists the op log and snapshots.
Two flows define this system: real-time concurrent editing (Alice and Bob typing simultaneously) and offline sync (Carol reconnects after hours offline). Both use the same merge algorithm, the offline case is simply a delayed version of the real-time case. Understanding both flows is essential because they demonstrate that the architecture handles the full spectrum of connectivity, from perfect real-time to extended disconnection.
The question "how do you merge concurrent edits?" is the question an interviewer is really asking when they say "design Google Docs." The conflict-resolution algorithm is what makes this problem unique. Everything else (APIs, databases, load balancers) is standard infrastructure that appears in many system design problems. This section is the GATE.
Two algorithms dominate: Operational Transformation (OT) and Conflict-free Replicated Data Types (CRDT). Both guarantee convergence, every replica reaches the same state. They differ in how they achieve it. Understanding both, including their trade-offs, is what separates a strong answer from a surface-level one.
Three decisions cascade through the entire design: which merge algorithm, what consistency model, and whether to batch writes. Each choice has clear costs and benefits. In an interview, explicitly state the trade-off for each decision, do not just name the choice, explain what you gain and what you pay.
A collaboration server crashes mid-edit. A network partition splits editors across continents. A viral document attracts 100 simultaneous editors. Each failure traces back to a core design choice, and in an interview, connecting the failure to the design decision demonstrates deep understanding.
The collaboration server holding a document's state crashes. All connected editors lose their WebSocket connection.
Four extensions beyond the core design: richer content types, real-time presence visualization, cross-region optimization, and smarter conflict handling. Each builds on the CRDT foundation without requiring fundamental architectural changes.
The current design operates at the character level (plain text only. Rich text adds formatting ranges) bold characters 5-10, italic characters 12-15. When a user inserts a character at position 7, the bold range must expand to include it. When another user inserts at position 12, the system must decide whether the new character inherits italic formatting. This boundary problem is one of the hardest aspects of rich text CRDT.
Reading a solution is not the same as producing one under interview pressure. Design it on the whiteboard and get scored feedback.
Company guides that list this problem among their sample questions.
0%
System requirements
Functional
Capacity estimation
Users and Sessions
API design
REST (Control Plane)
Database design
Operation Log
High-level design
Client Layer
Request flows
Real-Time Concurrent Editing
Detailed component design
Operational Transformation (OT)
Trade-offs and tech choices
OT vs CRDT
Failure scenarios
Server Crash
Future improvements
Rich Text CRDT
System requirements
Functional
Capacity estimation
Users and Sessions
API design
REST (Control Plane)
Database design
Operation Log
High-level design
Client Layer
Request flows
Real-Time Concurrent Editing
Detailed component design
Operational Transformation (OT)
Trade-offs and tech choices
OT vs CRDT
Failure scenarios
Server Crash
Future improvements
Rich Text CRDT