C.W.K.
Stream
Lesson 01 of 08 · published

The HTTP Problem

~14 min · foundations, http

Level 0Poller
0 XP0/60 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Request-response is a one-way street

HTTP is built around a strict request-response contract. The client asks; the server answers; the connection closes; everybody goes home. The server cannot speak first, even when it knows something the client desperately needs. Imagine a restaurant where the waiter is forbidden from approaching your table — your food has been ready for ten minutes, but until you flag him down, you do not know.

That model is fine for documents. It is structurally hostile to events. Every "real-time" feature on the modern web — chat, presence, live prices, collaborative cursors, streaming AI tokens — is the same problem in disguise: the server has news, the client has not asked, and waiting for the next request is unacceptable.

The cost of HTTP overhead

Every HTTP request hauls a payload of headers — cookies, auth tokens, user-agent strings, accept-encoding negotiations, content-type, origin. Hundreds of bytes of metadata to ask a question whose answer might be a single integer. For one request a minute, this is invisible. For ten requests a second across a million users, this is millions of dollars in transit and CPU.

Where this quest goes

Track 1 places WebSocket on a map alongside polling, long polling, and Server-Sent Events. By the end of the track you will pick the right approach without ceremony. WebSocket is one tool. It is sometimes the right one. Often it is not.

Code

What every HTTP request actually carries·http
GET /api/messages HTTP/1.1
Host: example.com
Cookie: session=abc123def456
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

# ~600 bytes of envelope just to ask: "anything new?"
# Multiply by 10K clients polling every 2 seconds.
The same conversation, three asks deep·text
Client                          Server
  |                                |
  |--- GET /messages ------------->|
  |<-- 200 OK [] ------------------|   "no, nothing new"
  |                                |
  |   ... 3 seconds idle ...       |
  |                                |
  |--- GET /messages ------------->|
  |<-- 200 OK [] ------------------|   "still no"
  |                                |
  |   ... 3 seconds idle ...       |
  |   (server now has news)        |
  |                                |
  |--- GET /messages ------------->|
  |<-- 200 OK [{msg}] -------------|   "finally"

External links

Exercise

Open your browser dev tools, network tab. Visit any chat or social app you use daily and watch the network panel for 30 seconds while idle. Note: how many requests per minute? Are they polling, long-polling, SSE (look for text/event-stream), or WebSocket (look for status 101)? Write down what you see — you will revisit this list at the end of the quest.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.