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
Feature Flag
Development PracticesA software development technique allowing features to be enabled or disabled at runtime without deploying new code.
Webhook
Paradigms & PatternsAn HTTP callback that delivers real-time notifications from one application to another when a specified event occurs.
Test-Driven Development
Development PracticesA development practice where failing tests are written before the code that makes them pass.
Behaviour-Driven Development
Development PracticesA development approach where application behaviour is described in a natural language format before implementation.
Integration Testing
Quality & TestingTesting the interaction between different software modules or components to verify they work together correctly.
Concurrency
ArchitectureThe ability of a system to handle multiple tasks simultaneously by interleaving their execution.
Code Review
Development PracticesA systematic examination of source code by developers other than the author to identify bugs and improve quality.
Object-Relational Mapping
Paradigms & PatternsA technique that maps objects in code to relational database tables, abstracting direct SQL interaction.