API Fundamentals Course
API Fundamentals
/
Intermediate

Server-Sent Events (SSE)

Definition

A standard allowing a browser to receive automatic updates (event streams) from a server via an HTTP connection. It is strictly a one-way communication channel (Server to Client).

Explain Like I'm New

WebSockets is a two-way phone call. SSE is a one-way radio broadcast. The client tunes in to the station, and the server continuously streams data to them. The client cannot talk back on that channel.

Real World Example

A live Twitter feed or a live sports score ticker. The user is just watching the data flow in. They don't need to send complex high-speed data back to the server, so a full WebSocket is overkill. SSE handles this perfectly over standard HTTP.

Common Use Cases

  • •Live scoreboards
  • •News feeds
  • •Streaming AI text (ChatGPT)

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • Which is generally easier to set up through corporate firewalls and load balancers: WebSockets or Server-Sent Events?

intermediate

  • If a client needs to send a chat message while listening to an SSE stream, how do they do it?

Flash Cards

Question

Easier to setup?

Click to reveal answer
Answer

Server-Sent Events. Because SSE operates completely over standard HTTP (port 80/443), practically all firewalls and proxies handle it natively. WebSockets use a custom protocol that often requires special proxy configuration.

Question

How to send data?

Click to reveal answer
Answer

They must send a standard, separate HTTP POST request. SSE is strictly one-way (downlink). The POST request goes up, the server processes it, and broadcasts the result back down the SSE stream.