Card 01/ 10
Five Ways for New Data to Reach a Client
Told apart by who asks and whether the connection stays open between messages.
When data changes on a server, there are five common ways for a client to learn about it, and they differ in two things: who starts each exchange, and whether a connection stays open between messages. Short polling and long polling have the client ask. Server-sent events and WebSockets keep a connection open so the server can send. Webhooks have one server call another.
| Pattern | Who starts | Direction | Between messages |
|---|---|---|---|
| Short polling | Client, on a timer | Server to client, as answers | Nothing open |
| Long polling | Client; the server holds the answer | Server to client, as answers | One request held open, then a new one |
| Server-sent events | Client opens it once | Server to client only | One response that does not end |
| WebSockets | Client opens it once | Both ways, any time | One connection, kept open |
| Webhooks | Another server | Sender's server to yours | Nothing open |
An analogy. Short polling is checking the letterbox every hour. Long polling is waiting by the door until the postman comes. Server-sent events are a radio broadcast you tune in to. WebSockets are a phone call, where either side can speak. A webhook is a courier who rings your bell. The analogy breaks at the radio: a broadcast goes on with nobody listening, while a server-sent event stream exists only for the one client that opened it, and ends when that client leaves.
Why the choice matters. The patterns trade freshness against cost. Asking often wastes requests when nothing has changed; asking rarely delivers news late. Keeping a connection open delivers news at once, but every open connection holds memory on the server, so a million connected readers means a million open connections.
What each card that follows covers. For every pattern, the same five things in the same order: who starts the exchange and which way data flows, the messages as a sequence, what it costs the server, when it fits and when it does not, and one product that uses it.
So before choosing a pattern, answer two questions about the feature: who needs to send, and how soon must the other side know.
← → move through sections and cards