Chapter 2 · Communication
Interview drill
7 questions from this chapter. Answer each one out loud first, then open it to compare.
-
2.1"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.
-
2.2"What's wrong with
setInterval(fetchData, 1000)?"- Responses slower than the interval stack up; use a
setTimeoutchain that waits for the response. - It keeps polling in a hidden tab — gate on
visibilityStateand back off. - No jitter means synchronised clients hammer the server in waves.
- Responses slower than the interval stack up; use a
-
2.3"Why not just poll every second instead?"
- Short polling burns requests when nothing changed; long polling only answers when there's news.
- The cost moves from bandwidth to held server connections and requires a non-blocking server.
- Past roughly one update per second, reconnect churn beats the savings — switch to WebSocket or SSE.
-
2.4"Your chat works locally and breaks behind the company proxy. Why?"
- Some proxies strip the
Upgradeheader or kill idle connections;wss://(TLS) survives far more of them. - Add heartbeats so a silently dead connection is detected, and always ship an SSE or long-poll fallback.
- Behind a load balancer, a reconnect can land on a different server — you need a shared pub/sub layer, not in-memory state.
- Some proxies strip the
-
2.5"Score ticker for ten million viewers — SSE or WebSocket?"
- SSE: the client never sends anything, so duplex is wasted capacity and wasted code.
- Reconnect and replay come free via
Last-Event-ID, which is the hard part of a WebSocket build. - It's plain HTTP, so it rides existing CDN, proxy, and HTTP/2 infrastructure — but confirm HTTP/2 first.
-
2.6"Payment succeeds. How does the user's screen update?"
- Two hops: Stripe → your server by webhook, then your server → the browser by SSE, WebSocket, or a short poll on the order.
- Never wait on the webhook in the checkout request — show an optimistic pending state and reconcile.
- Handle duplicate and out-of-order deliveries with an idempotency key on the event id.
-
2.7"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.
- Prices: SSE — one-way, high frequency, and free reconnect with replay by