Editor Colaborativo

Multijugador estilo Google Docs / Figma

Escrito por Darjus Kazakevic · revisado el

One server per document orders every edit; clients apply theirs at once.

Up to 50 people edit one document at once. Each sees the others' changes and cursors within 200 ms, edits made offline merge when the device reconnects, and the full history stays available.

Two people will type into the same sentence at the same moment, and both edits must survive in an order everyone agrees on. Waiting for the server before showing a keystroke is not an option: typing must feel local.

En esencia — Route each document to one server that orders every edit, apply your own edits at once, and transform or merge what arrives so every copy converges.

Cuándo recurrir a él

Recurre a él cuando

  • Several people change one document and must see each other live
  • Edits must merge, not overwrite, when two people touch one place
  • Offline edits must sync later without losing anyone's work

Reconsidéralo cuando

  • One person edits at a time: a lock or "last save wins" is enough
  • Records are small forms, not shared text: use versioned writes
  • Edits need approval before others see them: use drafts and review

The components

Document session server (uses consistent hashing)
Every editor of one document connects to the same server, chosen by hashing the document ID. It holds the document in memory and gives each edit the next revision number.
Operation log
Every edit is stored as an operation with its revision: insert, delete or format. A snapshot every 1,000 operations keeps loading fast, and the log is the history.
Merge engine
Turns concurrent edits into one order. With OT, the server transforms an edit made at an old revision against everything since. A CRDT gives every character an ID, so edits merge in any order.
Presence channel (uses pub/sub)
Cursors, selections and who is here. Sent at most 10 times a second, kept in memory only, and dropped when a client disconnects.
Client pending queue
The client applies an edit at once and keeps it as pending until the server confirms it. Edits that arrive in the meantime are transformed against the pending ones.

Key decisions

One authority per document
A single server puts every edit for one document in order. Agreeing on an order across servers is a consensus problem; one owner per document avoids it.
Apply locally, reconcile later
Show each keystroke at once and send it with the revision it was made on. When the server's order differs, transform the pending edits. Never block typing on the network.
Keep presence out of the log
Cursors change ten times a second and matter for a moment. Send them on a separate, lossy channel and never store them.
Choose OT or a CRDT by topology
With a central server, OT is simpler and its operations are small. For peer-to-peer or long offline editing, a CRDT merges without a server, at the cost of metadata per character.

Errores habituales

  • Saving whole snapshots instead of operations. Two people save at once, and one loses everything typed since their last save.
  • Storing cursor moves in the edit log. The log grows ten times faster than the text, and the history fills with noise.
  • Breaking ties differently on different clients. Two inserts at the same spot land in a different order on two screens, and the copies never converge.
  • Letting two servers own one document after a failover. Both accept edits and the order splits. Fence the old owner before the new one takes over.