Persistent connections.
WHAT THE PROBLEM IS
Ordinary requests are initiated by the client. The server cannot send something unprompted.
WHAT THE OLD WORKAROUND WAS
Repeatedly asking whether anything changed, which wastes requests and adds delay.
WHAT WEBSOCKETS PROVIDE
A persistent two-way connection, over which either side may send at any time.
WHAT THAT SUITS
Chat and messaging
Live updates: prices, scores, status
Collaborative editing Notifications Anything where delay matters
WHAT ALTERNATIVES EXIST
Server-sent events, where only the server needs to send Long polling, as a fallback
WHEN TO USE THE SIMPLER OPTION
When communication is one-way, which is frequently the case.
WHAT TO HANDLE
Connection failure Reconnection, with increasing delay Messages arriving out of order Duplicate messages after reconnection The connection being idle and closed
WHAT TO NEVER ASSUME
That the connection persists.
WHAT TO CONSIDER
Server resources, since each connection is held open.
WHAT TO SECURE
The connection, and authentication on it.