With the explosion of generative AI streaming interfaces and real-time collaborative applications, choosing the correct client-server communication channel is a vital system design decision.
While WebSockets provided the standard for full-duplex communication for years, HTTP/3 Server-Sent Events (SSE) provide auto-reconnection, multiplexing, and simple proxy traversal for unidirectional streaming.
Table of Contents
1. Protocol Architectural Differences
WebSockets upgrade an HTTP connection to a full-duplex TCP/TLS socket connection where both client and server can transmit binary and text frames freely. Server-Sent Events (SSE) utilize a standard persistent HTTP connection where the server pushes UTF-8 text streams (`text/event-stream`) to the browser client.
2. Why SSE Over HTTP/3 Wins for Streaming
For LLM chat responses or live data dashboards, data flow is 99% unidirectional (server to client). SSE running over HTTP/3 provides native browser auto-reconnection, built-in event IDs for gap recovery, and multiplexing across a single QUIC connection without head-of-line blocking.
3. Implementing SSE Native Reconnection
Here is a lightweight EventSource implementation in JavaScript with structured JSON event parsing:
const eventSource = new EventSource('/api/v1/stream-metrics');
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received real-time update:', data);
};
eventSource.onerror = (err) => {
console.error('SSE Connection error:', err);
// EventSource automatically attempts reconnection per server retry header
};
Frequently Asked Questions
Can Server-Sent Events (SSE) send binary data like images or audio?
SSE streams are UTF-8 encoded text streams. To send binary data over SSE, encode the binary payload into Base64 or use WebSockets/WebTransport instead for raw binary framing.
How many concurrent SSE connections can a browser open to the same host?
Over HTTP/1.1, browsers limit concurrent connections to 6 per domain. However, over HTTP/2 or HTTP/3, SSE connections are multiplexed over a single TCP/QUIC stream, removing this bottleneck.