wtf( )unctionsystem design, drawn
← all problemsWebSocketsHard

Two cursors, one paragraph

A collaborative editor. Many people work on one document at once and expect to see each other within a frame or two.

The team has already tried the shape everyone draws first — a fleet of identical stateless servers with a shared cache and a shared database behind them — and it produced documents that were structurally impossible. Six sentences say why, without naming a single product.

  1. R1Everyone editing a document sees everyone else's changes within a frame or two, which means the server has to be able to send without being asked, to every client on that document at once.
  2. R2The system must never produce a structurally impossible document — an object that ends up as its own ancestor, say. Deciding that requires knowing the whole current shape of the document, not just the change being applied.
  3. R3Once a change is acknowledged it must not be lost, including through a restart of whatever accepted it.
  4. R4Exactly one thing in the world may hold and change the current state of a given document — two of them holding it is two answers to the same question. That is also what makes "one of two simultaneous values wins outright" mean anything: without a single point putting changes in an order, there is no fact about which one won.
Compose the editing path. Tier 1 is how a client stays connected and what decides, tier 2 is what survives.
Components — tap one, then tap a slot on the diagram
?Refusing to buy a merge algorithm is a product decision, not a technical one — and it is what makes everything below affordable.

Boundaries, outermost first: EDITING PATH: an empty slot for the server can send without being asked, tier 1, an empty slot for the one per document, decides the order, tier 1, an empty slot for the what an acknowledgement is worth, tier 2 Outside every boundary: Editors (hold the doc locally), Comments, permissions (ordinary product data) Connections: Editors holds an open connection to server can send without being asked server can send without being asked holds an open connection to one per document, decides the order one per document, decides the order calls what an acknowledgement is worth Editors calls Comments, permissions — separate path

Editorshold the doc locally
Comments, permissionsordinary product data