
← Software Engineer Interview Prep Podcast3 oct. · 28 min
How WebSockets Power the Real-Time Web
<p>Why does a chat message arrive instantly, but the web was never built for it? In this deep dive we unpack WebSockets: how engineers turned a request/response web into an open, two-way line, and what that costs at scale.</p><p><br></p><p>You'll learn:</p><p>- Why short polling, long polling and Server-Sent Events fall short (and the math behind 200,000 empty requests per second)</p><p>- How the WebSocket handshake hides inside a normal HTTP request, and the "cryptographic high-five" that proves the server understood</p><p>- Why clients mask every frame but servers never do, and the cache-poisoning attack it prevents</p><p>- Half-open connections, idle timeouts and why heartbeats every 20–30 seconds keep sockets alive</p><p>- Close code 1006, the "ghost code" every system design candidate should know</p><p>- The real cost of state: 1 million connections × 20 KB = 20 GB of RAM before a single message</p><p>- Gateways, pub/sub buses, the thundering herd, and exponential backoff with full jitter</p><p>- Cross-site WebSocket hijacking, and why tokens never belong in the URL</p><p>- When NOT to use WebSockets: SSE vs WebSockets vs gRPC</p><p>- Head-of-line blocking and why QUIC and WebTransport may be next</p><p><br></p><p>Perfect for software engineers preparing for system design interviews.</p><p><br></p><p>Chapters</p><p>00:00 Intro: the web wasn't built for real time</p><p>02:19 Short polling and the 200,000 requests/second problem</p><p>03:54 Long polling</p><p>04:42 Server-Sent Events</p><p>05:31 WebSockets and full-duplex communication</p><p>06:19 The handshake: disguised as HTTP</p><p>07:55 Sec-WebSocket-Accept: the cryptographic high-five</p><p>09:05 Why clients mask frames</p><p>09:53 Cache poisoning explained</p><p>11:50 Half-open connections</p><p>12:38 Idle timeouts at every network hop</p><p>13:47 Heartbeats: Ping and Pong</p><p>14:36 Close code 1006</p><p>15:23 The cost of state</p><p>16:57 Scaling with gateways and pub/sub</p><p>18:34 The thundering herd</p><p>19:46 Exponential backoff with full jitter</p><p>20:58 Cross-site WebSocket hijacking</p><p>22:32 Ticket-based authentication</p><p>23:45 When not to use WebSockets</p><p>24:55 The big trade-off: latency vs statefulness</p><p>25:43 Head-of-line blocking</p><p>26:55 What's next: QUIC and WebTransport</p><p><br></p><p>#SystemDesign #WebSockets #SoftwareEngineering #InterviewPrep #BackendEngineering</p><p><br></p><p>Interview Prep Podcast</p>