WebSocket
Full-duplex persistent connection, both sides send messages freely after a single handshake.
Two people edit the same document. Each keystroke, each cursor move, has to reach the other within about 50 milliseconds or the experience falls apart.
That is twenty messages a second in each direction, both ways at once. Wrapped in ordinary HTTP requests, every one of those messages carries a few hundred bytes of headers to deliver a few bytes of payload, and pays for a round trip to say it.
WebSocket drops the request and response rhythm for a raw two-way pipe. One handshake, then either side sends whenever it likes, for hours, with a header of a couple of bytes.
It is the heavyweight of this course and the one teams reach for first and regret most, because everything HTTP was quietly doing for you is now yours to build.
Lessons
4 in this chapter- The Upgrade HandshakeOne HTTP request, a 101 response, and then HTTP is over for the life of the connection.3 min
- Full Duplex MessagingFrames are cheap and unstructured, so the message protocol becomes your job.2 min
- Scaling WebSocket FleetsThe connection is the state, so scaling is routing, memory, and surviving your own deploys.2 min
- When Not to Use ItMost features that ask for WebSocket are polling or SSE workloads wearing a costume.2 min