What is server-sent events vs WebSockets for performance?

Answer

Server-Sent Events (SSE) and WebSockets serve different real-time communication patterns with different performance characteristics. SSE: unidirectional — server pushes to client only. Uses standard HTTP/1.1 or HTTP/2. Automatic reconnection built in. Works through proxies and firewalls. Browser sends Accept: text/event-stream; server streams data: ...\n\n text. Client: const es = new EventSource("/updates"). Performance: lightweight protocol, no extra handshake beyond HTTP. With HTTP/2, multiple SSE streams share one connection. WebSockets: bidirectional — both client and server can send. Requires protocol upgrade (ws:// or wss://). More complex proxy handling. Performance: lower overhead per message than HTTP requests, but the persistent connection consumes server resources. Choose SSE when: server pushes data (live feeds, notifications, progress), client doesn't need to send frequent messages, you want simple HTTP semantics. Choose WebSockets when: bidirectional communication (chat, multiplayer games, collaborative editing), low-latency required for client→server messages. SSE on HTTP/2 scales efficiently — each additional stream reuses existing multiplexed connections.