Part I β The Pipes Β· Lesson 2.1
Communication Overview
In one lineTwo questions decide everything: who starts the message, and how often does it arrive?
Where you've seen itA single Swiggy order-tracking screen runs three transports at once β REST for the order, a stream for rider location, push for the doorbell moment.
Diagram
How it works
- Decide direction. Only the server has news β SSE or polling. Both sides talk β WebSocket.
- Decide frequency. Slower than a minute β poll. Faster than a second β stream.
- Decide the cost you can pay. Polling burns requests; streaming burns open connections and server memory.
- Always design the fallback. Corporate proxies still block WebSockets; mobile networks drop streams on backgrounding.
Trade-offs
| Transport | Direction | Cost per client | Reconnect logic |
|---|---|---|---|
| Short polling | pull | N requests/min | none needed |
| Long polling | pull, feels like push | 1 held request | you write it |
| WebSocket | duplex | 1 socket + state | you write it |
| SSE | server β client | 1 held response | built in |
| WebHook | server β server | none (no client) | retry queue |
Interview angle
"Design the update mechanism for a food-delivery tracking screen."
- Split by frequency: order status changes rarely (poll), rider location changes constantly (stream).
- Use SSE for location because it's one-way and reconnects itself; save WebSockets for the chat with the rider.
- State the fallback and the reconnect/backoff policy β that's the part candidates skip.
Recap
- Direction and frequency pick the transport; everything else is detail.
- Pull wastes requests, push holds connections β choose which cost you prefer.
- Real screens mix transports; one answer for the whole app is a red flag.