Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
System Design topics
Lesson 23/ 31
Distributed Systems & Architecture

Real-Time Communication

Deliver sub-second chat, live scores, notifications, and video calls with the right push transport.

IntermediateWebSockets · SSE · Fan-Out3 quiz questions0/2 subtopics done
Practice in AI HLD
In plain wordsDiagramTheorySubtopics (2)Step by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice
Deep-dive subtopics (2) - 0/2 completed
Polling vs. SSE vs. WebSockets

Choose the simplest real-time transport for chat, AI streaming, dashboards, and games.

Beginner
Feed Fan-Out: Push vs. Pull (Hybrid)

How Twitter/Instagram deliver posts to millions of followers without melting.

Intermediate

In plain words

Real-time communication lets the server push updates to you the instant they happen, instead of your app asking "anything new?" over and over.

Think of it like…

Polling is checking your mailbox every 10 seconds; SSE/WebSockets is a live phone line; push fan-out vs. pull fan-out is mailing flyers to 10M people vs. putting a poster on a billboard.

Where you’ve seen it

In WhatsApp, a WebSocket connection stays open, so a friend’s message appears on your screen immediately.

Words you’ll hear

Polling
The client repeatedly asks the server for updates.
Long polling
The server holds the request open until there is something new.
WebSocket
A two-way connection that stays open.
SSE
Server-sent events: a one-way stream from server to browser.

Visual diagram

Loading interactive diagram
Loading interactive exercise

Theory & deep dive

Scaling stateful WebSockets across multiple servers

Unlike stateless REST servers, a WebSocket holds an open TCP connection in memory! If Alice is connected to WS-Gateway-1 and Bob is connected to WS-Gateway-2, WS-Gateway-1 cannot push a message straight to Bob’s phone.

The standard pattern is a Connection Registry + Pub/Sub (e.g., Redis Pub/Sub or Kafka): WS-Gateway-1 publishes Bob’s message to channel user:bob, and WS-Gateway-2 (subscribed to Bob) pushes it down Bob’s live socket.

Key takeaway: Use Redis Pub/Sub (or NATS) behind WebSocket gateways so any server can reach any connected user.

How it works, step by step

Step 1 of 4
Transport Layer

1. Pick the client-server transport

Use SSE for one-way server-to-client feeds (LLM tokens, live scores); WebSockets for bidirectional low-latency chat/collab; WebRTC for P2P/SFU audio/video.

SSE works over plain HTTP; WebSockets handle full-duplex frames
Key numbers at this step
1-Way Stream
SSE
Bi-Directional
WebSockets

When to use it & trade-offs

What it is

Real-time communication replaces wasteful polling with persistent or push channels - SSE, WebSockets, WebRTC, and mobile push (APNs/FCM) - paired with scalable fan-out routing.

Why it matters: Naive HTTP polling every second wastes battery and bandwidth, while naive WebSocket fan-out explodes when 1M viewers watch one live stream.

When to reach for it

  • Chat apps (WhatsApp/Slack): WebSockets + Redis presence + APNs/FCM offline push
  • Live news feeds (Twitter/Instagram): Hybrid push-for-normals / pull-for-celebrities fan-out
  • Group video conferencing: WebRTC with an SFU (Selective Forwarding Unit)

When to avoid or be careful

  • Short-polling every 500 ms across millions of clients (kills servers and batteries)
  • Fan-out-on-write for a user with 50M followers (triggers massive write amplification)

Real-Time Transport Options

Server-Sent Events (SSE)
Best for: Stock tickers, live sports scores, AI streaming responses, notifications

Strengths: Standard HTTP, automatic reconnect, firewall-friendly, simpler than WebSockets.

Watch out: Unidirectional (server → client only); binary payloads need Base64.

WebSockets
Best for: Chat apps, multiplayer games, collaborative whiteboards/docs

Strengths: Full-duplex, tiny 2-byte frame overhead, instant bidirectional messaging.

Watch out: Stateful TCP connections complicate load balancing, draining, and horizontal scale.

WebRTC (with SFU / TURN)
Best for: Video/audio calls and low-latency screen sharing

Strengths: UDP media transport with NAT traversal (ICE/STUN/TURN) and SFU selective forwarding.

Watch out: Complex signaling and media server bandwidth costs for large rooms.

Interview signals & numbers to know

When this topic comes up

  • real-time chat
  • presence / typing indicator
  • live scores
  • celebrity fan-out
  • video call

Benchmarks & rules of thumb

WebSockets per tuned server -
50k–250k concurrent
Presence heartbeat TTL -
30–60 seconds
Celebrity fan-out threshold -
~10k–100k followers
SSE reconnect -
Built-in `Last-Event-ID`

Common mistakes & follow-ups

Common interview mistakes

  • Storing WebSocket connections without an external user → pod mapping, making cross-user delivery impossible
  • Updating presence ("last seen") straight to SQL every 5 seconds instead of Redis with TTLs
  • Using fan-out-on-write for celebrities, causing 30-second feed delivery lag

Likely interviewer follow-ups

  • How do you gracefully deploy a WebSocket gateway holding 100,000 active connections without a thundering-herd reconnect?
  • How does WhatsApp ensure message ordering and offline delivery across multiple devices?
  • Explain why Twitter/Instagram uses a hybrid push+pull fan-out model.
Interview tip: Separate stateful WebSocket Gateways from stateless Chat/Presence services, and always propose Hybrid Fan-Out when feeds + celebrities appear.

Knowledge check

Loading quiz

Put it into practice

Design full architectures with AI feedback

Apply Real-Time Communication inside real High-Level Design prompts or review Q&A flashcards.

Open AI HLD Practice →SD Interview Q&A
Previous topic
Stream & Batch Processing
Next topic
High Availability & Failover