Skip to content

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
123CLIENTEditor clientEDGEDocument routerSERVICEDocument ownerDATABASEPostgres op log

Select a component to see what it is responsible for and which state it owns.

  1. 1Editor client → Document router: WebSocket: ops, acks, remote ops, presence
  2. 2Document router → Document owner: Route by document id to the current owner
  3. 3Document owner → Postgres op log: Append ops at next seq (batched, epoch-fenced)
  • Server push
  • Request / response

What you need to know

0 of 1 checks done
  1. 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.

  2. Check

    A laptop lid closes without a goodbye message. What removes that user's avatar?