Lesson 6 of 12
21. Polling vs WebSockets vs Push

21.5 How do you choose?

3 min read+10 XP

At the gate: Out of the house? It's a note in the letterbox. Need to talk back and forth? Phone line. Just want to hear the news? Radio. Expecting one thing, sometime this afternoon? Call now and then.

In the system:

three questions: is the app closed, does the client talk back, are updates rare.

Figure: three questions pick the transport.

DirectionLatencyServer costWorks when app closedTypical use
Short pollingClient asksInterval / 2 on averageMany requests, mostly emptyNo"Is my report ready?"
Long pollingServer → clientNear instantOne held request per userNoFallback
SSEServer → clientInstantOne open connection per userNoTracking, scores, feeds, AI streaming
WebSocketBoth waysInstantOne open, stateful connection per userNoChat, games, collaboration
Mobile pushServer → deviceSeconds, not guaranteedCalls to APNs/FCMYesAlerts that bring users back

Most real products combine them. The grocery app:

  • Mobile push for "out for delivery" and "delivered" when the app is in the background.
  • SSE (or a WebSocket) for the tracking screen while it's open, with the rider's position every few seconds.
  • A normal GET whenever the screen opens, to load the current state, so nothing depends on every event arriving.
  • If the app also has chat with the rider, a WebSocket for that screen.

Memory code: "Out? Push. Talking? WebSocket. Listening? SSE. Rarely? Poll."