Skip to content
ADP
API Design PrincipleBETA

[ADP-372] Server-Sent Messages

Overview

In certain scenarios, HTTP applications require the server to provide continuous or real-time information, rather than relying on the traditional request-response model.

Guidance

  • API providers SHOULD choose between WebSocket and Server-Sent Events (SSE) based on specific requirements.
  • Server-Sent Events (SSE) SHOULD be used when there's no need for bidirectional communication or high concurrency.
  • WebSocket SHOULD be used for scenarios requiring high concurrency or full-duplex communication.

Implementation Options

Several methods exist for implementing server-sent messages:

  1. Server-Sent Events (SSE): For unidirectional, real-time data flow from server to client.
  2. WebSocket: For full-duplex, real-time communication between server and client.
  3. Polling: Simple but potentially inefficient method where the client requests data at regular intervals.
  4. Long Polling: Reduces latency compared to regular polling by holding the connection open until new data is available.
  5. HTTP/2 Server Push: Allows servers to proactively send responses to clients before they request them.
  6. GraphQL Subscriptions: Enables real-time updates in GraphQL environments.
  7. Message Queues: Useful for decoupled architectures, leveraging systems like RabbitMQ or Kafka.