News for hackers. Stuff that matters.
Re:Back to basics: Why we chose long-polling over websockets by ipnon on Sunday January 05, 2025 @07:58AM (#42601467)
Articles like this make me happy to use Phoenix and LiveView every day. My app uses WebSockets and I don’t think about them at all.
Re:Back to basics: Why we chose long-polling over websockets by leansensei on Sunday January 05, 2025 @08:19AM (#42601552)
Same here. It truly is a godsend.
Re:Back to basics: Why we chose long-polling over websockets by zacksiri on Sunday January 05, 2025 @08:43AM (#42601696)
I was thinking this exact thing as I was reading the article.
Re:Back to basics: Why we chose long-polling over websockets by tzumby on Sunday January 05, 2025 @08:58AM (#42601771)
I came here to say exactly this! Elixir and OTP (and by extension LiveView) are such a good match for the problem described in the post.
Re:Back to basics: Why we chose long-polling over websockets by j45 on Sunday January 05, 2025 @03:50PM (#42604918)
I was kind of wondering how something hadn't solve this at all, compared to a solution not readily being on one's path.
Re:Back to basics: Why we chose long-polling over websockets by cultofmetatron on Sunday January 05, 2025 @10:03AM (#42602188)
hah seriously. my app uses web sockets extensively but since we are also using Phoenix, its never been source of conflict in development. it really was just drop it and scale to thousands of users.
Re:Back to basics: Why we chose long-polling over websockets by arrty88 on Sunday January 05, 2025 @12:09PM (#42603173)
Why couldn’t nodejs with uWS library or golang + gorilla handle 10s of thousands of connections?
Re:Back to basics: Why we chose long-polling over websockets by apitman on Sunday January 05, 2025 @01:05PM (#42603607)
I think GP's point is that they feel Phoenix is simpler to use than alternatives, not necessarily that it scales better.
Re:Back to basics: Why we chose long-polling over websockets by cultofmetatron on Monday January 06, 2025 @02:13AM (#42608451)
to clarify, it does scale better out of the box. a clustered websocket setup where reconnections can go to a different machine and resume state works our of the box. its a LOT of work do do that in nodejs. I've done both.
Re:Back to basics: Why we chose long-polling over websockets by dugmartin on Sunday January 05, 2025 @10:45AM (#42602514)
The icing on the cake is that you can also enable Phoenix channels to fallback to longpolling in your endpoint config. The generator sets it to false by default.
Re:Back to basics: Why we chose long-polling over websockets by pipes on Sunday January 05, 2025 @12:05PM (#42603144)
Is this similar to Microsoft's blazer?
Re:Back to basics: Why we chose long-polling over websockets by pipes on Sunday January 05, 2025 @01:01PM (#42603571)
Odd, I wonder why I got down voted for it, it was a genuine question
Re:Back to basics: Why we chose long-polling over websockets by NicoJuicy on Sunday January 05, 2025 @02:48PM (#42604440)
Blazor? Raw guess
Re:Back to basics: Why we chose long-polling over websockets by mattmanser on Sunday January 05, 2025 @05:58PM (#42605792)
MS's web socket solution is called signalr.

It is also fire and forget with fall over to http if web sockets aren't available. I believe if web sockets don't work it can fall over to http long polling instead, but don't quote me on that.

All the downsides of web sockets mentioned in the article are handled for you. Plus you can re-use your existing auth solution. Easily plug logging stuff in, etc. etc. Literally all the problems mentioned by the author are dealt with.

Given the author mentions C# is part of their stack I don't know why they didn't mention signalr or use that instead of rolling their own solution.

Re:Back to basics: Why we chose long-polling over websockets by hikarikuen on Sunday January 05, 2025 @09:06PM (#42606839)
To further clarify, I believe Blazor uses SignalR under-the-hood when doing server-side rendering. So the direct answer is probably "this is similar to a component used in Blazor"

Edit: Whoops, I lost context here. Phoenix LiveView as a whole is probably pretty analogous to Blazor.

Re:Back to basics: Why we chose long-polling over websockets by whoknowsidont on Sunday January 05, 2025 @09:06PM (#42606843)
>Given the author mentions C# is part of their stack I don't know why they didn't mention signalr or use that instead of rolling their own solution.

Not saying this is why but SignalR is notoriously buggy. I've never seen a real production instance that didn't have issues. I say that as someone who probably did one of the first real world, large scale roll outs of SignalR about a decade ago.

Re:Back to basics: Why we chose long-polling over websockets by rswskg on Monday January 06, 2025 @09:29AM (#42610810)
I believe it's changed alot since then? I was abit cynical of it from that initial experience but recent usage of it made it seem reliable and scalable.
Re:Back to basics: Why we chose long-polling over websockets by davidgl on Friday January 17, 2025 @11:02AM (#42739205)
We use it in a production system on the aspnetcore stack, and it's been bulletproof for a number of years.

We have lots of proxies in the way, and old tech on certain networks, and at this moment we are 97% websockets, 2% server side events, 1% long polling, and it's all transparent to me, brilliant.

Re:Back to basics: Why we chose long-polling over websockets by avgDev on Monday January 06, 2025 @11:06AM (#42611711)
You are correct.

I am using Blazor Server, and for some reason a server is not allowing Web Socket connections(troubleshooting this) and the app switches to long polling as fallback.

Re:Back to basics: Why we chose long-polling over websockets by abrookewood on Sunday January 05, 2025 @09:20PM (#42606940)
Phoenix predates Blazer, but they are both server-side rendered frameworks.

In terms of real time updates, Phoenix typically relies on LiveView, which uses web sockets and falls back to long-polling if necessary. I think SignalR is the closest equivalent in the .Net world.

Re:Back to basics: Why we chose long-polling over websockets by jtchang on Sunday January 05, 2025 @01:16PM (#42603710)
This is using elixir right?
Re:Back to basics: Why we chose long-polling over websockets by abrookewood on Sunday January 05, 2025 @09:21PM (#42606946)
Yes.
Re:Back to basics: Why we chose long-polling over websockets by diggan on Sunday January 05, 2025 @02:36PM (#42604362)
Articles like this make me happy to use Microsoft FrontPage and cPanel, I don't think about HTTP or WebSockets at all.
Re:Back to basics: Why we chose long-polling over websockets by wutwutwat on Sunday January 05, 2025 @04:07PM (#42605047)
every websocket setup is painless when running on a single server or handling very few connections...

I was on the platform/devops/man w/ many hats team for an elixir shop running Phoenix in k8s. WS get complicated even in elxir when you have 2+ app instances behind a round robin load balancer. You now need to share broadcasts between app servers. Here's a situation you have to solve for w/ any app at scale regardless of language

app server #1 needs to send a publish/broadcast message out to a user, but the user who needs that message isn't connected to app server #1 that generated the message, that user is currently connected to app server #2.

How do you get a message from one app server to the other one which has the user's ws connection?

A bad option is sticky connections. User #1 always connects to server #1. Server #1 only does work for users connected to it directly. Why is this bad? Hot spots. Overloaded servers. Underutilized servers. Scaling complications. Forecasting problems. Goes against the whole concept of horizontal scaling and load balancing. It doesn't handle side-effect messages, ie user #1000 takes some action which needs to broadcast a message to user #1 which is connected to who knows where.

The better option: You need to broadcast to a shared broker. Something all app servers share a connection to so they can themselves subscribe to messages they should handle, and then pass it to the user's ws connection. This is a message broker. postgres can be that broker, just look at oban for real world proof. Throw in pg's listen/notify and you're off to the races. But that's heavy from a resources per db conn perspective so lets avoid the acid db for this then. Ok. Redis is a good option, or since this is elixir land, use the built in distributed erlang stuff. But, we're not running raw elixir releases on linux, we're running inside of containers, on top of k8s. The whole distributed erlang concept goes to shit once the erlang procs are isoltated from each other and not in their perfect golilocks getting started readme world. So ok, in containers in k8s, so each app server needs to know about all the other app servers running, so how do you do that? Hmm, service discovery! Ok, well, k8s has service discovery already, so how do I tell the erlang vm about the other nodes that I got from k8s etcd? Ah, a hex package cool. lib_cluster to the rescue https://github.com/bitwalker/libcluster

So we'll now tie the boot process of our entire app to fetching the other app server pod ips from k8s service discovery, then get a ring of distrubuted erlang nodes talking to each other, sharing message passing between them, this way no matter which server the lb routes the user to, a broadcast from any one of them will be seen by all of them, and the one who holds the ws connection will then forward it down the ws to the user.

So now there's a non trivial amount of complexity and risk that was added here. More to reason about when debugging. More to consider when working on features. More to understand when scaling, deploying, etc. More things to potentially take the service down or cause it not to boot. More things to have race conditions, etc.

Nothing is ever so easy you don't have to think about it.

Re:Back to basics: Why we chose long-polling over websockets by Muromec on Sunday January 05, 2025 @06:01PM (#42605812)
If only there was a way to send messages from one host to another in elixir
Re:Back to basics: Why we chose long-polling over websockets by wutwutwat on Sunday January 05, 2025 @06:42PM (#42606057)
Did you even read my comment? I literally talk about how to do that, in multiple different ways.
Re:Back to basics: Why we chose long-polling over websockets by abrookewood on Sunday January 05, 2025 @09:24PM (#42606971)
Were the servers part of an Elixir cluster? Because that functionality should be transparent. It sounds to me like you had them set up as two independent nodes that were not aware of each other.
Re:Back to basics: Why we chose long-polling over websockets by conradfr on Sunday January 05, 2025 @06:25PM (#42605955)
Did you try the Redis adapter that ships with Phoenix.PubSub (which Channels use)?
Re:Back to basics: Why we chose long-polling over websockets by wutwutwat on Sunday January 05, 2025 @06:42PM (#42606055)
Yes, and I mentioned redis above. You need a message broker with 2+ servers, be it pg, redis, or distributed erlang. It's still more complex than a single server setup, which was my point. It's easy to say you don't have to think about things working when you have 1 server, it's not easy to say that past 1 server, because the complexity added changes that picture.
Re:Back to basics: Why we chose long-polling over websockets by davydog187 on Sunday January 05, 2025 @09:19PM (#42606936)
Ok but in literally any other language you minimally need this setup to do PubSub.

Elixir gives more options and lets you do it natively.

Also, there are simpler options for clustering out there like https://github.com/phoenixframework/dns_cluster (Disclaimer: I am a contributor)

Re:Back to basics: Why we chose long-polling over websockets by conradfr on Monday January 06, 2025 @05:52AM (#42609509)
Ok it was not clear if you used Redis directly with some custom code or the integrated stuff.

Anyway I agree that once you go with more than one server it's a whole new world but not sure if it's easier in any other language.