What it is
A presence system answers a simple question at scale: who is online right now. It powers the green dots, typing indicators, and last seen times that make realtime apps feel alive.
The core mechanism
- When a user connects, the gateway writes a presence record with a short time to live.
- The connection sends a heartbeat that refreshes the time to live.
- If heartbeats stop, the record expires and the user is shown offline.
Why expiry beats explicit logout
A user who loses network never sends a clean logout. Relying on an explicit signal leaves ghosts marked online forever. A time to live that the heartbeat refreshes makes presence self healing: stale records vanish on their own.
Fanning presence out
- Changes are pushed to interested users such as friends in a contact list.
- Batching and debouncing rapid flaps avoids a storm of online and offline updates.
Key idea
A presence system tracks who is online by refreshing a short lived record with heartbeats, letting stale state expire automatically instead of trusting an explicit logout.