r/programming • • Oct 10 '26

Stop reaching for WebSockets by default: WebSockets vs SSE vs Long Polling

https://medium.com/@anirbansingha20/websockets-vs-long-polling-vs-server-sent-events-fa9bc1644cb8

Real time communication isn't one size fits all. A common mistake in system design is picking WebSockets when all you really needed was server-to-client streaming.

I wrote a short 3 minute architectural comparison of the trade offs here:https://medium.com/@anirbansingha20/websockets-vs-long-polling-vs-server-sent-events-fa9bc1644cb8

What do you usually reach for first when building real time features ?

228 Upvotes

92 comments sorted by

View all comments

Show parent comment

1

u/feldim2425 Oct 12 '26 edited Oct 12 '26

Which is why I mentioned cookies. (Which the original commenter also mentioned)

If you where to put auth data in the body of a request you'd pretty much end up with the same issues which is why headers are a better option but IMO if you are already using headers cookies would be better (since it doesn't even require you to have access to the token in Javascript).

If you really have a auth system that may not work purely with HTTP builtin functionality (Webauthn, DPoP etc.) this might change but usually that creates a short time token that you could use as a auth cookie for making the connections which should work with SSE, REST, WebSockets alike.

PS: I should note that I don't disagree that saying "SSE doesn't support auth headers" is not a great argument when WebSockets don't as well.