HARDReal-time Systemsstaff engineer

Design Google Docs

Design a real-time collaborative document editing system like Google Docs supporting multiple concurrent editors.

Estimated Time: 60 minutes
#collaboration#real-time#ot#crdt#websocket
Solution Overview

Use Operational Transformation (OT) or CRDTs for conflict resolution, WebSockets for real-time sync, and document versioning.

Hints to Get Started
1

Research OT vs CRDT approaches

2

How do you handle cursor positions?

3

Consider offline editing scenarios

Requirements

functional

  • Create/edit documents
  • Real-time collaboration
  • Version history
  • Comments
  • Sharing/permissions

non functional

  • Strong consistency for edits
  • Low latency sync
  • Offline support
  • Scale to millions of docs
System Architecture Diagram

Architecture diagram visualization

(Diagram generation coming soon)

data flow

  • Client sends operation
  • Server transforms against concurrent ops
  • Broadcast to all clients
  • Persist to storage

components

  • WebSocket Gateway
  • Document Service
  • OT/CRDT Engine
  • Storage Service
  • Permission Service
Storage

documents

Object storage for content

snapshots

Periodic snapshots for fast loading

operations

Append-only log of operations

Deep Dives

offline

Queue operations locally, sync on reconnect

large docs

Chunk documents, load visible portions

cursor sync

Broadcast cursor positions via WebSocket

Conflict Resolution

crdt

cons

  • Higher memory overhead
  • Limited operation types

pros

  • No central coordinator
  • Eventually consistent

description

Conflict-free Replicated Data Types

operational transformation

cons

  • Complex to implement correctly
  • Server coordination needed

pros

  • Battle-tested (Google Docs)
  • Works well for text

description

Transform operations against concurrent operations