Scrivio Interview library
ConceptFoundations7 min read · updated 13 November 2026

Browsers get server updates without reloading in three main ways: long polling (a request held open until data arrives), server-sent events (a one-way stream over HTTP) and WebSockets (a two-way connection upgraded from HTTP).

Explain what each looks like on the wire and what proxies and load balancers must allow for each.

Long polling is an ordinary HTTP request that the server holds open until data arrives or a timeout passes; server-sent events are one long HTTP response with Content-Type text/event-stream that the server keeps writing to; a WebSocket starts as an HTTP/1.1 request with Upgrade: websocket, gets 101 Switching Protocols, and then carries frames in both directions. Proxies handle long polling without special support but need timeouts longer than the hold time, SSE needs unbuffered responses and long idle timeouts, and WebSockets need the Upgrade and Connection headers forwarded.

Why this question is asked

Live updates appear in almost every product: order tracking, notifications, dashboards, chat. Choosing between the three techniques is easy on a whiteboard, but most production trouble comes from the boxes in between: proxies that buffer, load balancers that cut idle connections, and deploys that drop thousands of clients at once. Interviewers ask this question to see whether we know what actually travels over the network, because that is what explains the failures. In this answer, we will look at each technique on the wire, see what each hop must allow, compare them side by side, and then choose one for a live order-status page.

1Long Polling: A Request That Waits

With long polling, the browser sends a normal HTTP request, for example GET /orders/42/updates?after=17. If there is news, the server answers at once. If there is none, the server does not answer with an empty response; it holds the request open until something happens or until a timeout, typically around 30 seconds, and then answers with the data or with 204 No Content. As soon as the browser receives the answer, it sends the next request. To the network, this looks like a slow but ordinary HTTP exchange.

Java
GET /orders/42/updates?after=17 HTTP/1.1
Host: shop.example.com
-- (server waits up to 30 s)
HTTP/1.1 200 OK
Content-Type: application/json
{"seq":18,"status":"SHIPPED"}
-- the client immediately sends ?after=18

Because it is plain HTTP, every proxy, CDN and corporate firewall understands it. The only requirement is that the timeouts along the path (proxy read timeout, load balancer idle timeout) are longer than the hold time; otherwise the proxy answers 504 before the server does. The costs are a new request and response headers for every message, and a short gap between responses where a message must wait for the next request. The after=17 parameter matters: it lets the server send anything the client missed during that gap.

2Server-Sent Events: One Response That Never Ends

Server-sent events (SSE) use one HTTP request and a response that keeps streaming. The server replies with Content-Type: text/event-stream and then writes small text blocks: lines starting with data:, an optional id: and event:, and a blank line to end each event. The browser's EventSource API parses this and fires an event for each block. It is one-way: server to client only; the client uses normal requests to send anything back.

YAML
GET /orders/42/stream HTTP/1.1
Accept: text/event-stream
HTTP/1.1 200 OK
Content-Type: text/event-stream
Cache-Control: no-cache
id: 18
data: {"status":"SHIPPED"}
: keep-alive comment, sent every 15 s
id: 19
data: {"status":"OUT_FOR_DELIVERY"}

A nice property is built in: if the connection drops, EventSource reconnects automatically and sends a Last-Event-ID header with the last id it saw, here 19, so the server can resume without losing events. For proxies there are two needs. First, they must not buffer the response; NGINX, for example, buffers proxied responses by default, so the events would arrive in clumps or not at all until the buffer fills. We turn buffering off for that location or send the X-Accel-Buffering: no header from the application. Second, idle timeouts must be longer than the gap between events, which is why servers send a comment line every 15 to 30 seconds as a heartbeat.

3WebSockets: An Upgraded, Two-Way Connection

A WebSocket begins as an HTTP/1.1 request with two special headers, Upgrade: websocket and Connection: Upgrade, plus a random Sec-WebSocket-Key. If the server agrees, it answers 101 Switching Protocols with a Sec-WebSocket-Accept value derived from that key. From then on, the TCP connection no longer carries HTTP. Both sides send small binary frames, text or binary messages plus control frames such as ping, pong and close, in either direction at any time.

YAML
GET /chat HTTP/1.1
Host: shop.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
-- from here: frames in both directions

Notice that Upgrade and Connection are hop-by-hop headers: by the HTTP rules, a proxy removes them before forwarding a request. So a reverse proxy must be told explicitly to pass them on and to speak HTTP/1.1 to the backend. If it does not, the backend sees an ordinary GET and answers 400 or 426 Upgrade Required. Load balancers must also support the upgrade and then treat the connection as an opaque byte stream. WebSockets can also be carried over HTTP/2 with the extended CONNECT method (RFC 8441), but support across proxies and servers is uneven, so most deployments still use HTTP/1.1 for the upgrade.

4What Every Hop Must Allow

All three techniques hold something open for a long time: a pending request, a streaming response or a connection. That changes the arithmetic at every hop. A proxy that handles 1,000 short requests per second with 50 open at a time may suddenly hold 100,000 open connections, each using a file descriptor and some memory. Idle timeouts at the CDN, the cloud load balancer, the reverse proxy and the application server must all be longer than the longest silence, or heartbeats must be more frequent than the shortest timeout. And deploys need connection draining: when a node is replaced, its open streams and sockets must be closed gracefully so clients reconnect elsewhere, rather than all failing at once.

The three techniques compared
Long pollingServer-sent eventsWebSocket
On the wirerepeated normal requestsone long text/event-stream responseHTTP upgrade, then frames
Directionserver to client per replyserver to clientboth ways
Reconnect and resumeclient sends last seen idbuilt in: Last-Event-IDwrite it yourself
Proxy needstimeout above hold timeno buffering, long idle timeoutforward Upgrade and Connection
Overhead per messagefull request and headersa few bytes of framing2 to 14 bytes of framing
All three need long idle timeouts and graceful draining at every hop.

5Choosing for a Live Order-Status Page

For an order-status page, updates flow one way, from server to browser, and arrive a few times per order. That is exactly what SSE is good at. It works over plain HTTP, so it passes through CDNs and firewalls that might block upgrades, it gets automatic reconnection and resume through Last-Event-ID for free, and with HTTP/2 many streams share one connection, so several open tabs are not a problem. In Spring Boot, a controller can return an SseEmitter or, in WebFlux, a Flux of ServerSentEvent. We would choose WebSockets only if the page needed frequent messages from the client too, such as a chat with the courier, and long polling only as a fallback for very restrictive networks.

6Follow-up questions

Which would you choose for a live order-status page, and why?

Server-sent events. The data flows only from server to browser, SSE is plain HTTP so it passes through proxies and CDNs that are configured not to buffer, and EventSource reconnects and resumes with Last-Event-ID automatically. Over HTTP/2, many tabs share one connection. WebSockets would add the upgrade handling and our own reconnection logic for no benefit, because the client has nothing to stream back.

Can a CDN cache or break an SSE stream?

It can if it buffers responses or applies a short response timeout. We mark the stream with Cache-Control: no-cache, disable buffering for that path and check the CDN's limits for long-lived responses; some CDNs require a specific setting or product tier for streaming.

How does the server know a long-poll client has gone away?

Often it does not until it tries to write the response. That is why held requests need a timeout and why the server should not keep per-request state that leaks if the client disappears. With SSE and WebSockets, heartbeats reveal dead connections because the write fails.

7Conclusion

In this answer, we saw what each technique looks like on the wire. Long polling is a normal request the server holds, and any proxy handles it if timeouts exceed the hold time. SSE is one long text/event-stream response with built-in reconnection through Last-Event-ID, and proxies must not buffer it. A WebSocket upgrades an HTTP/1.1 request with 101 Switching Protocols and then exchanges frames both ways, so proxies must forward the hop-by-hop Upgrade and Connection headers; HTTP/2 extended CONNECT exists but support varies. All three need long idle timeouts, connection capacity and graceful draining at every hop.

What to say in the interviewAbout 80 seconds aloud

Open with

Long polling is just a normal HTTP request that the server holds open until there is data or a timeout, say 30 seconds, and then the client sends the next one with the last id it saw.

Then, if they want more

Any proxy can carry it, but the proxy and load balancer timeouts have to be longer than the hold time or you get 504s.

Server-sent events are a single HTTP response with content type text/event-stream that never ends; the server writes data lines, the browser's EventSource parses them, and if the connection drops it reconnects by itself and sends Last-Event-ID so the server can resume.

The proxy must not buffer that response, which NGINX does by default, and idle timeouts must be long, so the server sends comment heartbeats. A WebSocket starts as an HTTP/1.1 request with Upgrade: websocket and Connection: Upgrade, the server answers 101 Switching Protocols, and then both sides send frames in either direction.

Because Upgrade and Connection are hop-by-hop headers, the proxy must be configured to forward them. There is also WebSocket over HTTP/2 with extended CONNECT, but support is uneven. For all three, long-lived connections mean idle timeouts, connection limits and draining during deploys matter at every hop. For an order-status page I would pick SSE.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain what each looks like on the wire and what proxies and load balancers must allow...": https://scrivio-interview-library.netlify.app/architecture/load-balancing-networking/7541e489fb/