Think of a cricket score app π.
βHow does the server push real-time updates to clients?β
1οΈβ£ Polling
The client repeatedly asks: > βAny new updates?β at a fixed interval.
Flow
Client Server
Request --------------->
Current Score = 100
<--------------- Response
(wait 5 sec)
Request --------------->
Current Score = 100
<--------------- Response
(wait 5 sec)
Request --------------->
Current Score = 120
<--------------- ResponseExample
Client calls: GET /score every 5 seconds.
Pros
- Simple
- Easy to implement
- Works everywhere
Cons
- Lots of unnecessary requests
- High server load
- Updates are delayed
If polling interval = 5 sec Server updated at 10:01 - Client sees at 10:05
Latency can be up to polling interval.
System design Use Cases
- Monitoring pages - Dashboard refresh every minute
Not suitable for chat apps
2οΈβ£ Long Polling
Instead of immediately responding: Server waits until new data arrives.

Pros
- Almost real-time
- Atleast better then Polling
Cons
- Connection repeatedly opens/closes
- Scalability - Doesnβt scale as well for millions of users - creates http overhead
System design Use Cases
- Notification systems
- Before WebSockets became common
3οΈβ£ SSE (Server-Sent Events)
SSE keeps one HTTP connection open. Server continuously pushes updates.
Flow
Client ---------------------> Connect
Client <--------------------- Event
Client <--------------------- Event
Client <--------------------- Event
Client <--------------------- EventConnection remains open.
Example
Browser:
const eventSource =
new EventSource("/events");Server:
data: Score = 100
data: Score = 120
data: Score = 150Characteristics
| Feature | SSE |
|---|---|
| Direction | Server β Client |
| Protocol | HTTP |
| Persistent Connection | Yes |
| Auto Reconnect | Yes |
| Browser Support | Excellent |
Pros
- Simpler than WebSockets
- Uses HTTP
- Automatic reconnection
- Great for live feeds
Cons
- One-way communication
- Client cannot push data through same connection
Interview Use Cases
- Stock prices
- Live sports score
- News feed
- Monitoring dashboard
4οΈβ£ WebSockets
WebSocket creates a persistent TCP connection.
After connection establishment:
Client <---------> ServerBoth sides can send messages anytime.
Handshake
Starts as HTTP:
GET /chat
Upgrade: websocketServer:
101 Switching ProtocolsNow protocol becomes WebSocket.
Flow
Client <=================> Server
Chat Message
Client <=================> Server
Typing Event
Client <=================> Server
Read ReceiptFull duplex communication.
Characteristics
| Feature | WebSocket |
|---|---|
| Direction | Two-way |
| Persistent | Yes |
| Real-time | Yes |
| Protocol Upgrade | Yes |
Pros
- Lowest latency
- Full duplex
- Efficient
- Ideal for real-time apps
Cons
- More complex
- Stateful connections
- Load balancing becomes harder
Interview Use Cases
- Chat applications
- Slack
- Multiplayer games
- Trading platforms
- Collaborative editors
Quick Comparison
| Feature | Polling | Long Polling | SSE | WebSocket |
|---|---|---|---|---|
| Real-time | β | β οΈ Almost | β | β |
| Persistent Connection | β | β οΈ Temporary | β | β |
| Direction | Client β Server | Client β Server | Server β Client | Bidirectional |
| HTTP Based | β | β | β | Starts with HTTP |
| Server Push | β | β οΈ Sort of | β | β |
| Complexity | Low | Medium | Medium | High |
| Scalability | Poor | Better | Good | Best for realtime |
Easy Interview Rule
If interviewer asks:
User refreshes every minute
β‘οΈ Polling
Notification service
β‘οΈ Long Polling or SSE
Live cricket score
β‘οΈ SSE
Reason:
- Server pushes updates
- Client rarely sends data
- Simpler than WebSocket
WhatsApp / Slack
β‘οΈ WebSocket
Reason:
- User sends and receives messages continuously
- Bidirectional communication required