Skip to the guide

Polling, long polling, SSE and WebSockets

IntermediateConcept3 pages

HTTP is built for the client to ask and the server to answer. Chat, notifications and live scores need the opposite: the server has news and must tell the client now. There are four ways to do it, and in any real-time design the interviewer will ask which you'd pick and what it costs at scale.

Waiting for your order at a food court

You've ordered at a busy food court. You could walk to the counter every minute and ask "is it ready?", and mostly hear no. You could stand at the counter until it's ready, then queue again for your next item. They could hand you a buzzer that goes off whenever there's news, though you can't talk back through it. Or you could both have walkie-talkies.

  • asking every minute → short polling: the client sends a request every few seconds
  • waiting at the counter → long polling: the server holds the request open until there's news
  • the buzzer → SSE (server-sent events): one long-lived response the server keeps writing to, server to client only
  • walkie-talkies → WebSockets: one connection, both sides send whenever they want
  • the counter → the chat server that has the news