Design a Collaborative Editor (Google Docs), stage 10 of 12: change it
The all-hands document
The single-owner design made ordering free. Now one document's traffic exceeds what one process can deliver. Sequencing is still cheap (200 ops/s); delivery is not (about 46,000 messages/s).
System so far· 4 parts
Select a component to see what it is responsible for and which state it owns.
- 1Editor client → Document router: WebSocket: ops, acks, remote ops, presence
- 2Document router → Document owner: Route by document id to the current owner
- 3Document owner → Postgres op log: Append ops at next seq (batched, epoch-fenced)
- Server push
- Request / response
What you need to know
0 of 2 checks done
Find the part of the work that must be serialized and keep only that part serialized. Here:
- Sequencing (assigning order) must be single-writer, and it's cheap: about 200 ops a second.
- Delivery (sending to 230 sockets) is expensive, and parallel by nature.
Work it out
Instead of sending each op separately, each recipient gets one frame every 50 ms containing all new ops. With 230 recipients, how many frames a second?Check
A viewer on a bad connection reads slower than ops arrive. What should the server do with their send buffer?