5 ms·
I feel like websockets get waaay too much hype and attention compared to SSE, especially for use cases that are barely interactive at all.
by iomcr 6y ago
I feel like websockets get waaay too much hype and attention compared to SSE, especially for use cases that are barely interactive at all.
- viklove 6y agoFuture-proofing is a good use case though. As a developer I don't want to maintain both SSE and WebSockets, since they solve similar problems and WebSockets are a superset of SSE. Even though my WebSockets implementation is currently unidirectional (server to client), I still opted for that over SSE because I'll probably need send data the other way at some point in the future. Why learn two tools when I can just learn one?
- anderspitman 6y agoWhat's wrong with normal HTTP requests for client->server streams? You get the added bonus of being able to dump them to a curl command for debugging.
- viklove 6y agoMore overhead, and it doesn't scale. My nodejs websockets server can handle thousands of connections without a problem, but my rails api server allocates a thread per connection so I'm limited to <16 unless I start horizontal scaling. For infrequent requests everything goes through the api, but for stuff like chat and live-document-editing, nodejs is the better solution.
- anderspitman 6y agoI think I missed something. Why can't you use node for SSE?
- viklove 6y agoI can, but why would I limit myself to one-way communication when I can have bidirectional communication?
- anderspitman 6y agoYou didn't cite bidi as your reason for choosing WS in your last comment, you cited scaling and node vs ruby. But to answer this new question: * You can have bidi without WS. * Because WS is more complicated.
- viklove 6y ago> You didn't cite bidi as your reason for choosing WS in your last comment, you cited scaling and node vs ruby. Because I was answering this question: "What's wrong with normal HTTP requests for client->server streams?" > You can have bidi without WS. Only by combining HTTP (which doesn't scale because my api server runs rails) and SSE (which does scale). If I want scaling bidirectional communication, I need websockets. > Because WS is more complicated. More complicated than SSE? I don't think so.
- cyral 6y agoIf you use nginx, you can use the excellent nchan module to push messages by having your backend make a POST request to nginx. Clients can connect to nchan via websockets, SSE, and few other things like long polling without your app having to support all of them. Been using it for a recent project and really like it.
- anderspitman 6y agoSadly it's not entirely unfounded. SSE on HTTP/1.1 is basically useless due to the connections-per-domain limits implemented in browsers. So WebSockets got a lot of mindshare while we waited for HTTP/2. But today I always start with plain HTTP, then try SSE, and finally WebSockets if I have to.