Daniel Murillo
Index

Architecture · October 23, 2026 · Daniel Murillo

WebSockets, SSE, and Webhooks: communication beyond REST

Not every app needs a permanent bidirectional channel. When to use WebSockets, SSE, or Webhooks depending on who initiates the event.

Not every application needs a permanent bidirectional connection. The best option depends on who initiates communication, how often events occur, and what guarantees the system needs.

Introduction

REST works very well for requests and responses: the client asks for a resource and the server returns a result. But some applications need live updates, event delivery, or notifications between systems.

WebSockets, Server-Sent Events (SSE), and Webhooks solve related problems, but they are not equivalent. WebSockets keeps a bidirectional channel; SSE lets the server send events to the browser; Webhooks notify another system with an HTTP request when an event occurs.

1. WebSockets: bidirectional communication

WebSockets establishes a persistent connection that lets client and server send messages without starting a new HTTP request for every exchange.

Common cases:

  • Chats.
  • Multiplayer games.
  • Collaborative editing.
  • Interactive notifications.
  • Operational dashboards with frequent changes.

The persistent connection can reduce the overhead of repeated exchanges, but it does not guarantee low latency by itself. The server still has to process messages, query data, and distribute events.

Scalability and backpressure

Thousands of open connections consume resources. A robust architecture must manage connection limits, memory, heartbeats, reconnections, and message distribution across instances.

Backpressure matters when messages are produced faster than the client can process them. Without limits, queues can grow and cause memory pressure and ever-increasing latencies.

Delivery and recovery

WebSockets does not by itself guarantee that the application has message persistence, processing acknowledgment, or recovery of events lost during a disconnection.

If the business needs those guarantees, you must design event identifiers, acknowledgments, storage, resume, and rules to avoid duplicates.

Compression

The permessage-deflate extension can compress messages if client and server negotiate it. It is not always worthwhile: compressing small messages can add unnecessary work, and there are security considerations when mixing sensitive data with attacker-controlled content.

2. SSE: events from server to client

Server-Sent Events lets a server send events to the browser over a persistent HTTP connection.

It is appropriate for:

  • Progress of a long task.
  • Live logs.
  • Server notifications.
  • Status updates.
  • Dashboards that receive data but do not need a constant bidirectional channel.

The client can open an SSE stream and the server send events as they become available. To send commands to the server, the client can use conventional HTTP requests.

SSE is usually simpler than WebSockets when communication is essentially unidirectional. Even so, you must check connection limits, proxy timeouts, buffering, and the reconnection behavior of the infrastructure.

3. Webhooks: notifications between systems

A Webhook is an integration pattern. When an event occurs, one system sends an HTTP request to a URL registered by another system.

For example, a payment provider can notify that a transaction changed state. The receiving system processes the event and updates its domain.

Webhooks do not need a permanent bidirectional connection. The sender initiates a request when it has something to notify.

Designing robust Webhooks

A delivery can fail temporarily or be repeated. That is why it is worth including:

  • Authentication or verifiable signatures.
  • Retries with backoff and limits.
  • Idempotency to process duplicates safely.
  • Event identifiers.
  • Timeouts.
  • Delivery logging.
  • Mechanisms to retry manually.

You should not assume a Webhook is delivered exactly once. The receiver design must tolerate duplicates and delays.

4. Practical comparison

NeedUsual optionWhy
Create, read, update, or delete resourcesRESTSimple request-and-response model
Client and server exchange messages continuouslyWebSocketsBidirectional channel
The server streams updates to the browserSSEUnidirectional HTTP stream
One system notifies an event to anotherWebhooksEvent-based delivery over HTTP
Messaging between IoT devices and servicesMQTT can fitLightweight publish and subscribe

These options can coexist. For example, an application can use REST to query data, SSE to show operation progress, and Webhooks to integrate an external provider.

5. Latency, cache, and state

WebSockets should not be chosen only because it is expected to be faster. If changes happen every few minutes, a periodic HTTP request or SSE can be enough and simpler to operate.

Cache also plays a different role depending on the pattern. In REST, resources can leverage HTTP cache. In SSE and WebSockets, you usually need to manage state and events in the application. Webhooks usually require persistence and retries more than response caching.

6. How to choose

Choose WebSockets if you truly need messages in both directions and frequent events. Choose SSE when the flow goes mainly from server to client. Choose Webhooks when another system must receive a notification without keeping a permanent connection.

Before deciding, consider event frequency, number of connected clients, tolerance for disconnections, need for persistence, security, and operational capacity.

Conclusion

WebSockets, SSE, and Webhooks exist for different needs. They are not universal substitutes for REST and they do not compete exactly with each other either.

The right decision depends on the direction of the flow, the frequency of events, and the guarantees the business needs.

Do not use a permanent connection if you only need an occasional notification; do not use constant polling if an event stream solves the problem more simply.

If the notice must arrive with the app closed or in the background, WebSockets and SSE are not enough: you need an OS or browser push channel. That is another layer.

In this series

  1. REST: how to design and optimize an API
  2. REST vs GraphQL
  3. gRPC vs REST
  4. WebSockets, SSE, and Webhooks (this note)
  5. Cache and compression
  6. Benchmarks and architecture decisions

Related reading

References