Skip to content
HLD Learn/Real-Time Systems
Browsing as a guest. Sign in to save your progress and earn XP as you complete chapters.

Building Chat & Presence Systems

5 min read

You'll learn to

  • -Explain how presence (online/offline) is tracked at scale

Chat is the canonical WebSockets use case: genuinely bidirectional, genuinely latency-sensitive. But a subtlety shows up the moment you have more than one WebSocket server: Client A might be connected to Server 1 while Client B is connected to Server 2, so Server 1 needs a way to tell Server 2 "forward this message to your client."

Client A
Client B
WS Server 1
Pub Sub
WS Server 2

A message from Client A must be broadcast through a pub/sub layer to reach Client B, who is connected to a different WebSocket server instance.

WS Server 1Pub Sub- publish messagePub SubWS Server 2- deliver to Client B

Presence: Tracking Online/Offline at Scale

Presence (who's online right now) is usually tracked with a short-TTL key per user in a fast store like Redis, refreshed by a heartbeat from the client's open connection. If the heartbeat stops (connection dropped, tab closed), the TTL simply expires and the user is treated as offline: no explicit "goodbye" message required.

Interview Signal is part of Pro

See a real weak answer next to a real strong one for this exact topic.

Quiz is part of Pro

Test what you just read with a short quiz, and bank the XP.