Real-Time Updates
Polling, WebSockets, SSE.
HTTP is request and response. The client asks, the server answers. But what about a chat message, or a live order status, that the server needs to push right now?

- Client asks, server answers
- But the server has news
- How does it push?
Four ways to stay updated
There are four common answers. Short polling asks every few seconds, which is simple but wasteful. Long polling asks, and the server holds the request open until there's news. Server sent events keep one connection open, and the server streams updates down it. WebSockets open a two way channel, so both sides can send at any time.
| Technique | How it works | Good for |
|---|---|---|
| Short polling | ask every few seconds | rare updates |
| Long polling | server waits to answer | simple push |
| SSE | server streams events | live feeds, AI text |
| WebSockets | two-way channel | chat, games |
The design cost
Real time has a cost. Each open connection uses memory on the server, so a million online users means a million open connections. You need servers built to hold many connections, and a way to find which server holds a given user's connection. We'll see this in the chat app case study.
| key | value |
|---|---|
| Open connections | memory per user |
| 1M users online | 1M connections |
| Special servers | built for many connections |
| Routing | which server has this user? |
Summary
Polling asks repeatedly, long polling waits, SSE streams down, and WebSockets go both ways. Next, a single front door for all your APIs.
Key takeaways- Polling is simple
- SSE streams to the client
- WebSockets go both ways