All the basics

What are live updates?

Instead of asking the server again and again, keep one line open so the server can tell you the moment something happens.

Two tin cans joined by a string. Once the string is pulled tight, either side can speak at any moment, with no need to ring first.

Press Play to watch it run · 7 steps

Polling asks the server over and over. A WebSocket or server-sent events connection stays open so the server can speak first.

Asking again and again, or one open linePolling asks the server over and over. A WebSocket or server-sent events connection stays open so the server can speak first.YouChat serverYour friend

Tap any box to see what it is and what it talks to.

  • Client
  • Service
Open in playground
Text description
  1. Your phone asks: any new messages?
  2. No. That trip was wasted.
  3. Two seconds later it asks again.
  4. No again. Most trips come back empty.
  5. Your friend sends a message. The server can only hold it.
  6. Up to two seconds late, your phone asks again.
  7. Only now do you see the message.
  • Asking over and over wastes trips and still arrives late.
  • An open connection lets the server speak first.
  • Use server-sent events for one-way updates, WebSockets for two-way.

Reach for it when

When people expect changes within a second, like chat or a delivery map. Asking every minute is fine for hourly reports.

The catch

Each open line holds server memory, so 100,000 chat users means 100,000 open lines, and every dropped line must catch up.

Say it in an interview“For chat I would use WebSockets so the server can push. Clients reconnect and resume from the last message ID. For one-way feeds, server-sent events are simpler.”