A practical comparison of Server-Sent Events (SSE) and WebSockets, arguing that SSE is the better default for most real-time use cases. Covers how AI chat streaming (like ChatGPT) uses SSE rather than WebSockets, why native EventSource has limitations and fetch-based streams are preferable, authentication patterns (HttpOnly cookies vs bearer tokens), and production gotchas including Nginx buffering, load balancer configuration, framework async requirements, and message delivery guarantees. Recommends starting with SSE and only switching to WebSockets when bidirectional communication, binary data, or extreme concurrency is genuinely needed.

10m read timeFrom neciudan.dev
Post cover image
Table of contents
The default is wrong 🔗“But WebSockets are also native to the browser.” 🔗Ditch native EventSource 🔗Where SSE wins 🔗Where WebSockets win 🔗The auth problem 🔗Shipping SSE in production 🔗Pick the right tool 🔗

Sort: