0Pricing
NestJS Enterprise Backend APIs · Lesson

Server-Sent Events for One-Way Push

Stream live updates to clients with the @Sse decorator and RxJS observables.

Why Server-Sent Events?

Server-Sent Events (SSE) let a server push a continuous stream of updates to a client over a single, long-lived HTTP connection. It is the simplest way to deliver one-way, server-to-client live data such as notifications, progress bars, or dashboard metrics.

  • One-way only: the server talks, the client listens. There is no client-to-server channel on the same connection.
  • Plain HTTP: no special protocol upgrade like WebSockets need. It rides on a normal GET request.
  • Auto-reconnect: the browser's EventSource reconnects automatically if the connection drops.

In NestJS, SSE is a first-class feature exposed through the @Sse() decorator combined with RxJS observables.

SSE vs WebSockets

Both stream live data, but they solve different problems. Choosing the right one is an architectural decision.

  • SSE: server → client only, text-based, runs over HTTP/1.1 or HTTP/2, built-in reconnection and event IDs. Ideal for feeds, alerts, and progress.
  • WebSockets: full-duplex (both directions), binary or text, requires a protocol upgrade. Ideal for chat, multiplayer games, and collaborative editing.

If your clients only need to receive updates, SSE is lighter, easier to scale behind standard HTTP infrastructure, and requires no extra client library. Reach for WebSockets only when the client must also push messages in real time.

All lessons in this course

  1. WebSocket Gateways with the Socket.IO Adapter
  2. Authenticating and Guarding Socket Connections
  3. Server-Sent Events for One-Way Push
  4. Scaling Realtime with a Redis Pub/Sub Adapter
← Back to NestJS Enterprise Backend APIs