How it works
A WebSocket starts as an ordinary HTTP request that asks to 'upgrade', then becomes a two-way channel over the same connection (ws://, or wss:// when encrypted). Either side can push small messages with very little overhead, so the client no longer has to keep asking whether anything has changed. The protocol was standardised in 2011 and every modern browser supports it.
Libraries such as ws and Socket.IO (which adds rooms and automatic reconnection) run it on Node.js, and services such as Supabase Realtime, Pusher and Ably host it for you. Open connections are the hard part: a server must keep thousands of them alive, reconnect dropped clients and share messages across machines, and many serverless platforms cannot hold connections open at all.
WebSockets pros and cons
Pros
- True two-way messaging with very little delay
- Supported natively by every modern browser
- Efficient for frequent small messages
Cons
- Long-lived connections need servers that stay running
- Reconnection, scaling across servers and auth need extra work
- Some proxies and corporate networks interfere with them
When to use WebSockets
Pick it when
- Chat, multiplayer games and collaborative editing
- Both sides send messages often
Skip it when
- Updates only flow from server to browser, where SSE is simpler
- Updates are rare, so checking now and then is enough
WebSockets pricing
Free
Free: it is a web standard. Hosted realtime services charge by connections and messages.
Approximate, checked September 2026.What the other tools cost
WebSockets vs the alternatives
Related terms
More in Backend and APIs
Realtime