Designing a Collaborative Editing Platform (Google Docs / Notion)
Difficulty: Advanced Topics: Real-Time Collaboration, OT/CRDT, WebSocket, Conflict Resolution, Presence Awareness Asked at: Google, Notion, Figma, Microsoft, Amazon · Prerequisites: WebSockets and Consistency Models
1. Understanding the Problem
A collaborative editing platform lets multiple users simultaneously edit the same document in real-time - seeing each other’s cursors, changes appearing character-by-character as they type, without any user overwriting another’s work. The hard part? When two users type at the same position in the same millisecond, you need a deterministic way to merge both changes without data loss, all while maintaining sub-100ms latency so typing feels instant.
2. Naive First Cut
flowchart LR
User1["User 1 Browser"]
User2["User 2 Browser"]
API["API Server"]
DB["Postgres DB"]
User1 --> API
User2 --> API
API --> DB
How this breaks:
- Last-write-wins in Postgres means User 1’s edits silently disappear when User 2 saves - data loss
- No way to push changes to other users in real-time - polling every second is too slow and wasteful
- Storing the full document on every keystroke creates massive write amplification (100 chars/min × millions of docs)
- No conflict resolution - concurrent edits at the same position produce garbled text
- Single API server can’t maintain persistent connections for millions of active editors
- No presence awareness - users have no idea others are editing, leading to conflicting sections
The rest of the doc evolves this into a production-grade real-time collaborative editing system using operational transformation (OT) and persistent WebSocket connections.
💡 Operational transformation is the idea that an edit carries a position, and that position has to be adjusted before being applied somewhere the text has already moved. “Insert at character 5” means something different once somebody else has deleted character 3, and OT is the rule for rewriting it.
3. Prior Art We’re Drawing From
- Google Wave OT - Pioneered Operational Transformation for real-time collaborative editing. Jupiter protocol with a central server that transforms concurrent operations to maintain consistency. (Google Research)
- Figma CRDT - Uses a custom CRDT (Conflict-free Replicated Data Type) for multiplayer design editing with no central coordination for conflict resolution. Demonstrated CRDTs can work at scale with structured documents. (Figma Engineering Blog)
💡 A conflict-free replicated data type (CRDT) is a data structure designed so that merging two copies always produces the same answer regardless of the order the changes arrive in. That removes the need for a central referee - the contrast with OT, where a server decides the order for everyone. Learn more → - Yjs - Open-source CRDT framework used by Notion, JupyterLab, and others. YATA algorithm for text sequences with O(1) amortized insertion and efficient encoding. (Yjs GitHub)
- Automerge - Research CRDT library that treats documents as mergeable JSON structures. Demonstrates how CRDTs handle offline editing and eventual convergence. (Ink and Switch)
- Google Docs Jupiter Protocol - Server-mediated OT where each client sends operations to a central server that transforms and broadcasts them. Single point of serialization ensures total ordering. (Operational Transformation FAQ)
4. Functional Requirements
Core (Top 3)
- Real-time collaborative editing - multiple users type simultaneously in the same document with changes appearing within 100ms for all participants
- Document storage and retrieval - create, open, and save documents; persist all content durably
- Version history - view previous versions of a document, restore any earlier state, see who made what changes
Below the Line
- Rich text formatting (bold, italic, headings, lists)
- Comments and suggestions (track changes)
- Offline editing with sync on reconnect
- Access control and sharing permissions
- Real-time presence indicators (cursors, selections)
- Document templates and search
5. Non-Functional Requirements
Core
| NFR | Target |
|---|---|
| Edit propagation latency | < 100ms from one user’s keystroke to appearing on another user’s screen |
| Consistency | Eventual consistency - all users converge to the same document state regardless of operation order |
| Availability | 99.99% - document editing must never be “down” during work hours |
| Scale | Support 100M+ documents with up to 50 concurrent editors per document |
Below the Line
- Version history retained for 30+ days
- Document size up to 1M characters
- Support 10M+ daily active users across all documents
- Sub-second document open time (cold start)
6. Scale Estimation (Back-of-Envelope)
- Users: 100M DAU, 5M concurrent editing sessions at peak, spread over ~2M open documents
- Write QPS: a typist emits ~5 ops/sec, and roughly 20% of open sessions are actively typing at any instant, so ~1M ops/sec sustained across all documents
💡 QPS means queries per second - here, edit operations per second. An “op” is one keystroke-sized change, not a whole save, which is why the rate is so high and each item so small. - Hot document: ~50 concurrent editors is the realistic ceiling, giving ~250-500 ops/sec on a single document
- Read QPS: 50K document opens/sec (initial state load + presence sync)
- Storage: ~10TB of current document state (500M documents × avg 20KB), before version history
- Bandwidth: ~10 Gbps (1M ops/sec × ~100 bytes, fanned out to ~2.5 collaborators each, plus framing and presence)
The numbers that shape the design: 1M ops/sec to serialize, 5M live connections to hold, and a 100ms budget for an edit to reach the other editors.
Discussion
Newest first