FSD Frontend System Design

Chapter 2 · Communication

Interview drill

7 questions from this chapter. Answer each one out loud first, then open it to compare.

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

    Review 2.1 Communication Overview →

  2. 2.2"What's wrong with setInterval(fetchData, 1000)?"
    • Responses slower than the interval stack up; use a setTimeout chain that waits for the response.
    • It keeps polling in a hidden tab — gate on visibilityState and back off.
    • No jitter means synchronised clients hammer the server in waves.

    Review 2.2 Short Polling →

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

    Review 2.3 Long Polling →

  4. 2.4"Your chat works locally and breaks behind the company proxy. Why?"
    • Some proxies strip the Upgrade header 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.

    Review 2.4 Web Sockets →

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

    Review 2.5 Server-Sent Events →

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

    Review 2.6 WebHooks →

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

    Review 2.7 Picking a Transport →