WebSocket
Also known as: WebSockets, WebSocket protocol, web socket
WebSocket is a communication standard that keeps a persistent, two-way connection open between a web browser or app and a server, so either side can send messages instantly at any time.
It powers real-time features such as live chat, multiplayer games, collaborative editing, stock tickers, and notifications. While regular web requests work like sending letters, WebSockets work like an open phone line, which is efficient for constant updates but requires servers to manage many open connections.
WebSocket, explained at three levels
At home
A WebSocket is like keeping a phone call open instead of sending text messages back and forth. Both sides can speak instantly whenever they want.
At work
WebSockets enable real-time features such as live dashboards and customer chat on business websites.
At home
When you see someone typing in a web chat or a live sports score update without refreshing, WebSockets or similar technology are often behind it.
At work
WebSocket connections start as normal HTTP requests and then 'upgrade.' They need load balancers and firewalls configured to support long-lived connections.
At home
Some workplace or public Wi-Fi networks block WebSockets, breaking live features. In my opinion, that's worth knowing when a chat app keeps disconnecting.
At work
Authenticate connections, check message origins, validate every message, set rate limits, plan for reconnections, and scale with tools designed for many concurrent connections.
Real-world examples
At home
Sophie plays an online word game with friends. Their moves appear instantly on her screen thanks to a WebSocket connection.
At work
Marcus builds a live delivery-tracking dashboard for a Hamilton courier company. WebSockets push each driver's location to dispatchers in real time.
How it compares
| feature | WebSocket | Regular HTTP request |
|---|---|---|
| Connection | Stays open | Opens and closes |
| Direction | Two-way | Client asks, server answers |
| Best for | Live, frequent updates | Occasional requests |
| Server load | Many open connections | Short-lived requests |
WebSockets keep a live line open. HTTP requests are one-off letters.
For analysts
When stakeholders ask for 'real-time,' I'd clarify how fast is fast enough. Many needs are met by updates every few seconds without WebSocket complexity.
History & origin
Early web apps faked real-time updates by repeatedly asking servers for new data, a technique called polling, or holding requests open with 'long polling.' WebSocket was developed as part of HTML5 work and standardized by the IETF as RFC 6455 in 2011, with browser support arriving around the same time. It enabled chat apps, trading platforms, and online games to run smoothly in browsers. Later alternatives include server-sent events for one-way updates and WebTransport, built on HTTP/3. AI chat apps often stream responses using similar real-time techniques. In my view, WebSockets helped make the browser a true platform for live applications.