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