What: A protocol (a specification that people agreed to follow) providing full-duplex communication channels over a single TCP connection, enabling real-time bidirectional communication between client and server. Unlike HTTP's request-response model, WebSocket maintains a persistent connection after the initial handshake, allowing both parties to send messages independently.
Use cases:
Real-time collaborative applications (Google Docs, Figma)
Live sports scores and financial market data
Online gaming and multiplayer experiences
Chat applications and messaging platforms
Live streaming comments/reactions
Reliability:
Built-in heartbeat mechanism (ping/pong frames)
Automatic reconnection handling
Error handling with close codes
Scalability:
Websocket is a stateful protocol that needs to maintain a persistent TCP connection between a client and a server. If the server goes down or a communication link is broken, the client needs to re-establish the connection with another server.
A typical Websocket server produces events and listens to a messaging queue to ensure the application logic is decoupled from sending/receiving WebSocket messages. This also helps to scale different components separately.
Maintainability:
Battle-tested protocol
Clear connection lifecycle
Debugging tools support (Browser DevTools)
Easy integration with existing web infrastructure
Performance:
Reduced latency compared to HTTP polling
Minimal header overhead after handshake
Support for binary messages
Reddit showcased in this article that a single Websocket server is capable of handling ~4k connections and processing 150Mbps of data.
Users:
Resources:
Tags: #protocol #real-time
Disclaimer: Found a mistake or have a different perspective? Please drop a comment! I aim to keep this content accurate and valuable for everyone.