Requirements & scope
Problem Statement & Requirements
Functional Requirements
- Concurrent editing — multiple users edit the same document simultaneously
- Real-time sync — edits appear on all collaborators' screens within ~100 ms
- Conflict resolution — concurrent edits to the same section must merge correctly without data loss
- Cursor & selection sync — see where other users' cursors are and what they've selected
- Presence — show who is currently viewing/editing the document
- Undo/redo — per-user undo that doesn't revert other users' changes
- Version history — view and restore previous versions of the document
- Comments & suggestions — inline annotations anchored to document positions
- Offline editing — queue local changes and sync when reconnected
- Rich text — bold, italic, headings, lists, tables, images
Non-Functional Requirements
- Low latency — local edits appear instantly (< 16 ms); remote edits visible within 100-200 ms
- Consistency — all users converge to the same document state (eventual consistency)
- High availability — documents always editable, even during partial outages
- Scalability — support millions of documents, thousands with 50+ concurrent editors
- Durability — no data loss; every accepted edit is persisted
- Ordering — causal ordering of operations preserved
Out of Scope
- Spreadsheet-specific features (cell formulas, recalculation)
- Presentation/slides editing
- Drawing/whiteboard (requires different data model)
- Real-time voice/video (that's WebRTC)
Scale estimations
Scale Estimations
Users & Documents
| Metric | Value |
|---|---|
| Total users | 500M |
| Daily Active Users (DAU) | 50M |
| Total documents | 5B |
| Documents edited per day | 100M |
| Avg concurrent editors per document | 3-5 |
| Max concurrent editors (edge case) | 100+ |
| Avg edits per user per minute | 30 (typing) |
Operations
| Metric | Value |
|---|---|
| Edits per second (global) | 50M DAU × 30 edits/min × (10 min active/session) / 86400 = ~175K ops/sec |
| Peak edits per second | ~500K ops/sec |
| Cursor position updates per second | ~350K/sec (2× edit rate, includes mouse moves) |
| WebSocket connections (concurrent) | ~10M |
Storage
| Metric | Value |
|---|---|
| Average document size | 50 KB (text only) |
| Average operation size | 100 bytes |
| Operations per document per day | ~1,000 |
| Operation log storage per day | 100M docs × 1,000 ops × 100 bytes = ~10 TB/day |
| Document snapshots | 5B × 50 KB = ~250 TB |
| Operation log (30-day retention before compaction) | ~300 TB |
Network
| Metric | Value |
|---|---|
| Inbound (edits) | 175K × 100 bytes = ~17.5 MB/s |
| Outbound (broadcast to collaborators) | 17.5 MB/s × avg 3 collaborators = ~52.5 MB/s |
| WebSocket server count (20K conn/server) | ~500 servers |
Layered architecture
High-Level Architecture
High-Level ArchitectureExcalidraw diagram · editable shapes · reveal step by stepExplore
Detailed Component Architecture
Detailed Component ArchitectureExcalidraw diagram · editable shapes · reveal step by stepExplore
API & contracts
Detailed OT Client-Server Protocol
Client State Machine
Client State MachineExcalidraw diagram · editable shapes · reveal step by stepExplore
Server-Side OT Processing
Server-Side OT ProcessingExcalidraw diagram · editable shapes · reveal step by stepExplore
Data model
Document Storage & Versioning
Snapshot + Operation Log Model
Snapshot + Operation Log ModelExcalidraw diagram · editable shapes · reveal step by stepExplore
Data Model
Data ModelExcalidraw diagram · editable shapes · reveal step by stepExplore
Core design decisions
The Core Problem: Concurrent Editing
The Core Problem: Concurrent EditingExcalidraw diagram · editable shapes · reveal step by stepExplore
Algorithm Deep Dive: OT vs CRDTs
Option 1: Operational Transformation (OT)
Option 1: Operational Transformation (OT)Excalidraw diagram · editable shapes · reveal step by stepExplore
OT Transform Rules
OT Transform RulesExcalidraw diagram · editable shapes · reveal step by stepExplore
OT Architecture (Google Docs Approach)
OT Architecture (Google Docs Approach)Excalidraw diagram · editable shapes · reveal step by stepExplore
Option 2: CRDTs (Conflict-free Replicated Data Types)
Option 2: CRDTs (Conflict-free Replicated Data Types)Excalidraw diagram · editable shapes · reveal step by stepExplore
OT vs CRDT Comparison
OT vs CRDT ComparisonExcalidraw diagram · editable shapes · reveal step by stepExplore
Request flows
Workshop note · added for the website’s common reading format
- Editor clients: Apply local edits immediately and track operations awaiting server acknowledgement.
- WebSocket gateway: Authenticate users and route each connection to its active document session.
- Collaboration engine: Transform concurrent operations against accepted history so clients converge on a shared document.
- Presence service: Broadcast transient cursor state separately from durable document changes.
- Operation log: Append accepted operations for recovery, replay, and reconnect catch-up.
- Document store: Periodically snapshot the document so replay cost stays bounded.
Performance & caching
Workshop note · added for the website’s common reading format
Start with the dominant access pattern of Real-Time Collaboration. Operation log is one place to inspect capacity and tail latency. Measure before introducing a cache: define the cache key, invalidation policy, stale-data budget, and cold-start behavior.
Batch independent work where the latency budget allows it. Bound queues and concurrency, and verify that an optimization does not move the bottleneck to a dependency.
Advanced design
Cursor & Selection Sync
Cursor & Selection SyncExcalidraw diagram · editable shapes · reveal step by stepExplore
Presence System
Presence SystemExcalidraw diagram · editable shapes · reveal step by stepExplore
Rich Text Document Model
Rich Text Document ModelExcalidraw diagram · editable shapes · reveal step by stepExplore
Comments & Suggestions
Comments & SuggestionsExcalidraw diagram · editable shapes · reveal step by stepExplore
Document Session Management
Document Session ManagementExcalidraw diagram · editable shapes · reveal step by stepExplore
Edge cases
Offline Editing
Offline EditingExcalidraw diagram · editable shapes · reveal step by stepExplore
Undo/Redo in Collaborative Context
Undo/Redo in Collaborative ContextExcalidraw diagram · editable shapes · reveal step by stepExplore
Tradeoffs
Tradeoffs & Design Decisions Summary
| Decision | Option A | Option B | Chosen | Why |
|---|---|---|---|---|
| Sync algorithm | OT (Operational Transformation) | CRDT (Conflict-free Replicated Data Types) | OT (server-centric) | Lower memory overhead, battle-tested (Google Docs), simpler architecture with central server |
| Architecture | Peer-to-peer | Central server | Central server | Simpler OT (single serialization point), easier persistence, permissions enforcement |
| Document model | Flat text (positions) | Tree-based (ProseMirror) | Tree-based | Rich text requires structure (paragraphs, lists, tables) |
| Storage | Full document per edit | Snapshot + operation log | Snapshot + op log | Space-efficient, enables version history, supports audit trail |
| Session routing | Random (any node) | Sticky by doc_id | Sticky | Single-threaded OT per doc — all ops for a doc must go to same node |
| Cursor sync | Reliable (guaranteed delivery) | Unreliable (fire-and-forget) | Unreliable | Cursors are ephemeral; next update corrects any missed one |
| Snapshot frequency | Every operation | Every 1,000 ops | Every 1,000 ops | Balance between recovery speed and storage cost |
| Offline | Disallow | OT transform chain | OT + fallback to 3-way merge | OT works for short offline; 3-way merge for extended offline |
| Undo model | Global undo stack | Per-user undo stack | Per-user | User's undo should only revert their own operations |
| Comments | Position index | Marker-based anchoring | Markers | Markers move with text as document changes |
| Op log storage | MySQL | Cassandra | Cassandra | Append-heavy, partition by doc_id, linear scaling |
Reliability & fault tolerance
Workshop note · added for the website’s common reading format
Use explicit session ownership and recovery rules to avoid concurrent authoritative editors.
Set service-level objectives for the user-visible path, then map its dependencies. Define bounded retries with jitter, deadlines, and backpressure. Keep a degraded mode that protects authoritative state, and test recovery instead of treating replication as a backup.
For Real-Time Collaboration, pay special attention to Operation log, Document store, Offline buffer when deciding failure domains and recovery procedures.
Production architecture
Production Architecture
Production ArchitectureExcalidraw diagram · editable shapes · reveal step by stepExplore
Further exploration
Workshop note · added for the website’s common reading format
Rebuild Real-Time Collaboration from memory, then change one assumption: ten times more traffic, a new region, or a stricter consistency requirement. Which component must change first—and which does not?
Compare Collaboration engine with the same boundary in a related design. Write down one alternative you rejected, what it would simplify, and when you would choose it instead. Follow the source link at the end of this article to explore the original document.
Interview playbook
Interview Tips
Start by stating the core challenge — "The fundamental problem is: two users edit the same word at the same time. How do we merge without losing either edit?" This frames everything.
Draw the OT diamond — Show state S, two concurrent ops, and how transformation produces the same result S' regardless of order. This visual sells your understanding.
Compare OT vs CRDT — Even if you choose one, show you know the other. "OT requires a central server but uses less memory. CRDTs work peer-to-peer but carry tombstone overhead."
Client state machine is a great deep dive — Show SYNCHRONIZED → AWAITING_ACK → AWAITING_ACK_WITH_BUFFER. This proves you understand the practical implementation, not just theory.
Don't forget cursors — Interviewers love the cursor sync detail. "Cursor positions must be transformed against incoming operations. We throttle cursor updates to 20/sec and use unreliable delivery."
Snapshot + op log for storage — "We don't store the full document on every keystroke. We take snapshots every 1,000 ops and replay the op log to reconstruct any revision."
Session stickiness is essential — "All operations for a document must route to the same server node. This gives us single-threaded OT — no distributed consensus needed for operation ordering."
Mention undo correctness — "Per-user undo stack. When you hit Ctrl+Z, it reverts YOUR last operation, not someone else's. The inverse is transformed against all subsequent ops."
Version history comes for free — "Because we store the operation log, version history is just 'replay ops from snapshot to revision N.' Diff is computed from the op sequence."
Name real implementations — "Google Docs uses server-centric OT. Figma uses CRDTs. Yjs is the most popular open-source CRDT library." This shows industry awareness.