Long Polling
Server holds the connection open until data is ready, then client immediately reconnects.
Your chat app asks the server every three seconds whether anything is new. Almost every time, the answer is no.
At 10,000 people online that is 3,300 requests a second, and 99 percent of them return an empty list. You are paying for a fleet of servers whose main job is saying nothing yet, and a message still takes up to three seconds to appear.
Long polling changes one word of the deal. When the server has nothing to say, it says nothing and holds the request open instead of answering.
The message now arrives the instant it exists, and a quiet client makes two requests a minute rather than twenty. Your cost stops tracking the clock and starts tracking what actually happens.
Lessons
3 in this chapter- The Hanging RequestThe server parks the request until there is something worth answering with.2 min
- Timeouts and ReconnectsYour hold time is set by the grumpiest proxy in the path, and the reconnect gap eats messages.2 min
- Long Polling at ScaleCapacity is measured in parked connections, and the failure mode is the reconnect stampede.2 min