WhatsApp System Design
Online Status
2 min read
How does WhatsApp know someone is online?
The answer is surprisingly simple.
Clients periodically tell the server
"I'm still connected."
These are called heartbeats.
Presence Architecture
The Presence Service keeps track of
-
Online
-
Offline
-
Last Seen
-
Typing
Unlike chat messages,
presence data changes constantly.
Because of this,
it is usually stored in fast in-memory systems instead of permanent databases.
Heartbeats
Every few seconds,
the client sends a heartbeat.
I'm Alive
If heartbeats stop,
the Presence Service waits for a timeout.
If no heartbeat arrives,
the user is marked Offline.
Why Use Redis?
Presence information changes extremely frequently.
Writing every heartbeat to a relational database would be expensive.
Redis provides
-
Fast updates
-
Low latency
-
Automatic expiration
making it ideal for ephemeral state.
Interview Notes
Interviewer
Why isn't Online Status stored permanently?
Answer
Because it changes constantly and becomes outdated within seconds.
Fast in-memory storage is a much better fit.
Key Takeaways
✔ Online status is maintained through heartbeats.
✔ Presence is temporary state.
✔ Redis is commonly used for fast presence tracking.
✔ Heartbeats automatically expire if the client disconnects.