AI Hints
Home›System Design Tutorial›Safe Retries and API Styles
System Design · Lesson 21 of 120

Real-Time Updates

Polling, WebSockets, SSE.

⏱ 2 min read▶ Video at 23:49🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

HTTP is request and response. The client asks, the server answers. But what about a chat message, or a live order status, that the server needs to push right now?

Real-Time Updates
From the video: Real-Time Updates
  • Client asks, server answers
  • But the server has news
  • How does it push?

Four ways to stay updated

There are four common answers. Short polling asks every few seconds, which is simple but wasteful. Long polling asks, and the server holds the request open until there's news. Server sent events keep one connection open, and the server streams updates down it. WebSockets open a two way channel, so both sides can send at any time.

TechniqueHow it worksGood for
Short pollingask every few secondsrare updates
Long pollingserver waits to answersimple push
SSEserver streams eventslive feeds, AI text
WebSocketstwo-way channelchat, games

The design cost

Real time has a cost. Each open connection uses memory on the server, so a million online users means a million open connections. You need servers built to hold many connections, and a way to find which server holds a given user's connection. We'll see this in the chat app case study.

keyvalue
Open connectionsmemory per user
1M users online1M connections
Special serversbuilt for many connections
Routingwhich server has this user?

Summary

Polling asks repeatedly, long polling waits, SSE streams down, and WebSockets go both ways. Next, a single front door for all your APIs.

Key takeaways
  • Polling is simple
  • SSE streams to the client
  • WebSockets go both ways
Next up: API Gateways — one front door