SSE stands for Server-Sent Events. It is a web standard technology that enables a server to push real-time updates to clients over a single, long-lived HTTP connection.
Key Features Link to heading
- Server Push: The server can send messages at any time without the client needing to request them.
- Automatic Reconnection: If the connection drops, the browser automatically reconnects and can resume from the last received event using
last-event-id. - Simple Implementation: Requires minimal code on both client and server sides.
- Built on HTTP: Works well with proxies, firewalls, and existing web infrastructure.
- Event Support: You can send named events, data, IDs, and retry instructions.
- Lightweight: Lower overhead compared to WebSocket for one-way streaming.
Use Cases Link to heading
- Real-time notifications and alerts
- Live dashboards and monitoring systems
- Stock prices, cryptocurrency tickers, or sports scores
- Progress tracking for long-running tasks (file uploads, exports, AI processing)
- News feeds and social media updates
- Live chat applications (for the server-to-client message stream)
Limitations Link to heading
- Unidirectional Only: Data flows only from server to client. For client-to-server communication, you still need Fetch, AJAX, or WebSocket.
- Text-Only: Does not support binary data natively (images, videos, etc.). You must convert them using Base64, which increases payload size.
- Browser Connection Limits: Most browsers limit concurrent SSE connections per domain (typically 6). Too many open streams can cause issues.
- Not Ideal for High-Frequency Bidirectional Apps: For real-time multiplayer games or complex chat systems, WebSocket is usually better.
- Server Timeouts: Some servers and proxies have default connection timeouts. You may need to configure keep-alive settings.
- CORS Considerations: Cross-origin requests require proper server headers.