Dashboard/System design/39. Design a Collaborative Document Editing Service/Google Docs

SYSTEM DESIGN · LESSON 39 OF 52 · 13 MIN VIDEO · 5 TOPICS

Design a Collaborative Document Editing Service/Google Docs

Module Progress (0 / 5 Lessons Completed)0%
System design Track (0 / 52 Modules) · Overall 0/80 (0%)0%
⌁

Narrated HD Video Lesson (13 min) · Pro

Lesson Overview + Section #01 + RESHADED Checklist + Quiz #1 are unlocked free below (no login required). Unlock all 80 HD video lessons and deep-dive sections — or watch our two free sample video lessons first.

0% READSec 01/05 · System Design: Google Docs
SYSTEM DESIGN VIDEO LESSON & GUIDE

Design a Collaborative Document Editing Service/Google Docs

A collaborative document editing service like Google Docs enables dozens of concurrent writers to type into the same rich-text document simultaneously with 0 ms perceived local latency and sub-250 ms remote convergence across 80 million daily active users (8 million peak WebSockets, 160 billion keystroke operations/day, 8 TB/day operation log). Whole-file saves silently overwrite peer edits, while pessimistic locks serialize writers into a queue; real-time co-editing requires streaming granular character/range mutations ordered consistently across replicas. L4-L6 interviewers evaluate optimistic local editing, single-server per-document ordering via consistent hashing, Operational Transformation (OT) vs. Conflict-Free Replicated Data Types (CRDTs), and event-sourced Snapshot + Operation Log compaction.

WHAT YOU WILL MASTER IN THIS LESSON
  • Size stateful WebSocket gateways (160 servers at 50K open sockets/host) and identify why the 8 TB/day operation log (8x larger than 1 TB/day new documents) mandates periodic snapshot compaction.
  • Design a dual-plane architecture pairing document-hashed stateful Collaboration Servers and replicated write-ahead queues with stateless HTTPS APIs backed by SQL (ACLs), NoSQL (comments), and Blob + CDN (media).
  • Resolve concurrent index-shift divergence ('CAT' -> 'HAT' vs. 'AHT') using server-serialized Operational Transformation (OT) and single-in-flight client operation buffering.
  • Compare centralized OT against decentralized sequence CRDTs across per-character memory overhead, tombstone garbage collection, offline merge resilience, and per-document active editor caps (~100).
SYSTEMATIC INTERVIEW CHECKLIST · RESHADED + 45-MIN CLOCK

8-Step RESHADED Execution Checklist

Follow this exact sequence from the Intro narration on every system design prompt so you never miss requirements, math, contracts, or the 13-minute deep dive.

0 / 8 Checked
INTERVIEWER SCORECARD · WHAT MAKES A STRONG HIRE?

5 Signals Bar Raisers Grade (L4 vs. L5 Senior vs. L6 Staff)

Senior (L5 / E5 / Senior SDE) Bar — Autonomous Pacing, Depth & Proactive Trade-Offs: Owns the 45-minute clock without prompting, derives every component quantitatively, surfaces failure modes (hot shards, stampedes, dual writes) BEFORE being asked, and defends consistency vs. latency trade-offs.
1. Scoping
✓ STRONG HIRE SIGNAL

Clarifies users, read/write skew, p99 latency, consistency bounds, and explicit non-goals in minutes 2–8.

✗ NO-HIRE RED FLAG

Jumps straight into drawing load balancers and microservices at minute 2 without asking a single question.

2. Right-Sized Design
✓ STRONG HIRE SIGNAL

Starts with the simplest working architecture justified by the math (e.g., 1 NVMe SQL primary + replicas + Redis for 40 writes/s & 3 TB).

✗ NO-HIRE RED FLAG

Recites a memorized Kafka + multi-DC Cassandra diagram that contradicts their own traffic calculations.

3. Technical Depth
✓ STRONG HIRE SIGNAL

Drives deep into 1–2 hard bottlenecks (partition keys, hot-key mitigation, transactional outbox, KV-cache batching) at minute 27.

✗ NO-HIRE RED FLAG

Skims across 12 boxes at identical buzzword depth and runs out of time before the deep dive.

4. Explicit Trade-Offs
✓ STRONG HIRE SIGNAL

Uses 3-part reasoning: 'A queue here because SMTP spikes to 3 s; checkout stays <60 ms, and we accept eventual email delay + retry dedup.'

✗ NO-HIRE RED FLAG

Name-drops tools ('We put Kafka and ZooKeeper here') without stating the alternative or operational cost.

5. Communication
✓ STRONG HIRE SIGNAL

Thinks aloud every 30–45s, checks alignment at phase transitions, and treats 'What if X fails?' as a cue for where points are awarded.

✗ NO-HIRE RED FLAG

Goes silent for 5 minutes while drawing or defends a flawed assumption defensively when nudged.

ARCHITECTURE & DATA-FLOW SLIDES · SLIDE 1 OF 1Section 01: System Design: Google Docs
ARCHITECTURE / DATA FLOW DIAGRAM
same textAliceeditorsame textBobeditorone orderDocumenton a server
SECTION 01 OF 5

1. System Design: Google Docs

★ FREE PREVIEW
Key Takeaway: Whole-file uploads lose concurrent edits and exclusive locks block collaboration; real-time co-editing streams tiny character-level operations and converges by applying them under one agreed causal order.
ARCHITECTURE / DATA FLOW DIAGRAM
same textAliceeditorsame textBobeditorone orderDocumenton a server

Why Whole-File Overwrites and Pessimistic Locks Fail

Allowing multiple authors to edit a shared document exposes an immediate concurrency dilemma. Under naive whole-file upload (Last Writer Wins), Alice downloads v1, appends a paragraph, and saves v2, while Bob—who also opened v1—fixes a single typo a minute later and uploads his full buffer, silently erasing Alice's paragraph. Pessimistic file locking prevents lost updates by granting exclusive write access to Alice while forcing Bob into read-only mode, turning five teammates racing a deadline into a sequential queue. Collaborative editors take a third path: every keystroke emits a compact delta operation (such as insert(pos=4, "H")), ordered centrally and broadcast within < 250 ms so all replicas converge on identical text.

Concurrency ModelWrite UnitMulti-Author UXPrimary Failure Mode
Last Writer Wins (Whole File)Entire document blobConcurrent offline/local editsSilent data loss: later save overwrites peer changes
Pessimistic Exclusive LockDocument-wide lease1 active writer; N-1 blocked readersDestroys live teamwork; orphaned locks on client crash
Granular Operation StreamingCharacter/range op (~50 bytes)Simultaneous sub-second live co-editingIndex shifts diverge unless transformed (OT) or ID-addressed (CRDT)

Three Core Ideas Behind Live Collaboration

Modern cloud editors rest on three tight architectural invariants: mutate the local browser copy immediately on keystroke so typing never waits on network RTT, route all operations for a given doc_id through a single authoritative ordering coordinator so every replica converges, and append every accepted operation to a replicated log backed by periodic full-document snapshots.

  • Edit Locally (0 ms UI latency): Local DOM updates occur synchronously before any network packet leaves the browser.
  • Order Centrally (1 coordinator per active doc_id): Eliminates distributed multi-leader transformation cycles.
  • Log Everything Durably (WAL + Snapshots): Guarantees zero acknowledged-edit loss and supports full version history.
SECTION 02 OF 5

2. Requirements of Google Docs' Design

🔒 PRO SECTION
Key Takeaway: With 80M DAU generating 160 billion operations/day (~1.85M ops/s), the 8 TB/day append-only operation log outgrows raw new document text (1 TB/day) by 8x, making periodic snapshot compaction essential.

Section 1 + Checkpoint Quiz #1 are unlocked free outside the paywall. Unlock all architecture slides, QPS & sharding trade-off tables, and all 80 narrated HD video lessons with Full Access — or inspect our sample payment system lesson first.

SECTION 03 OF 5

3. Design of Google Docs

🔒 PRO SECTION
Key Takeaway: Route all real-time operations for a document via consistent hashing to a single Collaboration Server holding live state in RAM backed by a replicated write-ahead queue, while isolating ACLs in SQL, comments in NoSQL, and media in Blob Storage + CDN.

Section 1 + Checkpoint Quiz #1 are unlocked free outside the paywall. Unlock all architecture slides, QPS & sharding trade-off tables, and all 80 narrated HD video lessons with Full Access — or inspect our sample payment system lesson first.

SECTION 04 OF 5

4. Concurrency in Collaborative Editing

🔒 PRO SECTION
Key Takeaway: Concurrent edits converge either by transforming positional indices against linear server history (OT, used by Google Docs for lean documents) or by assigning immutable per-character identifiers and tombstones that commute in any order (CRDTs).

Section 1 + Checkpoint Quiz #1 are unlocked free outside the paywall. Unlock all architecture slides, QPS & sharding trade-off tables, and all 80 narrated HD video lessons with Full Access — or inspect our sample payment system lesson first.

SECTION 05 OF 5

5. Evaluation of Google Docs' Design

🔒 PRO SECTION
Key Takeaway: Optimistic local edits, single-server per-document serialization, and replicated write-ahead logging satisfy latency, convergence, and durability—at the intentional trade-off of capping concurrent active editors per document to ~100.

Section 1 + Checkpoint Quiz #1 are unlocked free outside the paywall. Unlock all architecture slides, QPS & sharding trade-off tables, and all 80 narrated HD video lessons with Full Access — or inspect our sample payment system lesson first.

ACTIVE RECALL & TRADE-OFF PROBES

System Design Checkpoint Quizzes (1)

CHECKPOINT QUIZ #1

In "System Design: Google Docs" (Why Whole-File Overwrites and Pessimistic Locks Fail), how does a production-grade design handle "Pessimistic Exclusive Lock" (Primary Failure Mode)?