almessadi.
Back to Index

SSE Is Often the Better Fit for One-Way Realtime Streams_

If the browser mostly listens and rarely talks back, Server-Sent Events can provide a simpler and more HTTP-friendly option than WebSockets.

PublishedDecember 8, 2024
Reading Time9 min read

WebSockets are powerful because they support two-way communication. That is also why they are often overkill. A lot of products do not need a full duplex channel. They need a browser to stay connected and receive updates.

For notifications, dashboards, job progress, and activity feeds, Server-Sent Events are often the cleaner choice.

Why SSE Ages Well

SSE stays simple because it keeps the transport model narrow:

  • standard HTTP request
  • native browser EventSource
  • server-to-client streaming only
  • easy integration with proxies and existing auth patterns

A minimal server endpoint looks like this:

app.get("/events", (req, res) => {
  res.writeHead(200, {
    "Content-Type": "text/event-stream",
    "Cache-Control": "no-cache",
    Connection: "keep-alive",
  });

  res.write(`event: ready\n`);
  res.write(`data: ${JSON.stringify({ status: "ok" })}\n\n`);
});

And the client side is equally small:

const source = new EventSource("/events");

source.addEventListener("ready", (event) => {
  console.log(JSON.parse(event.data));
});

When WebSockets Still Win

WebSockets are still the better tool when the browser and server both need to speak frequently:

  • multiplayer interactions
  • collaborative editing
  • bidirectional command channels
  • high-frequency client events

The mistake is choosing WebSockets because "realtime" sounds like it requires them.

Better Rule

If the browser mostly listens, start with SSE. Move to WebSockets only when bidirectional communication is a real product requirement, not just an architectural reflex.

Further Reading