The Overhead of HTTP Polling
Before WebSockets, building real-time web features (like chat applications or financial trackers) required client browsers to poll servers continuously using AJAX requests.
- ◆Short Polling: Firing queries every few seconds, wasting server threads and network bandwidth on empty responses.
- ◆Long Polling: Holding HTTP connections open until the server has data to send.
HTTP headers are verbose, adding significant payload overhead to every request.
The finalization of RFC 6455 (The WebSocket Protocol) in December 2011 resolves this bottleneck.
The WebSocket Handshake and Connection
WebSockets establish full-duplex communication over a single long-lived TCP socket connection:
- 1.The client sends a standard HTTP request containing an Upgrade header:
Upgrade: websocket. - 2.The server responds with status code
101 Switching Protocols. - 3.The connection upgrades to a persistent, low-overhead WebSocket channel, allowing both client and server to stream frames instantly without HTTP header overhead.
javascriptcode
// Client-side WebSockets implementation in late 2011
const socket = new WebSocket("ws://shivamitcs.in/realtime");
socket.onopen = function() {
socket.send("Hello Server!");
};
socket.onmessage = function(event) {
console.log("Message from server:", event.data);
};Architectural Impact
WebSockets enable a new class of low-latency interactive applications, laying the foundation for modern real-time SaaS dashboards.
VP
Vijay Paliwal
Founder, SHIVAM ITCS · 18+ years enterprise & AI engineering
MCA · Ex-HiveGPT USA · Ex-Social27 Seattle