Node.js Lease Presence Beats Disconnect Events After Realtime Network Drops
TL;DR: When realtime presence shows ghost users after a network drop, treat presence as a short lease owned by one newsroom editor session, not as a fact that a disconnect event must erase. A Node.js service should expire the lease unless the same authenticated session renews it. Disconnect events can speed up cleanup, but they can't be the source of truth. Keep in-app mention notifications…
The article discusses the issue of ghost users appearing in realtime presence after a network drop when using Node.js. The root cause of this problem is that servers typically detect graceful closures quickly, but network drops are different as the client cannot send a final message when connectivity is lost. This results in the client not being able to transmit a leave event, which can create the illusion of ghost users.
To address this issue, the article suggests treating presence as a short lease owned by one newsroom editor session, rather than assuming that a disconnect event must erase the presence. This approach involves using a session-scoped lease with a random presence token that is restricted to one document, one user, one session, and a short expiry.
By doing so, the design becomes more robust and avoids ambiguity when multiple tabs are opened. Additionally, the article recommends replaying awkward sequences to understand how the system behaves under different conditions and to ensure that the lease is properly managed.
Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.