Software EngineeringParadigms & Patterns

WebSocket

Overview

Direct Answer

WebSocket is a standardised protocol enabling bidirectional communication over a single persistent TCP connection, established via an HTTP upgrade handshake. It eliminates the request-response overhead inherent in traditional HTTP polling by maintaining an open channel for real-time data exchange.

How It Works

A client initiates a connection using an HTTP GET request with specific upgrade headers (Connection: Upgrade, Sec-WebSocket-Key). The server responds with a 101 Switching Protocols status, transitioning the TCP connection from HTTP to the WebSocket protocol. Data then flows as framed messages in both directions simultaneously without requiring new connection establishments.

Why It Matters

Organisations deploying real-time applications benefit from reduced latency and server load compared to polling mechanisms, directly improving user experience and operational efficiency. Industries including financial trading, collaborative tools, and live notifications require this efficiency to meet responsiveness expectations and cost constraints.

Common Applications

Live chat systems, collaborative document editing platforms, financial market data feeds, multiplayer gaming environments, and real-time notification services all leverage this protocol. Video conferencing signalling and Internet of Things device communication represent additional deployment domains.

Key Considerations

Stateful connections consume server resources and complicate horizontal scaling; load balancing requires sticky sessions or alternative architectures. Firewall and proxy compatibility issues may arise in restrictive network environments, necessitating fallback mechanisms.

More in Software Engineering