System Design intermediate LIVE DEMO
πŸ“

Collaborative Editor System Design

Learn how a real-time collaborative editor keeps multiple people on the same document without making typing feel slow.

system-designoperational-transformationcrdtwebsocketsconcurrency
Interactive Demo

Continue with the guided workspace

Use the paired workspace to connect this guide's mental model with live component state, visible signals, and the outcome each step or scenario is meant to prove.

Mental Model

If you are new to collaborative editors, focus on one question first: how can two people type at nearly the same time and still end up with the same document?

Think of the editor as three jobs happening at once:

  1. The browser keeps the typing experience fast for the local user via optimistic updates.
  2. The collaboration server decides the shared order of edits.
  3. Storage systems keep enough history and state so the document can be restored, replayed, and synchronized later.

Components and Why They Exist

Client (Browser)

The browser client gives each collaborator an instant, responsive editing workspace through local optimistic updates. It applies keystrokes to the local document view immediately, syncs cursor coordinates, and queues operations locally whenever the network connection drops.

Load Balancer

The load balancer distributes incoming WebSocket connections and routes concurrent collaborators editing the same document to the appropriate backend session tier. It inspects connection upgrades, maps document IDs to server targets, and maintains persistent WebSocket routes across the canvas.

Collaboration Server

The collaboration server orders concurrent edits, resolves index conflicts via Operational Transformation or CRDT rules, and broadcasts merged operations to connected peers. As edit particles arrive from multiple browsers, the server card transforms conflicting offsets and fans the canonical update out to every active client.

Operation Log (Oplog) & Document Store

The Operation Log and Document Store persist fine-grained edit history alongside periodic full-document snapshots so returning clients can load quickly without replaying every keystroke since creation. Sequential edit entries append to the Oplog card while periodic compacted checkpoints write into the Document Store.

Redis Presence Store

The Redis presence store handles ephemeral, high-frequency state such as live cursor positions, text selections, and active user heartbeats without burdening durable storage. Cursor movement and online presence badges update directly inside the Redis node in real time.

Edge Cases and Misconceptions

Operational Transformation (OT) Complexity

OT is notoriously difficult to implement for rich text because formatting modifications (bolding, headers) combined with insertions and deletions create complex intersection states. If any edge cases are missed, different client views will drift and never converge.

CRDT Storage Overhead

While CRDTs don’t require a central server for transformation, they attach unique metadata (client IDs, vector clocks) to every character, which dramatically increases memory usage compared to plain text. Garbage collection strategies are required to clean up deleted character metadata.

Common Questions

What is the difference between Operational Transformation (OT) and Conflict-free Replicated Data Types (CRDTs)?

OT relies on a central server to coordinate and transform incoming operation indices based on concurrent operations. CRDTs use mathematically designed structures where each item has a globally unique ID, allowing replicas to merge edits deterministically without a central coordinating server.

Why use WebSockets here?

Because the editor needs a live two-way connection. The browser can send each edit immediately, and the server can push updates back without waiting for the client to ask again.

Why do snapshots matter if we already have an operation log?

Because replaying every old edit gets slower as the document grows. A snapshot gives new or returning clients a recent full copy, so they only need to replay the newer operations after that checkpoint.

What does Redis do in this design?

It stores fast-changing presence data such as cursors, selections, and active sessions. That information changes constantly and usually does not need the same long-term storage as the document itself.

How does offline editing work in a collaborative editor?

While offline, the client buffers all user edits locally in an operations queue. When the connection is restored, the client sends this backlog to the server, which merges them into the shared state and broadcasts updates to catch the client up.