Design a Collaborative Editor (Google Docs), stage 1 of 12: model
Size the problem
Real-time systems fail in ways that depend on numbers: message rates, fan-out factors, connection counts. Work some out before you choose anything. Useful figures: 20,000 connections at peak, about a tenth of users typing at any moment, 5-10 operations per second per typist, and one document with 30 editors and 200 viewers.
System so far· 2 parts
Select a component to see what it is responsible for and which state it owns.
What you need to know
"Last write wins" on the whole document means: whoever saves second replaces whatever the first person wrote. With two people typing in the same second, someone's sentence disappears.
Collaborative editing has to merge operations (insert "x" at this point, delete these characters), not replace whole documents.
Work it out
20,000 people connected, a tenth of them typing at about 7 operations a second. About how many operations a second arrive?Work it out
The all-hands doc: 30 editors at about 7 ops a second each, every op delivered to about 230 participants. About how many outbound messages a second?Check
Do 20,000 idle WebSocket connections need a large server fleet?