System Design AI

Design a Collaborative Document Editor like Google Docs: The Junior, Senior and Staff Answer

You walk into a system design interview and the prompt is “design a collaborative document editor like Google Docs.” The interviewer wants to see how you think about real-time state sharing, consistency guarantees, and scaling a write-heavy workload. They also watch how you break the problem into pieces, choose trade-offs, and communicate a clear request path.

What the interviewer is testing

  • Understanding of real-time collaboration – can you explain operational transformation (OT) or conflict-free replicated data types (CRDTs) and why they matter?
  • Scalability reasoning – can you estimate traffic, shard data, and pick services that grow horizontally?
  • Consistency vs latency – do you know the difference between eventual and strong consistency for edits?
  • Operational thinking – can you discuss monitoring, cost, and failure modes beyond the happy path?

Requirements and driving numbers

RequirementTypical value (hedged)
Concurrent editors per documentup to 10 k (large teams, webinars)
Document sizeup to 1 GB of rich text, images, embedded objects
Edit operationsroughly 100 k ops/second globally (10 k users × 10 edits/sec)
Latency target< 200 ms for edit propagation to all collaborators
Durabilityevery edit persisted within seconds, no loss on node failure

These numbers drive the choice of storage, messaging, and caching layers.

Core design – request path, data model, key choice

1. API gateway & stateless web servers

Clients (web or native) call a thin API layer (Amazon API Gateway + AWS Lambda or EC2). The gateway validates auth, routes to the appropriate service, and returns JSON responses. Keeping the web tier stateless lets us scale with Auto Scaling groups.

2. Edit ingestion service

Each edit hits an Edit Service (EC2 instances behind an Elastic Load Balancer). The service:

  • Assigns a monotonically increasing sequence number using a DynamoDB atomic counter per document.
  • Publishes the edit to a message bus (Kafka on MSK) for ordering and fan-out.
  • Writes the raw operation to an append-only log in S3 for durability and replay.

3. Operational transformation engine

A dedicated OT Worker consumes the Kafka stream, applies the transformation algorithm, and updates the document state store. The state store is a DynamoDB table keyed by documentId that holds the current version and pointers to the document content, which is kept in chunks in S3 because one DynamoDB item cannot exceed 400 KB. DynamoDB was chosen over Aurora because it offers single-digit millisecond latency, automatic scaling, and per-item atomic updates, which are crucial for the high write rate.

4. Real-time push to clients

After transformation, the worker writes the new version to ElastiCache (Redis) Pub/Sub channels per document. Client SDKs maintain a WebSocket connection (via API Gateway WebSocket) that subscribes to the Redis channel. Redis was preferred over SQS because it provides low-latency fan-out to many listeners.

5. Persistence & snapshotting

Periodically (e.g., every 5 min) a Snapshot Service reads the DynamoDB state, serializes a compact snapshot, and stores it in S3. Snapshots enable fast cold starts and recovery after a crash. CloudFront distributes static assets (CSS, JS) and the snapshot files to edge locations.

Data model sketch

Text
DocumentMeta (DynamoDB)
 - documentId (PK)
 - ownerId
 - createdAt
 - latestVersion (int)
 - snapshotKey (S3 URI)

DocumentState (DynamoDB)
 - documentId (PK)
 - stateChunks (S3 keys for the current document content)

EditLog (S3 prefix)
 - documentId/seqNumber.json

The key design decision is using DynamoDB for the authoritative state instead of a relational store. DynamoDB gives us predictable latency and automatic partitioning, which is harder to achieve with Aurora when the write pattern is many small updates per second.

Junior answer coverage

  • Lists functional requirements (real-time editing, version history, permissions).
  • Provides a simple three-tier diagram: client → API server → single relational DB.
  • Mentions using WebSockets for push but does not detail ordering or conflict resolution.
  • Estimates traffic loosely and suggests scaling the web tier with a load balancer.
  • Misses durability strategy, does not discuss sharding, and ignores operational transformation.

Senior answer additions

  • Introduces operational transformation and explains why a deterministic ordering mechanism is needed.
  • Replaces the single DB with DynamoDB for low-latency writes and automatic sharding.
  • Adds a message bus (Kafka/MSK) to guarantee ordered delivery of edits.
  • Shows a diagram with separate services: Edit Service, OT Worker, Snapshot Service.
  • Discusses read-through caching with ElastiCache for fast document fetches.
  • Provides a rough cost estimate (e.g., DynamoDB write capacity units for 100 k ops/sec).

Staff answer depth

  • Failure modes: outlines handling of Kafka broker loss, DynamoDB throttling, and Redis node failures. Describes fallback to S3 replay and client-side buffering.
  • Operational metrics: monitors edit latency, queue depth, DynamoDB throttling events, and cache hit ratio via CloudWatch dashboards.
  • Cost optimization: suggests on-demand vs provisioned capacity, using TTL on DynamoDB items, and tiered S3 storage for older snapshots.
  • Trade-off defense: argues for eventual consistency of the document state (acceptable for collaborative editing) versus the overhead of strong consistency. Defends DynamoDB over Aurora by citing write amplification and scaling complexity.
  • Security: uses AWS IAM policies, KMS-encrypted S3 objects, and token-based auth via Cognito.
  • Operations: describes a CI/CD pipeline for service updates, blue-green deployments, and chaos testing of the edit pipeline.

Mistakes that sink this question

  1. Skipping OT/CRDT – without a conflict-resolution algorithm the design cannot guarantee convergence.
  2. Over-engineering storage – proposing a heavyweight relational database for per-character edits leads to latency bottlenecks.
  3. Ignoring latency – focusing only on durability and forgetting the 200 ms real-time target.
  4. No sharding plan – assuming a single DynamoDB table will handle 100 k ops/sec without partition key design.
  5. Forgetting client sync – not describing how clients recover after a disconnect (replay from S3 snapshot + edit log).

How to practice this

  1. Sketch the request path on a whiteboard: start at the client, trace through API Gateway, Edit Service, Kafka, OT Worker, DynamoDB, Redis, and back to the client.
  2. Write a brief rubric: list functional, non-functional, and scalability criteria. Compare your answer against it.
  3. Study the worked design in the System Design AI library, then draw your own version on the canvas and ask the AI coach for feedback.

Questions people ask

What is operational transformation and why is it needed?

Operational transformation (OT) is an algorithm that adjusts concurrent edits, for example by shifting their positions, so that all participants converge on the same document state. It resolves conflicts by transforming each operation against others that arrived earlier.

Can I use a relational database for a collaborative editor?

You can, but a relational DB struggles with high-frequency small writes and scaling horizontally. NoSQL stores like DynamoDB provide lower write latency and automatic partitioning, which better match the edit pattern.

How do you ensure durability of edits?

Each edit is appended to an immutable log in S3 and also persisted in DynamoDB. If a node fails, the system can replay the log from S3 to rebuild the document state.

What are the main cost drivers for this system?

Write capacity on DynamoDB, Kafka broker throughput, and the amount of data stored in S3 for logs and snapshots. Caching with ElastiCache reduces read load and can lower DynamoDB read costs.