๐Ÿ“ก 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