Design a Collaborative Editor (Google Docs), stage 6 of 12: decide
Presence and cursors
Avatars show who is in the document; coloured cursors show where they are. Cursors move with every keystroke and every click. When someone closes their laptop, their avatar should disappear within seconds.
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
Presence (who's here) and cursors (where they are) describe now. They're useless a minute later, and they rebuild themselves within seconds when clients reconnect and re-announce. That makes them soft state: keep them in memory, refresh them with heartbeats, expire them on a short TTL. See Soft state.
Check
A laptop lid closes without a goodbye message. What removes that user's avatar?Cursors move with every keystroke, but only the latest position matters. So cursor updates can be coalesced (send only the newest every 50–100 ms), throttled, and sent at most once: a lost cursor update is replaced by the next one.