How would you design presence, and what would you not guarantee?
Sketch your own answer first, then compare it with the one below.
A strong answer
Use a heartbeat with an expiry. A connected client pings every so often, and the server records online with a lifetime a little longer than the interval. When pings stop, the entry expires and the user shows as offline.
The expiry is a failure detector, so it trades speed against false offline marks. Do not broadcast every change to every contact. Send presence only for open conversations, and only on change, and accept delays of seconds.
Presence can be late and approximate. Messages and their order cannot.
Sources
- Tushar Deepak Chandra, Sam Toueg (1996). Unreliable failure detectors for reliable distributed systems.