Backend & APIs
WebSockets
A protocol for persistent, two-way connections between client and server, used for real-time features such as chat, live updates and collaboration.
What WebSockets is
WebSocket is a standard protocol that upgrades an HTTP connection into a long-lived, full-duplex channel. Once connected, both client and server can send messages at any time without the overhead of new HTTP requests.
What it solves
- Delivering updates to users instantly without polling
- Two-way interactive communication such as chat or multiplayer interactions
- Reducing request overhead for frequent small messages
- Keeping several users’ views in sync during collaboration
When it makes sense
- Chat, support widgets and in-app messaging
- Live dashboards, monitoring screens and status tracking
- Collaborative editing and presence indicators
- Real-time games and trading or bidding interfaces
Strengths
- Low-latency, bidirectional communication
- Supported natively by all modern browsers
- Efficient for high-frequency small messages
- Mature libraries for Node.js, Python, .NET and other platforms
Limitations
- Stateful connections complicate horizontal scaling and load balancing
- Requires a pub/sub layer (for example Redis) to broadcast across multiple server instances
- Reconnection, message ordering and missed-message handling must be designed explicitly
- Some proxies and corporate networks handle long-lived connections poorly
Alternatives, and when they are better
- REST APIs
REST is better when interactions are request-response, updates are infrequent, or the API must be consumed by third parties. It is simpler to cache, scale and secure, and occasional polling is often sufficient.
- Server-Sent Events
Server-Sent Events are simpler when updates flow only from server to client, such as notifications or progress updates, and work over plain HTTP.
- Queues & event-driven systems
For communication between backend services, a message queue is more reliable than WebSockets because it persists messages and handles retries.
Practical examples
- A customer support chat that shows agent replies and typing indicators instantly
- A logistics dashboard showing live vehicle and shipment status
- A collaborative planning tool where several users edit the same board
How it fits into the product architecture
WebSockets usually run alongside a REST API: REST handles commands and initial data loading, while WebSockets push changes. With multiple server instances, a pub/sub layer such as Redis distributes messages to all connected clients, and load balancers must support connection upgrades and long timeouts. Authentication happens at connection time and should be revalidated, and connection counts and message rates need their own monitoring.
Next step
Choosing a stack for a new product?
We start from requirements, costs of ownership and the team you will have, then recommend technology with the reasons written down.