QA
Beginner LevelSystem Design & Architecture

Compare Polling vs Long Polling vs WebSockets vs Server-Sent Events (SSE) for real-time UIs.

❓ Interview Prompt: Compare real-time communication protocols: Short Polling, Long Polling, WebSockets (full-duplex TCP), and Server-Sent Events (SSE HTTP streaming).

Evaluating real-time client-server communication technologies:

| Technology | Direction | Protocol | Ideal Use Case |

|---|---|---|---|

| Short Polling | Client $\rightarrow$ Server | HTTP | Low-frequency periodic updates |

| Long Polling | Client $\leftrightarrow$ Server | HTTP (Kept open) | Legacy push updates without WebSocket support |

| WebSockets | Bi-directional (Full-Duplex) | TCP ('ws://' / 'wss://') | Real-time chat, multiplayer gaming, collaborative editing |

| Server-Sent Events (SSE) | Server $\rightarrow$ Client (Uni-directional) | HTTP ('text/event-stream') | Live stock tickers, news feeds, LLM token streaming |

Code Implementation Example

javascript
// Client-side Server-Sent Events (SSE) listener
const eventSource = new EventSource('/api/v1/live-stock-stream');
eventSource.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Real-time price update:', data);
};
πŸ’‘Streaming real-time server events using Server-Sent Events (SSE).
🎯 Interview Key Takeaway

Use WebSockets for bi-directional real-time communication (chat), and SSE for uni-directional server streaming (stock tickers, LLMs).

#System Design#WebSockets#SSE#Real-Time#Beginner
Back to all System Design & Architecture Questions→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?