Skip to content
BytePatterns

Design a Collaborative Editor

System Design Cases: lesson 20 of 20

Both typing in one paragraph, both landing on the same text.

Lesson 20 of 20 · 7 min

Design a Collaborative Editor

Step 1 of 11

Both people are inside the same paragraph, and both expect their own keystroke immediately.

The Idea

Two people typing in the same paragraph, each seeing their own keystroke instantly, both ending on identical text. The edit is applied locally first, then reconciled with whatever arrived from the other side.

Real-World Example

Two editors marking up one page by describing where each mark goes. "After the word cost" survives somebody inserting a sentence above it; "at character 41" does not.

The Tradeoff

Describing an edit by position means every concurrent edit must be transformed against it, which puts the ordering burden on a server that has to see everything. Identity-based edits merge in any order and carry metadata for every character ever typed. Presence rides a separate channel, because a moving cursor is not worth storing.

Your turn

Put the steps in the right order.

  1. Broadcast the settled edit to everyone else in the document
  2. Apply the keystroke locally and show it immediately
  3. Transform it against edits that arrived in the meantime
  4. Send the edit with the version it was written against

Mini quiz

1 / 3

A keystroke is applied locally before the server answers so that:

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.