Skip to main content
InterviewHubPRO
Section Overview
Q13

Question 13 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

26%
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.1
    • Upgrade: websocket
    • Connection: Upgrade
    • Sec-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.