Asked at
URL Shortener (TinyURL)
Asked from Junior level upFoundations & Storage
Distributed Rate Limiter
Asked from Mid level upAPI Gateway & Security
Distributed Key-Value Store
Asked from Senior level upFoundations & Storage
Distributed Notification Service
Asked from Mid level upMessaging & Queues
Distributed Web Crawler
Asked from Mid level upDistributed Systems
Metrics & Monitoring Platform
Asked from Senior level upObservability & Time-Series
Real-Time Chat App (like WhatsApp or Slack)
Asked from Mid level upReal-Time & WebSockets
Social News Feed (like X/Twitter)
Asked from Mid level upSocial & Feed Systems
Ride-Hailing App (like Uber)
Asked from Senior level upGeospatial & Real-Time
Low-Latency Stock Exchange Matching Engine
Asked from Staff level upFintech & Low Latency
Global Video Streaming Platform (like YouTube or Netflix)
Asked from Senior level upMedia & Streaming
Distributed Hotel & Ticket Reservation System
Asked from Mid level upE-Commerce & Transactions
Shared Document Editor (like Google Docs)
Asked from Staff level upReal-Time & Distributed State
Game Leaderboard
Asked from Junior level upCaching & Data Structures
File Sync Service (Dropbox / Google Drive)
Asked from Mid level upStorage
Payment System
Asked from Senior level upPayments & Transactions
Ad Click Aggregation
Asked from Senior level upStream Processing
AI Support Assistant (RAG)
Asked from Senior level upAI Systems
LLM Inference Platform
Asked from Senior level upAI Systems
Enterprise Semantic Search
Asked from Mid level upAI Systems
AI Code Completion
Asked from Senior level upAI Systems
LLM Gateway
Asked from Senior level upAI Systems
AI Agent That Takes Actions
Asked from Senior level upAI Systems
LLM Evaluation Platform
Asked from Senior level upAI Systems
AI Document Processing Pipeline
Asked from Mid level upAI Systems

Design a Shared Document Editor (like Google Docs)

Asked from Staff level upDomain: Real-Time & Distributed State
Concepts to know first:

Design an editor where many people change one document at the same time. Clashing edits must be merged, and edits made offline must sync later.

An analogy

Think of Google Docs like two painters working on the same canvas from far apart. When painter A adds a blue stroke and painter B adds a red stroke, an orchestrator blends the two strokes without smudging either one.

Where this design ends up. This is version 3 of 3. Part 5 builds it up from version 1 and says why each part was added.
  1. Clients
    • Editor A
    • Editor B
  2. Entry
    • WebSocket gateway
  3. Services
    • Document service
    • Snapshot worker
  4. Queues, caches
    • Sync channel
  5. Data, outside
    • Document store

1. Requirements and scope

Functional Requirements
  • Several people edit the same document at once, and each sees where the others are typing.
  • Clashing edits are merged by fixed rules, so once all edits arrive, everyone sees the same text.
  • Support document revision history and offline editing.
Non-Functional Requirements & SLAs
  • Sub-50ms keystroke broadcast latency.
  • High availability and partition tolerance.
  • Zero data loss or character transposition.
Key Traffic Assumptions: 50 Million active documents, up to 50 concurrent editors per document.

2. Back-of-the-envelope numbers

Writes and reads each second
  • Writes: 50,000 keystrokes a second (33%)
  • Reads: 100,000 document reads a second (67%)

Balanced: reads and writes are close. Both paths need care, so neither can be slow.

Write Throughput
50,000 keystroke operations/sec
Read Throughput
100,000 document reads/sec
Storage Growth
Document snapshot + change log: ~20 TB / year
RAM Cache Footprint
The live state of each open document is kept in memory on the WebSocket servers

3. API

WS/ws/documents/{docId}WebSocket channel for streaming character operations and cursor vectors
GET/api/v1/documents/{docId}/snapshotFetch latest compiled document state

4. Data model and storage

Storage Strategy: Every edit is added to the end of a log, in Cassandra or PostgreSQL. A full copy of the document is saved to S3 now and then.
DOC_OPERATIONS: (doc_id, op_id, user_id, op_type, position, character, vector_clock)

5. The design, in three versions

Version 1: Document Lock (Pessimistic Editing)

When one user edits, the entire document is locked for all other users.

Shared Document Editor (like Google Docs): Version 1: Document Lock (Pessimistic Editing) Version 1 of 3

The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.

One request, step by step

Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.

Editor AEditor BDocument serviceDocument store123
  • The order of the steps
  • A request or its reply

The parts: switch one off

1. Clients

Editor Atypes a letter
Editor Bsees the change

2. Services

Document serviceorders and merges edits

3. Data, outside

Document storesnapshots and the edit log

The steps in words0 of 3 steps shown

  1. Editor A to Document serviceHTTPS · 3 ms

    Editor A asks for the lock on the document.

  2. Document service to Document storequery · 8 ms

    A's edit is saved.

  3. Document service to Editor Breply · 20 ms

    Editor B must wait for the lock, then loads the new text.

Why this version
Very simple, with zero concurrency conflicts.
Next bottleneck
Only one user can type at a time; eliminates real-time collaboration.

Write path, read path and failures

Each path follows one request through the final design (version 3), one hop at a time.

Write pathType a character

  1. Client
  2. Local copy
  3. WebSocket gateway
  4. Operation log
  5. Sync channel
  6. Other clients
  1. Client to Local copy

    Asha types "x". Her app applies it to its own copy at once, so typing never waits on the network.

  2. Client to WebSocket gateway

    The app sends the change as a small operation: insert "x" after character id 17.

  3. WebSocket gateway to Operation log

    The server appends the operation to the document's log.

  4. WebSocket gateway to Sync channel

    It publishes the operation to every server that holds a connection for this document.

  5. Sync channel to Other clients

    Each server pushes it to its editors. Their apps merge it, and every copy ends with the same text.

Read pathOpen a document

  1. Client
  2. Document API
  3. Snapshot storage
  4. Operation log
  5. WebSocket gateway
  1. Client to Document API

    Ben opens the document.

  2. Document API to Snapshot storage

    The API loads the latest saved snapshot of the whole document.

  3. Document API to Operation log

    It reads the operations made since that snapshot and applies them.

  4. Client to WebSocket gateway

    Ben's app connects for live changes, starting from the last operation it has.

What breaks, and what happens then

  • A user goes offline while editing

    What users see
    Their changes cannot reach the server.
    What the design does
    The app keeps the operations and sends them on reconnect. They merge without overwriting anyone's work.
  • Two people type at the same place

    What users see
    The copies could end in a different order.
    What the design does
    Each character has a unique id, and ties are broken by a fixed rule. Every copy applies the same rule.
  • A WebSocket server crashes

    What users see
    Its editors are disconnected.
    What the design does
    They reconnect to another server and ask for the operations after the last one they saw.
  • The operation log grows very long

    What users see
    Opening the document gets slow.
    What the design does
    A worker saves a new snapshot every few minutes, so only recent operations need replaying.

6. Deep dives

Operational Transformation (OT) vs CRDT
OT, used by Google Docs, has a central server put every edit in order. It shifts each edit so it still fits edits made at the same time. A CRDT, as in the Yjs and Automerge libraries, gives each character its own unique ID. Inserts and deletes can then arrive in any order and still end up in the same place, with no central server needed.

7. Follow-up questions

  • How do you manage CRDT memory bloat for large 500-page books? (Answer: Periodic garbage collection compaction into immutable S3 snapshot blocks with tombstones deleted).

What it costs

Open connections and memory are the cost: each open document lives in memory on a server. The change log grows by about 20 TB a year. Save a snapshot now and then, so old changes can be dropped.

Another way to design it

Operational transformation with one central server is the other well-known design. The server puts all edits in one order, so clients stay simple. A CRDT fits better when people edit offline for long periods.

8. How answers are judged

A passing answer at Mid level. A complete design with numbers: about 50,000 keystroke operations a second across all documents. It explains how the server orders conflicting edits and goes deep on one part, such as syncing or storage.

How each level is judged
What is judgedJuniorMidSeniorStaff
BreadthHow much of the system does the answer cover?Names the core parts: clients, servers, a database and a cache.Covers the whole main flow, from the request to the stored data and back.Builds a complete design without being led through it.Covers the system, the systems around it and who owns each part.
DepthHow far does it go into the hard parts?Explains what each part does and why it is there.Goes deep on one part, such as the database or the cache.Goes deep on the two or three riskiest parts.Goes deepest where the risk is largest, and explains why the risk is there.
DrivingWho leads the conversation?Follows the interviewer, step by step.Moves forward alone, with an occasional nudge.Leads the conversation from start to finish.Changes the problem when the question asked is not the right one.
Trade-offsAre choices compared and justified?Names more than one option.Says why one option was picked over another.Compares options in detail, with what each one costs.Ties each choice to cost, speed and risk for the business.
Unclear questionsWhat happens when the question is vague?Answers the questions that are asked.Asks questions to make the problem clear.Sets the scope and says what is left out.Questions the assumptions behind the problem itself.
ScopeWhat does it consider beyond the normal path?Covers the normal path, when everything works.Adds what happens when a part fails.Adds growth: what breaks at ten times the load, and the fix.Adds abuse, cost and the daily work of running the system.

Requirements and scope

Strong answer
Before I design, I want to check the scope. Every document syncs edits between up to 50 concurrent editors, and offline edits must merge instead of overwriting. Does every keystroke need to reach others in under 50 milliseconds, or only the ones a user is actively watching? I will treat cursor positions as separate, lossy traffic from the edits themselves.
Weak answer
Multiple users open the same document and their keystrokes broadcast to each other live over a socket. Since everyone is online and editing together, I will not worry about offline support and start on the protocol.

Shows: Unclear questionsThe difference: The problem includes offline editing and merging as a requirement. Assuming everyone is always online skips a case the design must handle.

Estimates

Strong answer
50,000 keystroke operations a second is the write load, with reads about twice that, at 100,000 document loads a second. Each operation is about 100 bytes with its position, character and vector clock, so a year of raw log is about 160 terabytes. Snapshots that let old operations drop keep real storage near the stated 20 terabytes a year.
Weak answer
50,000 keystroke operations a second is the write load, so I would size the WebSocket fan-out for that same 50,000 messages a second going out.

Shows: DepthThe difference: Each keystroke broadcasts to up to 50 other editors on that document. Outbound traffic runs closer to 50 times the inbound rate, not the same as it.

Core design

Strong answer
Each client sends its edits over a WebSocket to the document's own server, the single source of truth for that document. The server places incoming edits in order and transforms each one against edits it has not seen yet. It then broadcasts the transformed edit to every other client. Every edit also appends to an operation log.
Weak answer
Each client sends its edits straight to the other connected clients over the socket. Every client applies incoming edits to its own copy of the text in the order they arrive.

Shows: DepthThe difference: Edits can reach each client in a different order, so their text differs. OT orders every operation through a central server; CRDTs use globally unique ids instead. Either fixes it.

Deep dive

Strong answer
The hard part is keeping every copy of the document identical without one lucky ordering. With OT, a central server orders every operation and transforms each one against what came before. I would only reach for CRDTs if offline-first editing across days mattered enough. Each character then gets a globally unique id, at the cost of far higher memory use.
Weak answer
When a device reconnects after being offline, I would replay its queued edits in the order it made them. Each one applies to whatever the document looks like now.

Shows: DepthThe difference: Positions recorded offline no longer match the document once others have edited it, so a replayed edit can land in the wrong place. OT or CRDTs avoid that instead.

Failures and trade-offs

Strong answer
If the network drops packets, cursor and presence updates stay lossy, on their channel apart from the text stream. A missed cursor position costs nothing. If a document's server crashes, a new server rebuilds its state from the last snapshot plus the operation log since. Reconnecting clients wait a short, random delay, so they do not all resync at once.
Weak answer
If a document's server crashes and restarts, every connected client reconnects right away and asks it to resync the whole document. All of this happens at the same moment the server is still cold.

Shows: ScopeThe difference: That reconnect storm can overload the server right as it restarts, since nothing spreads the resyncs out. A short random delay before reconnecting avoids that.

We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.

10. Check your design with your own AI

Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.

The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.

See the prompt
You are a system design interviewer. Review my design for the interview problem below.

Problem: Design a Shared Document Editor (like Google Docs)
Design an editor where many people change one document at the same time. Clashing edits must be merged, and edits made offline must sync later.

What users must be able to do:
- Several people edit the same document at once, and each sees where the others are typing.
- Clashing edits are merged by fixed rules, so once all edits arrive, everyone sees the same text.
- Support document revision history and offline editing.

How well it must work:
- Sub-50ms keystroke broadcast latency.
- High availability and partition tolerance.
- Zero data loss or character transposition.

Numbers to assume:
- 50 Million active documents, up to 50 concurrent editors per document.

Judge my design at the Mid level.
A passing answer at this level: A complete design with numbers: about 50,000 keystroke operations a second across all documents. It explains how the server orders conflicting edits and goes deep on one part, such as syncing or storage.

For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each:
1. Requirements and scope
2. Estimates
3. Core design
4. Deep dive
5. Failures and trade-offs

Then ask me the two follow-up questions an interviewer would ask next.
Do not write a full model answer for me.

My design:
[Describe your parts, how one request moves through them, and why you chose each one.]