← Lessons

quiz vs the machine

Platinum1700

System Design

Long Polling vs SSE vs WebSocket

Three ways to push fresh data to a browser, and when each one fits.

5 min read · advanced · beat Platinum to climb

The push problem

Plain request response cannot let a server deliver data the moment it appears. Three techniques close that gap, each with different cost and direction.

The three options

  • Long polling: the client makes a request that the server holds open until data arrives or it times out, then the client immediately asks again. Simple and works everywhere, but each message restarts a request.
  • Server sent events: the server keeps one connection open and streams a one way feed of events to the client over plain HTTP. It auto reconnects but flows server to client only.
  • WebSocket: a full duplex persistent connection where both sides send freely after an upgrade handshake. Best for true two way, low latency traffic like chat.

Choosing

  • One way updates like a live feed favor SSE for its simplicity.
  • Interactive two way traffic favors WebSocket.
  • Long polling is the fallback where the others are unavailable.

Key idea

Long polling is the universal fallback, SSE streams one way cheaply, and WebSocket gives full duplex for interactive apps.

Check yourself

Answer to earn rating on the learn ladder.

1. Which option provides full duplex communication?

2. What direction does server sent events support?

3. Why is long polling considered the universal fallback?