← Lessons

quiz vs the machine

Platinum1750

System Design

Long Polling vs SSE vs WebSockets

Three ways to push live updates to a browser and how to choose between them.

6 min read · advanced · beat Platinum to climb

Pushing to the browser

Plain HTTP is request response, so getting live server updates to a client needs a technique. Three dominate.

  • Long polling has the client send a request that the server holds open until it has data or a timeout, then the client immediately reconnects. It works everywhere but reopens a connection per message, adding overhead.
  • Server sent events, or SSE, opens one long lived HTTP connection over which the server streams events. It is one directional server to client, auto reconnects, and is simple, but it carries only text and is limited by the browser per host connection cap on older HTTP.
  • WebSockets upgrade the connection to a full duplex channel where both sides send messages anytime. It suits chat, games, and collaborative editing but adds protocol complexity and needs its own scaling and load balancing.

Choosing

  • Need only server to client updates like a notification feed or live scores: prefer SSE for its simplicity.
  • Need two way low latency messaging: pick WebSockets.
  • Stuck with old proxies or want the simplest fallback: long polling still works.

Key idea

Use SSE for one way streaming WebSockets for full duplex messaging and long polling as the universal fallback when neither is available.

Check yourself

Answer to earn rating on the learn ladder.

1. Which transport is full duplex, letting both sides send anytime?

2. When is SSE a good fit?

3. What is a downside of long polling versus a streamed connection?