Step 1 · The pattern
Is there anything new?
A message is posted to the room now and then. The server has it, but the other phones do not know. The simplest way to find out is short polling: every phone asks on a timer, here every 2.5 seconds. News is late by up to one interval.
- poll / new message
- answer: nothing new
- answer with the message
In short
Polling, long polling, SSE, WebSockets: how it works and how it breaks
A client has four common ways to learn that something new happened. Short polling asks on a timer. Most answers say nothing is new, the load is the number of clients times the poll rate whether or not anything happens, and news is late by up to one interval. Long polling sends the same request, but the server holds it open until there is news, answers, and the client asks again. Server-Sent Events keep a single HTTP response open and the server writes each event down it, in one direction. A WebSocket upgrades the connection so that both sides can send at any time. With a held connection the work follows events instead of clients times time, and news arrives at once. The price is that the server keeps a connection open for every client, and every proxy on the path has to allow that.
How this comes up in interviews
"Design how a chat or notification client learns that something new has happened. Which options do you have, and how do you choose between them?"
Then they ask
- The product team wants polling to feel live, so they ask to poll faster. What does that cost?
- You move to a held connection per user. What new costs and failure modes does the server side take on?
- When is plain polling still the right choice?
A strong answer covers
- Short polling asks on a timer: load is clients times poll rate whether or not anything happens, and news is late by up to one interval.
- Long polling holds the request open until there is news, answers, and the client asks again.
- Server-Sent Events keep one HTTP response open and write events down it in one direction. A WebSocket lets both sides send at any time.
- With a held connection the work follows events, and news arrives at once.
- The price is an open connection per client on the server, and every proxy on the path has to allow it.
Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.
On one page: the track cheat sheet.
Sources: HTML Standard: Server-sent events (WHATWG) ↗ · RFC 6455: The WebSocket Protocol ↗ · Uber's Real-Time Push Platform (Uber Engineering) ↗ · Report a problem
Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.