ahmadferdous

ahmadferdous

Scalability and fault-tolerance - Elixir vs Java

Hi folks,

I’m an Elixir newbie trying to understand how Elixir (Phoenix) compares with Java in terms of scalability and fault-tolerance for a typical web application backend (business logic + DB).

Scalability:
Phoenix spawns a new lightweight BEAM process when it receives a new request. Because it uses lightweight process, it can spawn a high number of process to handle a lot of requests. Once we hit the scalability limit with a single machine, we add more machines to scale horizontally.
Java also has lightweight threads and by adding more machines, we can scale horizontally. Then what additional advantages does Elixir (Phoenix) have over Java?

Fault tolerance:
Elixir uses supervisor to monitor the child processes. If a child process crashes, supervisor will restart it.
Java has exception handling to catch errors gracefully. The Java app can be restarted with operational support in place.
How is Elixir (Phoenix) superior to Java in terms of fault tolerance?

Please help me understand Elixir and Phoenix better. Thanks.

Most Liked

dominicletz

dominicletz

Creator of Elixir Desktop

Having worked with a big Java System (Cassandra) for many years I think there are pretty strong advantages on the Elixir/BEAM side of things. Especially for WevServices for which you want to ensure they always stay up:

Scalability:
1 Memory & GC)
Behind BEAM lightweight process model is also a superior scaling memory model. With BEAM you can easily scale to multigigabyte RAM machines and never have any garbage collection freezes. Now with Java on the other hand you will find yourself dealing with global garbage collection freezes at scale. If you scale your service and suddenly you get 1, 10 or even 100 second pauses you know you’ve got a problem. https://stackoverflow.com/questions/21992943/persistent-gc-issues-with-cassandra-long-app-pauses#22002767

For me I decided at some point that I’ve spent enough hours if my life dealing with Java gc pauses to leave that tech behind for good. Also don’t fall for their marketing Java every release claims that their garbage collector has been getting so much better, but the problem is that the concept of one large memory heap is just not scaling. The memory per process of beam just scales perfectly in comparison.

2 Team size)
Expect to scale a larger team with Java. Your code size will grow quicker factor 3x or more mostly because of boilerplate and types. Don’t underestimate the impact of this, development progress will be much slower over time with Java.

3 Ops)
I can’t put into word how much time I’ve saved debugging Elixir services because of the remote shell. In Java land you’ve got JMX and JConsole, but they can’t compete at all with the power of IEx and Observer. Being able to not only inspect all running GenServers, Supervisors, etc. but also to send them commands gives you superpowers and will allow you to manage much larger deployments much quicker. Try to hunt down the infamous null pointer exception in a running deployed Java application and then compare that to the ease of doing the same in Elixir.

Fault Tolerance:
This is a clear win for Elixir, partly because of the system and partly because of the architecture it enforces. Having each request in a worker means that when one worker crashes, everything it used is cleabed up and more importantly all other workers are unaffected.
Java more like C though have the problem that an unexpected error will lead to an unknown state of the whole system. This can range from just crashing the whole system to doing really bad things to all non-crashed components. Before you’ve found all the edge cases that need to be properly handled in a Java app you will turn gray. In Elixir on the other side, “letting it crash” is often totally reasonable and doesn’t affect your uptime. More importantly though this is the default - without any extra work. In Java the default is a burning desaster until you’ve added so many exception handlers that the normal code flow becomes hard to read. At the end of the day I’ve seen Java application to crash much more frequently than Elixir apps. Let it crash - fault tolerance in Elixir/OTP - Speaker Deck

To mention here I think are also live upgrades even if they’re relatively niche. With Elixir you can build systems the never fail. Tcp connections that are keept open for months even over software updates. The way you can upgrade statefull Elixir processes through OTP releases is unique. And if you really need fault tolerance to that level Elixir is probably your only option.

Best

11
Post #2

Where Next?

Popular in Discussions Top

pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
mmmrrr
Just saw that dhh announced https://hotwire.dev/ Is it just me or is this essentially live view? :smiley: Although I like the “iFrame-e...
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
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
WolfDan
After doing a port from a c++ library to my project in phoenix I’ve seen that I need a faster way to run this algorithm and I found this ...
New
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
Crowdhailer
I’ve been hearing much about the new formatter and it’s something I have been keen to try. I find examples buy far the most illuminating...
248 19204 150
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
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
jsonify
So, is Heroku the only free option for hosting Phoenix/Elixir at this point? I’m not ready to commit to paying monthly and was wondering ...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement