Take it from someone who has been in the deep muddy water of JavaScript development, both in frontend and backend, Elixir & Phoenix are better duo than anything I came across.
Let me answer each of your question, one by one.
-
I switched form Node.js. I used it along with Socket IO to make presence tracking app and distributed locking.
- The Node.js environment is riddled with memory leak. (The only Node.js program without memory leak is a Hello World program) (Elixir & Phoenix app have per process garbage collection, so memory won’t bloat for entire application)
- It is opaque, i.e. You can’t inspect what’s happening inside in production. (You can with Elixir & Phoenix, you can even terminate a single process that might be causing trouble, without crashing the whole server!)
- It’s not multi threaded, so you have to run multiple instances using PM2 or Docker. (Elixir & Phoenix have that natively)
- Multiple Node.js instances don’t communicate with each other, instead you have to host a separate Redis instance, and use its PubSub mechanism or use some other message queue. (Elixir & Phoenix run on top of BEAM virtual machine, which has those primitives built in!!)
- JavaScript is an unreliable mess, which you will replace with TypeScript anyway, which is just a fake type checker. (With Elixir, you won’t need Type checking whatsoever, because of the first class testing features and type checkers don’t prevent all bugs anyways, just type bugs)
-
a. Major benefits:
- The Phoenix Framework has Live View, which is like next level compared to the terrible Single Page Application. (I can fill a page about how it’s a mind-blowing piece of tech if you want to know)
- Elixir has LiveBooks, where you can learn, make Machine Learning models, even create business intelligence tools, because it can connect directly to all other Elixir Phoenix nodes with ease.
- Elixir has Pipelining, i.e. |>, for better readable and maintainable code.
def on_mount(:only_admin, _params, session, socket) do
{:cont, socket}
|> assign_user(session)
|> verify_user()
|> verify_lock()
|> verify_email()
|> verify_role(~w(super_admin admin)a)
|> subscribe_user()
end
- b. Some other benefits:
- The paradigm for coding is functional, and not OOP, so you won’t drown in the rabbit hole of Design Patterns.
- Elixir has pattern matching, which eases error handling and reduces lines of code we have to write:
def env(atom) when is_atom(atom), do: Application.get_env(:derpy_coder, :environment) == to_string(atom)
def env(str) when is_binary(str), do: Application.get_env(:derpy_coder, :environment) == str
def env(list) when is_list(list), do: Application.get_env(:derpy_coder, :environment) in list
-
Domains:
- The language and the BEAM virtual machine lend themselves to soft real time application really well.
- Better & Modern web applications. See: Phoenix Framework
- Soft Realtime, collaborative applications. See: Phoenix LiveView
- Internet of Things using Nerves project. See: Nerves Project
- Mobile Application. See: Phoenix LiveView Native
- Desktop Application. See: Elixir Desktop
- Artificial Intelligence training and serving. Elixir Nx, Axon
- Here’s a list of Awesome Collections: Awesome Elixir, Awesome Phoenix LiveView
-
Deployment
- It takes up less memory, compared to Java or Node based apps.
- It uses less server resources and just one instance deployed onto a server can utilise all cores of that machine. So you don’t have to use a tool like PM2 to run multiple instances like in case of Nodejs.
- There was a blog post about how a company using Ruby, with 80 servers came down to only 5 after switching to Elixir.
- Discord uses Elixir, and WhatsApp used to use it.
- Current build process can output single binary, so you can deploy it in a old school way like I prefer, or you can Dockerize it to run it inside Kubernetes, or throw the binary at Hashicorp Nomad for orchestrating standalone binaries.
- Separately deployed nodes can communicate with each other, without using ETCD or Redis or Kafka separately, it’s built in.
- With fly .io, you can deploy your server to the edge, as if it’s a CDN, except your code is running closer to the user, and you won’t have to deal with any extra tech layer. See: LiveBeats.
I have been falling down the rabbit hole of Front End frameworks, for what feels like forever. It was like a never ending Distro hopping. Everything that comes out in front end space solves one or the other problem, but leaves out a gaping hole behind them.
For instance, React, solved some problem, but left open the server side rendering. So Next.js came along.
REST api felt unwieldy, so GraphQL came along, now state needs to be maintained in both backend and front end. So you end up with business logic scattered across both places.
Routing story gets bad or has several fragmented implementation. State management remains a mess.
Then someone from business comes along and asks you to make some of it real time, and now you are caught in the JavaScript web hell.
The 2 ton heavy npm package gets replaced by pnpm, which breaks everything. You can’t reliably run a Node.js project after a hiatus.
Webpack bundler keeps getting slower, so you move to something else, which has some other headache of its own.
Believe me when I say, you are saving yourself a ton of headache and sparing yourself from paying technical debt by moving to Elixir/Phoenix.
It saved me from yak shaving me life away.
See the following talks to get a visual explanation of all the things I pointed out:
P.S. I would have put a lot more links, but new users are not allowed to add more than 5 links. (I started learning Elixir & Phoenix 3 or 4 months back and joined the forum today
)