Lesson 1 / 32
Why Plain HTTP Is Not Enough
Explain why request/response cannot push data to a browser and name the three ways web apps work around it.
By Rahul Agarwal · 15 years in web development
Pull vs push
Classic HTTP is pull: the browser sends a request, the server sends one response, and the exchange is over. The server has no way to start a conversation; it can only answer. That is fine for loading a page, but many features need push: a new chat message, a cricket score change, a delivery rider moving on the map, or an LLM printing its answer token by token. The data appears on the server at a moment the browser cannot predict. There are three families of workaround. Polling keeps asking "anything new?" on a timer. Server-Sent Events (SSE) keep one HTTP response open and let the server write events into it whenever it likes. WebSockets upgrade an HTTP connection into a long-lived, two-way channel where either side can send at any time. "Real-time" on the web means soft real-time: updates within tens or hundreds of milliseconds, with no hard guarantee.
From asking repeatedly to being told
The section moves left to right: short polling, long polling, Server-Sent Events, then WebSockets. Each step cuts wasted requests and latency, and each adds a little more connection state on the server.
The tea stall and the phone call
Polling is walking to the tea stall every two minutes to ask if your chai is ready. SSE is the stall owner shouting your token number when it is ready, while you can only listen. A WebSocket is a phone call: both of you can talk whenever you want, but the line stays busy the whole time.
Real-time is a product decision first
Before reaching for WebSockets, ask how stale the data may be. A dashboard that refreshes every 30 seconds is perfectly served by polling. Persistent connections cost memory, load-balancer configuration and reconnect logic, so pay that price only when users actually need sub-second updates.
Quick check: Why can a plain HTTP/1.1 server not send a new chat message to a browser on its own?
- Because HTTP responses cannot contain JSON
- Because the server can only respond to a request the client has already sent
- Because browsers block all incoming TCP packets
- Because HTTP/1.1 has no Content-Type header
Answer
Because the server can only respond to a request the client has already sent — HTTP is request/response: the server can only answer an open request. Push techniques work by keeping a request or connection open so the server has something to write into.