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
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.