fullofcaffeine

fullofcaffeine

Using Elixir/Phoenix as a super-charged "process manager"+framework around nodejs processes

Hi all! :waving_hand:

Having spent years in the Ruby and Rails ecosystem before transitioning to full-stack JS and PHP, I’ve always been fascinated by the versatility and productivity of these languages. JavaScript, with its expansive ecosystem and React, has been enjoyable and productive, albeit occasionally overwhelming with its abundance of options.

My interest in Rails was reignited by its recent updates, beautifully captured in this article by DHH: The One-Person Framework. The simplicity and power of Rails are truly compelling, yet the allure of Elixir’s concurrency model and optimized runtime have caught my eye, with the promise of sidesteping potential scaling challenges down the road.

While the JS/TS community offers similar promises, the culture and analysis paralysis can be daunting at times.

As I’m exploring Elixir, I can’t help but wonder about leveraging it beyond its typical use, akin to a super-charged “process manager.” Imagine using Elixir not just for backend functionalities like authentication and background jobs but also for overseeing Node.js processes that handle SSR for React views, supplemented by an Elixir-powered API for client-side hydration.

In theory, based on what I’ve read so far about BEAM/Elixir, this setup could offer incredible flexibility, allowing for selective delegation between Node.js and Elixir based on specific route requirements, potentially optimizing performance and scalability across the board.

Has anyone ventured down this path? Could Elixir effectively replace PM2 while boosting performance, scalability, and stability (and developer productivity)? I’m keen to hear your experiences or any insights you might have!

Thanks in advance!

First Post!

kwando

kwando

Usually people around here want less JavaScript, not more. :upside_down_face:

The problem is not PM2 it is just a symptom of nodejs/javacript not really being made for serverside work. You have to do all sorts of crazy and complicated things as a consequence of that.

You can certainly build what you are suggesting, but I don’t think it is where Elixir/BEAM shines.

Most Liked

hubertlepicki

hubertlepicki

I would love a Phoenix-powered React Server Components implementation, which would also be “live” as in LiveViews-live.

I experimented with something like that, by putting a Next.js server behind a Phoenix reverse-proxy. So basically a web request hits Phoenix, I use Ecto to load up the data, then use POST to send that data to Next.js handler, and stream the Next.js-generated response back to the client browser connected to Phoenix. This works and is pretty simple, in fact I was surprised how simple it is. But this is still running a Next.js server with all it’s bugs and issues it has, eventually I decided against actually pushing this forward in any way.

There’s a tiny library which I was going to try, but never did, that integrates LiveView with React: GitHub - fidr/phoenix_live_react: Render React.js components in Phoenix LiveView views · GitHub

As far as I understand, it doesn’t have any server-side rendering of React components, but you can somewhat build React Server Components-like behavior but also somewhat better with it using LiveViews.

The comopnents you mount this way will receive updated props from LiveView when it updates, and can send back events to LiveView.

What would be super cool is that these components could be pre-rendered, possibly using Bun or Node or some other JavaScript implementation and then hydrated. I believe that’s doable with something like you are suggesting.

namxam

namxam

I guess there are quite a few people around here using it in a similar way.

In our case, we use elixir / phoenix to provide a websocket based api for machines, as well as a basic web based UI for various native apps on a RaspberryPi. As long as you can control another process via a proper API, elixirs supervision trees are pretty awesome to manage and control all those dependencies.

hubertlepicki

hubertlepicki

Also, note that the LIveView state management and change tracking differs significantly in in principles from what React is doing. There are reasons for that, obviously, as avoiding re-rendering everything is somewhat more imporatant when the code sits on the server.

But another thing to try, would be to build something LiveView-like that is, however, using more React-style state management, for conceptual consistency if nothing else. Even if the code would be written in Elixir instead of JavaScript, having similar concepts of Hooks (as in useState) rather than implicit change tracking would be helpful and reduce the learning curve a lot.

Anyway, a lot of ideas, very little time to try them out.

Last Post!

gregvaughn

gregvaughn

Firstly, yes Elixir is capable of what you wish. I’m not sure if it’s still true, but Heroku used (still does?) Erlang’s supervision feature to manage its dynos. All those features are available in Elixir too.

This brings to mind an interesting perspective on skill level. In order to build what you want, one would develop considerable Elixir skills, perhaps even to the point of losing interest in their React skills. That sort of “catch 22” could be why no one has done it yet :person_shrugging:

Where Next?

Popular in Discussions Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
AstonJ
If so I (and hopefully others!) might have some tips for you :slight_smile: But first, please say which area you’re finding most challen...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New

We're in Beta

About us Mission Statement