Choosing the Right Real-Time Transport Protocol
Architecting real-time web applications requires balancing bidirectional latency, mobile battery drain, server connection density, and cloud bandwidth egress bills. The three dominant technologies are WebSockets, Server-Sent Events (SSE), and HTTP Long-Polling.
Protocol Trade-Off Comparison
- WebSockets (RFC 6455): The gold standard for true bidirectional communication (multiplayer gaming, collaborative whiteboards, chat). After an initial HTTP/1.1 Upgrade handshake, binary/text frames carry just 2 to 6 bytes of framing overhead.
- Server-Sent Events (SSE): Lightweight, unidirectional server-to-client push running on top of standard HTTP/2 or HTTP/3 streams. Built-in automatic reconnection, UTF-8 text framing, and zero special proxy or firewall configuration make SSE the default choice for AI token streaming (e.g. ChatGPT, Claude) and live dashboards.
- HTTP Long-Polling: Legacy fallback where clients issue blocking HTTP requests that wait until new data is ready. Incurs severe bandwidth waste (800โ1,200 bytes of redundant HTTP headers per message) and high CPU overhead on load balancers.
Managing the C10K & C100K Connection Problem
At scale (100,000 concurrent connected sockets), memory footprint per connection is critical. Modern asynchronous event-loop runtimes (Go epoll, Rust tokio, Node.js) allocate 30KB to 60KB of RAM per idle connection, allowing a single 8GB cloud VM to comfortably hold 100,000 open WebSocket connections.