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 #1

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
rower687
Hi all, I’ve been reading a lot about the “let it crash” term and how supervising processes and the whole messaging passing make an elixi...
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
PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New
Fl4m3Ph03n1x
Background This question comes mainly from my ignorance. Today is Black Friday, one of my favorite days of the year to buy books. One boo...
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New

Other popular topics Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
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
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
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement