Glossary · Web Development

WebSocket

WEB-sok-itnoun

A WebSocket is a persistent, two-way connection that lets a browser and server exchange data in real time.

Part of speech
noun
Pronunciation
WEB-sok-it
Origin
From 'web' and 'socket,' a networking endpoint. A protocol standardized in 2011 for two-way, always-on communication.

What is WebSocket?

A WebSocket is a persistent, two-way connection that lets a browser and a server exchange data in real time. In the traditional web model, a browser sends a request and the server sends back one response, then the connection closes. That pattern works well for loading pages but poorly for anything live, because the server has no way to speak unless the browser asks first. A WebSocket removes that limitation by keeping a single connection open so that either side can send messages to the other at any moment, with very little overhead per message.

Mechanically, a WebSocket connection begins as an ordinary web request. The browser sends an HTTP request that includes a special upgrade header asking to switch protocols. If the server agrees, the connection is upgraded from request-and-response HTTP into a full-duplex WebSocket channel that stays open. From that point forward, both parties can push small framed messages across the wire whenever they have something to say, without repeating the handshake or resending headers. The connection persists until one side closes it or the network drops, and well-built applications watch for disconnections and reconnect automatically.

The name combines web with socket, a long-standing networking term for an endpoint of a two-way communication link. The protocol was standardized in 2011, giving browsers and servers a common, interoperable way to maintain always-on connections. Before it existed, developers faked real-time behavior with workarounds such as repeatedly polling the server or holding requests open for long periods, techniques that were inefficient and awkward. WebSockets replaced those hacks with a purpose-built standard.

For a business, WebSockets power the interactive, live features that users increasingly expect. Chat and customer-support widgets, collaborative editing tools, live sports scores and stock tickers, multiplayer games, auction bidding, and instant notifications all rely on the server being able to push updates the moment they happen. On a commercial site, a live chat that responds instantly or inventory that updates in real time can lift engagement and conversions. Because a WebSocket avoids the overhead of opening a fresh connection for every update, it also scales more gracefully for high-frequency data than repeated polling would.

The common mistakes cluster around assuming the connection is always available and always cheap. Networks drop, mobile users move between towers, and proxies or corporate firewalls sometimes block long-lived connections, so applications need a reliable reconnection and fallback strategy rather than assuming the socket stays up forever. Every open connection also consumes server memory, so at large scale operators must plan capacity and often place a reverse proxy or specialized gateway in front of the servers. Security deserves care too, since a persistent channel needs the same authentication and message validation as any other endpoint. It also helps to know when a WebSocket is overkill: for occasional updates, a simpler request made through the Fetch API or an older background-request technique is lighter and easier to maintain. Reserved for genuinely real-time, bidirectional needs, WebSockets are the standard foundation for the live web, working alongside conventional API endpoints and asynchronous browser code rather than replacing them.

Why it matters

WebSockets power the live chat, notifications, and real-time updates that keep users engaged on a modern website or app.