📡 Web Dev

SSE vs WebSockets vs Polling — Choosing Real-Time Right

📅 Jul 5, 2026 ⏱ 3 min read

WebSockets aren't the only real-time tool — and often not the right one. The full menu:

Server-Sent Events — the underrated middle

// client — built into every browser
const es = new EventSource("/api/notifications");
es.onmessage = (e) => showNotification(JSON.parse(e.data));
// auto-RECONNECTS on drops — WebSockets don't!

// Express server
app.get("/api/notifications", (req, res) => {
  res.setHeader("Content-Type", "text/event-stream");
  res.setHeader("Cache-Control", "no-cache");
  const timer = setInterval(() => {
    res.write(`data: ${JSON.stringify({ time: Date.now() })}

`);
  }, 5000);
  req.on("close", () => clearInterval(timer));
});

The decision table

The interview answer

"One-directional server push → SSE (simpler, auto-reconnect, plain HTTP). Bidirectional → WebSockets. Neither needed → poll." Choosing the boring right tool over the shiny one is exactly what senior engineers listen for.

← All Articles