0️⃣ Quick Comparison

FeaturePollingLong PollingSSEWebSocket
Real-time⚠️ Almost
Persistent Connection⚠️ Temporary
DirectionClient → ServerClient → ServerServer → ClientBi-directional
HTTP BasedStarts with HTTP
Server Push⚠️ Sort of
ComplexityLowMediumMediumHigh
ScalabilityPoorBetterGoodGood

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.

Example

Client calls: GET /score every 5 seconds.

Client                      Server
 
Request --------------->
 
               Current Score = 100
 
<--------------- Response
 
(wait 5 sec)
 
Request --------------->
 
               Current Score = 100
 
<--------------- Response
 
(wait 5 sec)
 
Request --------------->
 
               Current Score = 120
 
<--------------- Response

Pros

  • Simple
  • Easy to implement
  • Works everywhere

Cons

  • Lots of unnecessary requests
  • High server load
  • Updates are delayed. you get stale data of 5 sec
    • If polling interval = 5 sec Server updated at 10:01 - Client sees at 10:05

System design Use Cases

  • Monitoring pages - Dashboard refresh every 1 min

Note: 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

  • HTTP 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.

Server seding cricket score data.

data: Score = 100
 
data: Score = 120
 
data: Score = 150

Characteristics

FeatureSSE
DirectionServer → Client
ProtocolHTTP
Persistent ConnectionYes
Auto ReconnectYes
Browser SupportExcellent

Pros

  • Simpler than WebSockets
  • Uses HTTP
  • Automatic reconnection
  • Lower overhead compair to long polling as connection remain open

Cons

  • One-way communication - Client cannot push data through same connection

Interview Use Cases

  • Stock prices
  • Great for live feeds
  • Live sports score
  • News feed
  • Monitoring dashboard

4️⃣ WebSockets

WebSocket creates a persistent TCP connection. After connection establishment:

Client <---------> Server

Both sides can send messages anytime.


Handshake

When the browser wants a WebSocket:

const socket =
    new WebSocket("wss://chat.example.com");

Starts as HTTPS:

GET /chat HTTP/1.1
Host: chat.openai.com
Upgrade: websocket
Connection: Upgrade

Server:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade

The connection becomes: WebSocket Protocol over the same TCP connection.


Flow

Characteristics

FeatureWebSocket
DirectionTwo-way
PersistentYes
Real-timeYes
Protocol UpgradeYes

Pros

  • Lowest latency
  • Bi-Directional
  • Efficient - less overhead compair to http based soluation
  • Ideal for real-time apps

Cons

  • More complex
  • Stateful connections - Load balancing becomes harder
  • scalability Issue

System Design Use Cases

  • Chat applications
  • WhatsApp
  • Slack
  • Multiplayer games
  • Trading platforms
  • Collaborative editors
  • ChatGPT

System Design 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

WebSockets are not easier to scale than stateless HTTP. They require maintaining long-lived stateful connections, sticky routing, connection management, and often a shared messaging layer like Redis Pub/Sub or Kafka. However, for large-scale realtime systems they are much more network-efficient than polling because they avoid repeated requests and allow instant bidirectional communication.