Draftly
A Google Docs-style editor where several people can write in the same document at once, which I built with my friend Richard Baah.
Everyone editing a document joins the same room on a live editing server over WebSockets. Each edit travels as a small insert or delete, and the server uses operational transformation to shift it past anything that changed in the meantime, so every copy ends up the same.
A separate Go REST API handles users, documents and sharing, backed by PostgreSQL, with document files in Amazon S3. Each service ships as a Docker image and runs on AWS.
Highlights
- Real-time editing for many people at once, kept consistent with operational transformation.
- Every edit is appended to a log, so anyone who joins late or reconnects catches up.
- Separate services for live editing and for accounts and documents.
Writers
Editing one document together
Live editing server
Go, rooms, operational transformation
Documents API
Go, REST
Operation log
Every edit, in order
PostgreSQL
Users, documents, sharing
Amazon S3
Document files
- Writers and Live editing server: edits
- Writers to Documents API: accounts
- Live editing server and Operation log: append
- Documents API to PostgreSQL
- Documents API to Amazon S3
See it work
Two writers typing at onceExample
Both writersStart on version 0
“cat”Writer ATypes “the ” at position 0. The server makes it version 1.
“the cat”Writer B, still on version 0Types “s” at position 3. Writer A's 4 characters landed before it, so the server shifts it to 3 + 4 = 7 and sends version 2 to everyone.
“the cats”Without the shiftWriter B's “s” would land at 3, inside the wrong word.
“thes cat”