Learning Question

How can a server send data over time without using WebSocket?

HTTP can keep one response body open and continue writing data into it. Server-Sent Events, or SSE, is a standard HTTP-based pattern where the server sends events to the client over a long-lived response.

This is not the same as sending multiple completed HTTP responses for one request.

HTTP Streaming

In HTTP streaming, the server starts a response and keeps the body active.

client sends one request
server sends response headers
server writes body data
server writes more body data
server writes more body data

The response is still one response. The body is produced over time.

SSE

SSE uses HTTP to send server-to-client events.

The client sends an HTTP request. The server keeps the response open and writes event-formatted data over time.

client -> GET /events
 
server -> response stays open
event: message
data: hello
 
event: message
data: later update

SSE is mainly server-to-client. It fits notifications, status updates, logs, and event streams where the client mostly listens.

How This Differs From WebSocket

WebSocket is bidirectional application messaging after an HTTP Upgrade. SSE keeps HTTP semantics and sends events in one long-lived response body.

The comparison is:

SSE
-> HTTP response stays open
-> server sends events to client
 
WebSocket
-> protocol switches after upgrade
-> both sides send WebSocket messages

Operational Limits

Long-lived HTTP responses and WebSocket connections can both be affected by server, proxy, load balancer, or platform timeouts. Keeping a connection open is not only a protocol choice. It is also an operational behavior that infrastructure must allow.

Core Mental Model

Do not collapse all server-to-client updates into WebSocket.

Ask:

Does the server only need to stream events to the client?
Does the client also need to send frequent messages on the same channel?
Can the update be represented as one long HTTP response body?

SSE and HTTP streaming are still HTTP-shaped. WebSocket changes the application protocol after the upgrade.