Real-Time Transport Protocols:
1. WebSockets:
- Protocol: Full-duplex, bidirectional communication over a single persistent TCP connection, upgraded from an initial HTTP handshake (ws:// or wss://).
- Overhead: Minimal framing overhead (2-10 bytes per frame) after handshake; eliminates repeated HTTP headers.
- Best For: High-frequency bidirectional data exchanges: collaborative document editing, multiplayer gaming, financial trading terminals.
2. Server-Sent Events (SSE):
- Protocol: Unidirectional (server-to-client) streaming over standard HTTP (Content-Type: text/event-stream).
- Features: Built-in browser reconnection, event IDs, and custom event names over standard HTTP/2 multiplexing. Bypasses corporate firewall/proxy restrictions that block WebSockets.
- Best For: Real-time feeds where clients only consume updates: live sports scores, stock price tickers, AI streaming completions.
3. HTTP Long Polling:
- Protocol: Client opens an HTTP request that the server holds open until data arrives or times out, immediately re-requesting upon reply.
- Overhead: High latency and redundant HTTP header overhead on every message.
- Best For: Legacy fallback environments where WebSockets or SSE are blocked.