Card 01/ 10

ConceptDifficulty: Beginner2 min

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.

The five patterns by who starts, which way data flows, and what stays open
PatternWho startsDirectionBetween messages
Short pollingClient, on a timerServer to client, as answersNothing open
Long pollingClient; the server holds the answerServer to client, as answersOne request held open, then a new one
Server-sent eventsClient opens it onceServer to client onlyOne response that does not end
WebSocketsClient opens it onceBoth ways, any timeOne connection, kept open
WebhooksAnother serverSender's server to yoursNothing 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