Mhonn YbañezSRE, DevOps, AI Engineer
 Today I Learned
Read the full page

What do polling, SSE, WebSockets, TCP, and UDP have in common?

Posted
Tags
networking, system-design, sre

They are all client-server communication patterns, split by who starts the conversation, which way data flows, and how long the connection lives. TCP and UDP are the layer underneath the rest, and the choice decides which SLOs make sense and how the system fails.

UDP, TCP, WebSocket, long polling, SSE. I've had these words floating around my head for a while, and I knew they belonged together somehow, but I couldn't name the thing they share.

The question I had

What's the common concept behind all of these?

What I found

They are all ways a client and server talk

They are client-server communication patterns: different answers to "how does data get between a client and a server?" Three questions sort them:

  • Who starts? Does the client ask, or does the server push?
  • Which way does data flow? One way, or both ways at once?
  • How long does the connection live? One request, or open for minutes and hours?

The catch is that they don't all sit at the same level. TCP and UDP are transport protocols, the floor everything else stands on. Polling, SSE, and WebSockets are patterns that run on top of TCP.

Pull: the client keeps asking

  • Short polling: the client sends a normal HTTP request every few seconds to ask "anything new?" Simple, but most answers are "no", and every one of them costs the server a full request.
  • Long polling: the client asks, and the server holds the request open until there is something to send or a timeout hits. As soon as the client gets an answer, it asks again. Fewer wasted requests, and it works almost everywhere, which is why it survives as a fallback.

Push: the server sends when it has something

  • SSE (Server-Sent Events): one long-lived HTTP response that the server keeps writing events into. The browser reads it with the built-in EventSource API. It only carries text, only flows server to client, and reconnects on its own (sending a Last-Event-ID so the server can pick up where it left off). On HTTP/1.1, browsers allow only about 6 connections per domain, so SSE in many open tabs can starve the page. HTTP/2 removes that limit.

Both ways: either side can talk at any time

  • WebSockets: starts as an HTTP request that asks to "upgrade", then becomes a long-lived, two-way connection over TCP. Good for chat, multiplayer games, and collaborative editing. Long-lived isn't permanent, though: networks, proxies, and deploys drop them, so the client needs reconnect logic.
  • WebTransport: a newer option built on HTTP/3 (QUIC). It offers reliable streams and also unreliable datagrams, so a browser can get UDP-like "fire and forget" messages.
  • WebRTC data channels: built for peer-to-peer audio and video, but the data channels also work client to server through a media server.

Underneath: TCP, UDP, and QUIC

  • TCP: connection first, then a reliable, ordered stream of bytes. Lost packets get resent. HTTP/1.1, HTTP/2, WebSockets, and SSE all run on it. The cost is that one lost packet holds up everything behind it (head-of-line blocking).
  • UDP: no connection, no resends, no ordering. Just packets sent to an address and port. Used where late data is worthless anyway: video calls, online games, and DNS.
  • QUIC: runs on UDP but adds reliability and built-in encryption (TLS 1.3) itself. It fixes specific TCP pain points: a lost packet only stalls its own stream, the connection and encryption handshakes happen together, and a connection can survive switching from Wi-Fi to mobile data. HTTP/3 runs on QUIC.

Side by side

ModelWho startsData flowsConnectionGood for
Short pollingPullClientServer → clientNew request each timeSimple, non-urgent checks
Long pollingPullClientServer → clientHeld open until data or timeoutFallback when nothing better works
SSEPushClient opens, server pushesServer → clientLong-lived HTTPLive feeds, dashboards, notifications
WebSocketsPush and pullClient opens, either side sendsBoth waysLong-lived TCPChat, games, collaboration
WebTransportPush and pullClient opens, either side sendsBoth waysLong-lived QUIC (UDP)Low-latency streams, high-frequency telemetry

What it looks like in code

Implementing a specific pattern depends on the programming language used. Here's one example in browser JavaScript, moving from short polling to a WebSocket:

// Short polling: ask every 5 seconds
setInterval(async () => {
  const res = await fetch('/api/updates');
  const data = await res.json();
}, 5000);

// WebSocket: one connection, the server sends when it has something
const socket = new WebSocket('wss://example.com/updates');

socket.onopen = () => {
  // Sending before the connection is open throws an error
  socket.send(JSON.stringify({ action: 'chat', message: 'Hello!' }));
};

socket.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('New data received:', data);
};

Additional questions I had

I assumed short polling and SSE were opposites: one pulls, the other pushes. They aren't exact reverses. Short polling opens and closes a connection over and over, while SSE opens one connection and streams down it. Both still start with the client.

The real reverse of polling is a webhook. Instead of the client asking "anything new?" over and over, the server calls a URL the consumer gave it whenever something changes. The roles flip: the server becomes the client. That only works when the consumer is itself a server with a reachable URL, which is why webhooks are for server-to-server, and browsers use SSE or WebSockets instead.

What it means for SRE work

The pattern decides what to measure and how things break.

What to measure

For request-response (polling), the usual SLIs work:

  • Latency: "99% of requests return within 200ms."
  • Error rate: "Fewer than 0.1% of requests return a 5xx."
  • Throughput: requests per second, mostly for capacity.

For long-lived connections (SSE, WebSockets, WebTransport), a request count says very little. What users feel is:

  • Connection success rate: how many connection attempts actually open.
  • Delivery latency: "99% of events reach the client within X ms of being created."
  • Unexpected drops: "Fewer than 1% of connections drop per minute."

How many connections a node can hold (say 50,000) matters a lot, but that's a capacity target and a saturation alert, not an SLO. Users don't feel the number, they feel what happens when it runs out.

How it fails

  • Thundering herd. With polling, a short outage ends and every client retries at the same moment. Long-lived connections have their own version: a deploy or node restart drops thousands of sockets and they all reconnect at once. The fix is the same for both, exponential backoff with jitter. I wrote about this in my thundering herd vs retry storm post.
  • Running out of file descriptors. Every open connection is an open file to the operating system. A server can have spare CPU and memory and still refuse new connections because it hit its open file limit (ulimit -n, often 1024 by default). The error is EMFILE: too many open files. epoll is how the server watches all those connections efficiently. It isn't the limit itself.
  • Sticky connections and uneven load. A load balancer only picks a server when a connection opens. With long-lived connections, a server keeps its clients for as long as they stay connected. During a traffic spike, newly added servers only get new connections while the old ones stay overloaded. Least-connections balancing, a maximum connection age (so clients reconnect and spread out), and draining connections before a deploy help even it out.

Takeaway

These words share one concept: how a client and server exchange data. TCP and UDP are the layer underneath, and polling, SSE, and WebSockets are patterns on top. Choosing one is an infrastructure decision too. Polling is easy to run but wastes requests and herds on recovery. Persistent connections are fast but bring connection limits, reconnect storms, and uneven load that I have to plan for.