✏️ Explanatory Question

Design the high-level architecture for a real-time collaborative editor.

👁 10 Views
📘 Detailed Answer
🟢 Easy
No previous question
No next question
💡

Answer with Explanation

The core constraint: multiple users edit the same document simultaneously, everyone must converge on the same final state, and no edit may be lost.

Connection layer - WebSockets, not HTTP polling, because updates must be pushed with sub-100 ms latency. This makes the connection tier stateful, which is the first architectural consequence: a load balancer must route all collaborators on one document to the same server, typically by consistent hashing on document ID.

Conflict resolution - the heart of the problem. Two approaches:

  • OT (Operational Transformation) - operations are transformed against concurrent ones. Needs a central server to order operations. Used by Google Docs.
  • CRDTs - data structures that merge deterministically regardless of order, so they work peer-to-peer and offline. Simpler to reason about but carry metadata overhead.

Persistence - do not write the full document on every keystroke. Append operations to a log, and periodically write a compacted snapshot. The document state is snapshot plus subsequent operations, which also gives version history and undo for free.

Supporting pieces: a presence service for cursors (ephemeral, in Redis with a TTL, never persisted), a Pub/Sub layer so servers holding the same document can broadcast to each other, and an access-control service.

State the trade-off: stateful connection servers make deployment harder - you need connection draining and client reconnect-with-resume logic, because a deploy disconnects every active editor.

No previous question
No next question