FSD Frontend System Design

Part I β€” The Pipes Β· Lesson 2.3

Long Polling

In one lineThe client asks, and the server holds the request open until it actually has news.

Where you've seen itOld Facebook Chat β€” messages appeared instantly, years before WebSockets existed in browsers.

  • Time13 min
  • DiagramSequence with a held connection, vs short polling timeline
  • Chapter2 Β· Communication

Diagram

diagram
diagram
diagram

How it works

  1. Client sends a request.
  2. Server does not respond; it parks the request and registers the client as a listener.
  3. On new data β†’ respond immediately. On a 25–30s timeout β†’ respond empty.
  4. Client immediately opens the next request, passing the last id it saw.
  5. Server replays anything that arrived during the gap.

Trade-offs

Use whenAvoid when
Updates are infrequent and unpredictableUpdates are constant β†’ WebSocket
Proxies or firewalls block WebSocketsYou need client β†’ server push too
You want plain HTTP infrastructureServer can't hold many open connections

Server-side cost: every waiting client occupies a connection. A thread-per-request server dies at a few thousand; an event-loop server (Node, Go, nginx) handles far more. This is a backend constraint you should name out loud.

Interview angle

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

Recap

  • Long polling is pull that feels like push.
  • Always pass a cursor (?since=) β€” the gap between responses drops messages otherwise.
  • Bridge technology: correct when WebSockets aren't available, not when they are.