Part I β The Pipes Β· Lesson 2.7
Picking a Transport
In one lineAnswer three questions in order β direction, frequency, tolerance for staleness β then defend the cost.
Where you've seen itA live order screen runs four transports at once, each chosen for a different piece of the UI.
Diagram
DECISION TREE
Does the client need to SEND, not just receive?
β
βββββββββββββββββ΄ββββββββββββββββ
YES NO
β β
WebSocket How often does it change?
(chat, cursors, β
games, collab) ββββββββββββββββΌβββββββββββββββ
> 1 min 1s β 1 min < 1s
β β β
Short polling Long polling SSE
(+ ETag, jitter) (or SSE) (ticker, feed,
token stream)
Event starts in ANOTHER system, no browser? βββΊ WebHookCOST TABLE β what you pay per 10,000 concurrent clients
requests/min open conns server state you write
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Short poll (5s) 120,000 0 none nothing
Long poll (30s) 20,000 10,000 list cursor logic
SSE 0 10,000 last-id almost none
WebSocket 0 10,000 session reconnect,
resubscribe,
replay
WebHook 0 0 queue idempotencyONE SCREEN, FOUR TRANSPORTS β the answer interviewers want
βββββββββββββββββββββββββ Order tracking βββββββββββββββββββββββββ
β β
β Order details, address β REST, fetched once β
β Status: "Preparing" β SSE, changes ~5 times per order β
β Rider on map β SSE, 1 update/sec while moving β
β Chat with rider β WebSocket, both sides send β
β "Delivered" notification β Web Push, works with tab closed β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββHow it works
- Direction first. Client must send β WebSocket. Otherwise you're choosing among pull options and SSE.
- Frequency second. Minutes β poll. Seconds β long poll or SSE. Sub-second β SSE or WebSocket.
- Staleness third. If a 30-second-old value is harmless, polling is the cheaper, simpler answer β and it survives every proxy.
- Then name the cost you accepted: wasted requests, held connections, or reconnect code you now own.
- Then name the fallback and the offline behaviour. Every streaming answer needs one.
Trade-offs
| Don't use WebSocket if | Don't use SSE if | Don't use polling if |
|---|---|---|
| Only the server has news | The client must send | Sub-second freshness matters |
| You can't run a pub/sub backplane | You're stuck on HTTP/1.1 with many streams | Clients number in the millions |
| The feature is a notification badge | You need binary payloads | Battery and data cost matter |
Interview angle
"Design real-time updates for a stock trading dashboard."
- Prices: SSE β one-way, high frequency, and free reconnect with replay by
Last-Event-ID. - Order placement and fills: WebSocket, because the client sends and needs sub-second acknowledgement.
- Throttle on the client: coalesce ticks into one render per animation frame, or the UI dies before the network does.
Recap
- Direction β frequency β staleness. Three questions, in that order.
- State the cost you accepted and the fallback you'd ship; that's the senior signal.
- Mixing transports on one screen is the correct answer, not a compromise.