0% completed
What are Server-Sent Events?
On This Page
How Server-Sent Events Work
What About Sending Data Back?
Strengths of Server-Sent Events
Weaknesses of Server-Sent Events
Where Server-Sent Events Are Used
Server-Sent Events (SSE) is a technique where the client opens one long-lived HTTP connection, and the server keeps sending updates over it as they happen. Data flows in one direction only: from the server to the client.
Think of a radio broadcast. You tune in once, and the station keeps sending. You hear every update the moment it airs, but you cannot talk back through the radio. SSE is that broadcast, delivered over a normal HTTP connection.
How Server-Sent Events Work
- The client sends a regular HTTP request to a special updates endpoint on the server.
- The server accepts the connection and keeps it open instead of finishing the response.
- Whenever there is news, the server writes a new event (a small chunk of text) into that same open response. The response never really ends; it just keeps growing, one event at a time.
Browsers support SSE natively through an object called EventSource. The client code says "subscribe to this URL," and the browser does the rest. Best of all, if the connection drops, the browser reconnects automatically. You do not have to write that logic yourself.
What About Sending Data Back?
SSE gives the client no way to send data over the event stream. If the client needs to talk to the server, it makes a normal, separate HTTP request.
That sounds like a limitation, and it is. But look at how most applications behave: they mostly read. A news feed, a scoreboard, a price ticker. The user only occasionally sends something, and a plain request handles that fine.
Strengths of Server-Sent Events
- It is plain HTTP. No protocol upgrade and no special server setup. It passes through most infrastructure that already handles HTTP.
- Automatic reconnection. The browser re-establishes a dropped connection on its own, and it can even tell the server the last event it received, so nothing is missed.
- Efficient one-way streaming. One connection carries an endless stream of updates with very little overhead per event.
Weaknesses of Server-Sent Events
- One direction only. Client-to-server messages need separate HTTP requests.
- Text only. Events are plain text. Sending binary data requires encoding it into text first.
- Connection limits in older setups. Over the older HTTP/1.1, browsers allow only a handful of open connections per site. A user with many tabs open can hit that ceiling. Newer HTTP versions largely remove this problem.
Where Server-Sent Events Are Used
SSE fits anywhere updates flow steadily in one direction:
- Live scores and news tickers: the server announces, everyone listens.
- Stock and crypto price feeds: a stream of small text updates.
- Progress updates: a long-running job reporting percent complete.
- AI assistants: chatbots that stream their answer to your screen word by word typically deliver it over SSE.
You have now met all three techniques. In the next lesson, Difference Between Long-Polling, WebSockets, and Server-Sent Events, we will put them side by side and learn how to choose.
On This Page
How Server-Sent Events Work
What About Sending Data Back?
Strengths of Server-Sent Events
Weaknesses of Server-Sent Events
Where Server-Sent Events Are Used