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

PragTob
Hey everyone, this has been on my mind for some time and I’d love your input on it! TLDR: I feel like maps are superioer for storing and...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
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
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement