r/programming • • Jun 13 '19

WebSockets vs Long Polling

https://www.ably.io/blog/websockets-vs-long-polling/
581 Upvotes

199 comments sorted by

View all comments

Show parent comments

12

u/GuinnessDraught Jun 13 '19

My experience with SSEs has been that they are just a half-baked and more limited WebSocket. You handle the SSE stream nearly the same way you would a WS, but you don't get the full benefits of a 2-way protocol. I also had a harder time dealing with errors and connection resets with SSEs than I've ever had with WebSockets.

For the future if I need streaming I'd sooner just go full-on WS over SSE I think, unless there was a really specific reason not to. I don't doubt there are valid reasons to do so, but I can't think of one off the top of my head.

10

u/intuxikated Jun 13 '19

Haven't used either, but it seems like the people at TutaNota had the opposite experience, + improved battery life on SSE for their android app: https://f-droid.org/en/2018/09/03/replacing-gcm-in-tutanota.html This is however for an android app, not a browser app (used as google cloud messaging replacement)

10

u/Ravavyr Jun 13 '19

Makes sense. SSE doesn't require the app to do anything. The server pushes to it. Websockets has both client and server "aware" of the other and sending/getting pingbacks, so battery usage is going to be more.

0

u/Ravavyr Jun 13 '19

Makes sense. SSE doesn't require the app to do anything. The server pushes to it. Websockets has both client and server "aware" of the other and sending/getting pingbacks, so battery usage is going to be more.

2

u/sign_on_the_window Jun 14 '19

That is my experience with them. I just end up scrapping it in the end and using web sockets.

1

u/sephg Jun 13 '19

I usually use websockets for my apps, but SSE have the advantage that they can work fine through HTTP2. Amongst other things this makes initial session establishment quite a bit faster