Streaming / UX
Sync & Broadcast
Pushing information to your screen the moment it happens. You see changes instantly without ever needing to hit the refresh button.
Ask once. Get told when something changes.
Polling is asking "anything new?" every second. Most answers are no. A WebSocket opens a tunnel that stays open. The server pushes news the moment it happens. Less waste, lower delay.
Watch polling burn requests asking nothing. Watch the socket sit quiet until news arrives.
Send the message to only who should see it
Not every event is for everyone. A public channel sends to all users. A private channel sends to one. A presence channel knows who's currently in the room. You pick the channel; the server handles delivery.
Press Public to shout at everyone. Press DM to whisper to one user.
Send a ping every few seconds to check the line
Connections can die silently. A short ping every few seconds confirms the line is still alive. If a ping or pong is missed, the client drops the connection and tries to reconnect. No more zombie sockets.
Hold the button to fake a lag. Watch the heartbeat fade and a reconnect kick in.
Share events across many WebSocket servers
One server can hold a few thousand connections. To serve millions of users you need many servers. Redis Pub/Sub sits in the middle. Any server can publish an event, and every other server hears it instantly. From the user's view, it's one big real-time system.
Many WebSocket servers, one Redis in the middle. An event published once reaches all of them.