WebSockets, SSE & Long Polling
Comparing client-server push patterns for live chat, notifications, and streaming AI tokens at scale
Difficulty: Intermediate · Read time: 8 min · Access: Step-1 Preview + Knoera Pro
How It Works
Standard HTTP (Hypertext Transfer Protocol) is client-initiated request-response—the server cannot push unprompted data. Long Polling holds an HTTP request open until new data arrives, then immediately reconnects. Server-Sent Events (SSE) stream one-way server-to-client updates over a single persistent HTTP stream (`text/event-stream`). WebSockets (`ws://` / `wss://`) upgrade HTTP via `101 Switching Protocols` into a persistent, full-duplex bidirectional Transmission Control Protocol (TCP) socket.
Why It Matters
Picking heavy stateful WebSockets when you only need stock tickers or Large Language Model (LLM) token streaming adds unnecessary sticky-routing complexity; SSE handles one-way pushes natively over HTTP with automatic browser reconnection, while WebSockets shine for low-latency two-way chat and multiplayer collaboration.
Interactive Architecture Scenarios
- WebSocket Bidirectional Frame Push
- Failure Mode: Isolated Nodes & Reconnect Storm