Overview
The Server-Sent Events (SSE) endpoint provides an alternative method for real-time notification delivery using HTTP-based server-push technology. This approach is beneficial for clients that cannot maintain WebSocket connections due to proxy limitations or require a simpler implementation.Connection
Endpoint:GET /api/v1/client/events
Authentication: Requires Bearer token using user credentials
Connection Query Parameters
Parameter | Type | Required | Description |
---|---|---|---|
token | string | Yes | User authentication token (alternative to Authorization header) |
last_event_id | string | No | ID of the last received event for reconnection purposes |
types | string | No | Comma-separated list of event types to subscribe to (default: all) |
client_id | string | No | Client identifier for correlation (UUID recommended) |
version | string | No | Protocol version for compatibility (defaults to latest) |
Connection Example
Message Format
SSE messages are formatted according to the EventSource specification with event types and JSON data payloads:Event Types
The following event types are supported:Event Type | Description |
---|---|
notification | New notification available for the user |
status_update | Status change for an existing notification |
error | Error condition related to the connection |
ping | Server heartbeat to maintain connection |
Event Data Formats
Notification Event
Status Update Event
Error Event
Ping Event
Reconnection
One of the key advantages of Server-Sent Events is the built-in reconnection mechanism provided by the browser’s EventSource implementation. When a connection is lost, the browser will automatically attempt to reconnect with exponential backoff. The SSE protocol uses theLast-Event-ID
header for resuming the stream from where it left off. When reconnecting, the client should include the last received event ID to ensure no events are missed:
Custom Reconnection Strategy
For applications that need more control over the reconnection behavior, you can implement a custom strategy:Limitations
- Maximum of 10 concurrent SSE connections per user
- Connection timeout: 120 seconds of inactivity
- Reconnection delay: Controlled by client with server-suggested 3-second initial delay
- Maximum event size: 512KB
Browser Compatibility
Server-Sent Events are supported in all modern browsers:- Chrome 6+
- Firefox 6+
- Safari 5+
- Edge 79+
- Opera 11.5+
Advantages Over WebSockets
While WebSockets provide bidirectional communication, SSE offers several advantages for notification delivery:- Simpler Implementation: No need to handle message framing or connection state
- Automatic Reconnection: Built-in reconnection with message resumption
- Better Proxy Support: Works over standard HTTP, avoiding firewall/proxy issues
- Event Filtering: Subscribe to specific event types
- Less Overhead: Lower connection maintenance overhead for unidirectional communication
Best Practices
- Store Last Event ID: Always persist the last event ID for reliable reconnection
- Handle Backpressure: Process events asynchronously to avoid blocking the event stream
- Implement Timeout Handling: Close and reconnect if no events are received within the expected interval
- Graceful Degradation: Fall back to polling if SSE is not supported or continuously fails
- Connection Monitoring: Track connection state and implement health checks
- Memory Management: Close EventSource when component is unmounted to prevent memory leaks