Design interviews / Intermediate / 6 min / Updated
Design chat presence: heartbeats and the online dot
Heartbeats decide the green dot. Close a laptop and see how long friends still see online, then make a lossy network flap and cut presence fan-out.
Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.
In short
How do you design online presence for chat?
Clients send a heartbeat every few seconds; the server marks a user offline after several missed beats and tells friends.
Why does it matter?
A closed laptop or dead phone sends no goodbye, and chat apps want the green dot to be right within seconds.
What is the trade-off?
Short beats detect fast but cost requests; one allowed miss causes flaps; fan-out to all friends is the real cost.
How do you explain it in an interview?
"Heartbeat over the WebSocket every 30 s, offline after 2 misses, status kept in Redis with TTL, pushed only to open chats."
Check yourself
Why does a chat app need heartbeats to show presence?
Answer: A crashed or closed client sends no goodbye, so silence is the only signal. The server marks a user offline when several heartbeats in a row are missing.
Allowing only one missed heartbeat on a mobile network causes what?
Answer: False offline flaps when a single packet is lost. With loss p, a false offline needs k losses in a row (p^k). More allowed misses means far fewer flaps, but slower detection.
What is usually the biggest cost of presence at scale?
Answer: Fanning out every status change to all friends. Each change goes to hundreds of friends. Sending it only to people with the chat open, or on demand, cuts it by an order of magnitude.