Uploaded October 2026 | Updated November 2026, 51 minutes ago
One server restarts, and thousands of clients reconnect in the very same second. How do real-time apps survive that?
In a chat, a message shows up the moment it arrives, without a refresh. But plain HTTP is request and response: the server can never start the conversation. Polling (asking "any new message?" every two seconds) works, but with hundreds of thousands of users it becomes a mountain of wasted requests.
A WebSocket changes this, in four steps:
1. Handshake: the connection starts as a normal HTTP request with Upgrade: websocket. The server answers 101 Switching Protocols, and the same connection stays open.
2. Both ways: client and server can send any time, as small frames instead of full HTTP headers. If you only need server to client (a live score), Server-Sent Events are enough.
3. Heartbeat: mobile networks drop connections silently, so both sides send ping and pong. No answer means dead, so clean it up.
4. Scaling: each connection lives on one server. Keep a shared map of which user is on which server (for example in Redis) and a pub/sub channel between servers.
The catch: a deploy restarts a server, all its connections drop, and thousands of clients reconnect in the same second. That is a reconnect storm. The fix: exponential backoff with random jitter, and on reconnect the client sends the last message ID it got, so missed messages are sent again.
Next, in the System Design Interview series: design WhatsApp, where the other user is offline and the message must be kept safe until they come back. Comment and tell me: does your app use polling or WebSockets? Follow for the full series.
kgptalkie.com
#shorts #SystemDesign #WebSockets #RealTime #Backend #BackendEngineering #DistributedSystems #SoftwareEngineering #SystemDesignConcepts #SystemDesignInterview #Redis #KGPTalkie
One server restarts, and thousands of clients reconnect in the very same second. How do real-time apps survive that?
In a chat, a message shows up the moment it arrives, without a refresh. But plain HTTP is request and response: the server can never start the conversation. Polling (asking "any new message?" every two seconds) works, but with hundreds of thousands of users it becomes a mountain of wasted requests.
A WebSocket changes this, in four steps:
1. Handshake: the connection starts as a normal HTTP request with Upgrade: websocket. The server answers 101 Switching Protocols, and the same connection stays open.
2. Both ways: client and server can send any time, as small frames instead of full HTTP headers. If you only need server to client (a live score), Server-Sent Events are enough.
3. Heartbeat: mobile networks drop connections silently, so both sides send ping and pong. No answer means dead, so clean it up.
4. Scaling: each connection lives on one server. Keep a shared map of which user is on which server (for example in Redis) and a pub/sub channel between servers.
The catch: a deploy restarts a server, all its connections drop, and thousands of clients reconnect in the same second. That is a reconnect storm. The fix: exponential backoff with random jitter, and on reconnect the client sends the last message ID it got, so missed messages are sent again.
Next, in the System Design Interview series: design WhatsApp, where the other user is offline and the message must be kept safe until they come back. Comment and tell me: does your app use polling or WebSockets? Follow for the full series.
kgptalkie.com
#shorts #SystemDesign #WebSockets #RealTime #Backend #BackendEngineering #DistributedSystems #SoftwareEngineering #SystemDesignConcepts #SystemDesignInterview #Redis #KGPTalkie










