Networking & Protocols (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
How do WebSockets work and what is the HTTP Upgrade Handshake?
senior LevelSystem DesignHTTP & REST APIs
In Simple Words: WebSockets provide persistent, bidirectional, full-duplex communication over a single TCP socket:
- Handshake: Begins as a standard HTTP request:
GET /chat HTTP/1.1Upgrade: websocketConnection: UpgradeSec-WebSocket-Key: dGhlIHNhbXBsZSBvbmNl...
- Server responds with
HTTP/1.1 101 Switching Protocols. - The TCP connection remains permanently open; both client and server can push messages at any time with minimal 2-byte framing overhead.