Real-Time Revolution: Building Interactive Apps with WebSockets (2026)
By Huzi
File #87 · 3 min read
The old web was one-way: you asked, the server answered, the connection closed. WebSockets flipped that — a single persistent, full-duplex connection where either side can push at any moment. Group chats, collaborative editors, live scores, multiplayer games and token-by-token AI streaming all live on this bridge.
The quick answer: Long polling when you must, Server-Sent Events when only the server talks, WebSockets when both sides do — and never hand-roll rooms or reconnection, because Socket.IO 4, Supabase Realtime and PartyKit already did. Authenticate during the handshake and rate-limit per connection, and the bridge stays standing.
The handshake
A WebSocket starts life as an ordinary HTTP request carrying an Upgrade: websocket header. If the server agrees, it replies 101 Switching Protocols, and the HTTP conversation becomes a bare frame stream on the same TCP connection.
Frames carry 2-to-14-byte headers, which is why high-frequency messaging here beats polling on bandwidth and battery alike. The HTTP-based handshake is also why WebSockets pass cleanly through Cloudflare, Nginx and most load balancers.
Choosing your transport
| Transport | How it works | Best for |
|---|---|---|
| Long polling | Server holds the request open until it has something to say | Works everywhere, heavy everywhere |
| Server-Sent Events | Clean one-way server-to-client streams | AI chat tokens; the simpler tool if the client never pushes back |
| WebSockets | One persistent, full-duplex connection | Chat, games, editors, dashboards — when both sides talk |
The big AI providers still stream chat tokens over SSE today.
Don't hand-roll the hard parts. Socket.IO 4 adds rooms, namespaces, reconnection and polling fallback out of the box. Supabase Realtime pushes Postgres row changes to the browser via logical replication, and PartyKit, now under Cloudflare, runs multiplayer state as edge functions.
A collaborative editor in seven lines
CRDT libraries like Yjs merge concurrent edits without a referee:
import { WebSocketServer } from "ws";
import { setupWSConnection } from "y-websocket/bin/utils";
const wss = new WebSocketServer({ port: 1234 });
wss.on("connection", (conn, req) => {
setupWSConnection(conn, req);
});
That is a working multiplayer document server. Conflict resolution lives inside the CRDT, not in your code.
A family planning one Umrah trip from three different cities has the same concurrency problem, and no library for it. At HTG Travel we are the referee, and our merge strategy is patience — every edit reconciled, nobody's version lost.
Scaling past one server
WebSockets are stateful; your servers are not. The standard fix is Redis Pub/Sub or Streams linking instances, so a message arriving at Server 1 reaches the user connected to Server 2.
Without that, sticky sessions on the load balancer keep each client glued to one backend. Mind backpressure too: a slow client can saturate your send buffer, so honor the drain event instead of writing blind.
Locking the bridge
Check the Origin header to block cross-site hijacking, and rate-limit per connection, because a rogue client spamming tiny messages is a cheap denial of service.
Pro tip: Authenticate during the handshake — a short-lived JWT in the query string, validated before the upgrade completes, never after. A socket you never authenticated is a door you left open.
In Gaza a single bar of signal is a family's lifeline — a voice note, a name, a message that says we are still here. Sudan's families crowd around one working phone to tell distant relatives they are alive — may their calls soon be about ordinary things.
Real-time is our trade in the human sense: shaadi season at our desk runs on itineraries that change hourly — guest lists, flight times, who is finally flying in from Dubai. HTG Travel holds the line open on the group bookings where the only constant is change. No forms, no bots — just +92 317 5054959.




