1. What It Is
HTTP was designed around a request/response model: the client asks, the server answers, connection closes (or is kept alive for reuse). This doesn't work well for real-time use cases where the server needs to push data to the client without waiting for a request.
Two standard mechanisms solve this:
WebSockets: a full-duplex, persistent connection between client and server. After an HTTP handshake, the protocol upgrades to WebSocket — either side can send messages at any time. Works over a single TCP connection.
Server-Sent Events (SSE): a one-way, server-to-client stream. The server holds an HTTP connection open and pushes events as plain text. The client uses the browser's EventSource API to consume them.
Why it matters: real-time features (chat, live feeds, notifications, collaborative editing, dashboards) are common in modern web apps. Choosing the right protocol — or knowing why polling still makes sense sometimes — is a practical engineering decision.
In the full tutorial
- 2. How It Works in Practice
- 3. Common Real-World Usage
- 4. Trade-offs and Common Mistakes
- 5. Interview Angle
- 6. Practical Examples