January 28, 2022
Over the past couple of years, we wrote extensively about Ruby (and Ruby on Rails), so you know we like it a lot.
We’ve also dabbled some in Elixir (and Phoenix), but never before have we compared the two side by side to see which one can be a better fit for you and when. So here it goes.
Ruby and Ruby on Rails probably need no introduction. They are both widely used tools for writing web applications.
Ruby on Rails lets developers write applications fast with the use of many gems—libraries with features. In the hands of experienced developers, RoR is an excellent Web development framework for building highly functional, usable, and robust Web apps.
RoR changed the landscape of web app development. By introducing tools that facilitate fast app development and focusing on the pleasurable aspect of coding, it set the direction for other Web frameworks that soon followed.
Ruby and Elixir share many similarities. Elixir’s creator, José Valim, was a Rails core team member. He appreciated Ruby’s flexibility and clean and elegant syntax, but the more he worked with Ruby, the more room for improvement he began to notice. His main concern revolved around Ruby’s code limits in concurrency and throughput. It became clear to José what he needed to do—take what was best in Ruby and build something entirely different on top of it. Based on the Erlang VM to solve concurrency limitations, Elixir was conceived.
As for Phoenix, a web framework for Elixir, it was put together by Chris McCord. Having come from the same Rails background as José, Chris borrowed essential ingredients from Rails for his Phoenix project to create a framework that would ultimately outperform Rails.
Below is a short table comparing Ruby, Elixir, RoR, and Python.
|Ruby||Elixir||Ruby on Rails||Phoenix|
|Who||Yukihiro Matsumoto||José Valim||David Heinemeier Hansson||Chris McCord|
|Object-oriented programming language||Functional programming language||Server-side web application framework||Web application framework|
|Why||Developer happiness||Concurrent language||Rapid application development||Simplicity and joy in writing modern web applications with functional ideas
With the basics out of the way, let’s see what each of the two programming languages has to offer, throwing in a little additional detail on their respective most popular frameworks.
As already mentioned, Elixir runs on the Erlang virtual machine (BEAM). Not only is this invention the oldest VM in the history of IT, but it's also very much still in use. With its roots in telecom, Erlang VM BEAM fits perfectly where there’s a need to build and manage systems with multiple simultaneous connections.
Thanks to Erlang, widely adopted by the telecom - an industry where it's used to manage simultaneous connections - Elixir supports code concurrency. Elixir lets you run concurrent connections on a single computer as well as multiple machines.
It’s a great speed boost: with Elixir, you can use every core on a single server, and if you need more resources to meet the traffic demand, you can use every core on all your available servers.
In Elixir, pieces of the code are executed as processes. At the heart of Elixir’s concurrency capabilities, each process is lightweight, using very little memory and CPU power. You can have hundreds of thousands of these processes running at the same time.
Also, thanks to processes, Elixir is great for developing distributed, fault-tolerant systems.
Suppose a system or an application is expected to sustain plenty of traffic in the future. In that case, Elixir’s ability to get the most out of a single machine is an undisputed benefit. With Elixir, there’s no need to add more servers to the app's architecture to accommodate the bandwidth demand that a growing number of users generates.
Elixir has clear syntax, patterns, and design that facilitate the development and understanding of various, often difficult, concepts of this functional language.
Elixir comes with Erlang’s Open-Telecom Platform (OTP). The OTP is a set of tools designed to simplify the creation of concurrent applications. The biggest emphasis in OTP is placed on writing fault-tolerant applications. With the included framework, developers can build their software capable of handling many concurrent connections.
With full interoperability, Erlang libraries can be easily incorporated into any Elixir project.
On the official Elixir website, there are plenty of useful guides and resources as well as links to highly active communities supporting Elixir. Documentation can also be called up from the terminal, so that’s a nice bonus.
Phoenix, the most popular Elixir web development framework, prides itself in unparalleled response times measured in microseconds. Rails is no slouch, with millisecond response times, but there's an order of magnitude difference here.
Even though it was created in 2011, Elixir is still considered a niche language. This creates a relative market void in that area of expertise. Since Elixir is partially rooted in Ruby, however, Ruby developers will find it easier to learn and be able to start working in the language. But there’s a hurdle that many developers, especially ones with little experience, might find difficult to overcome at first. And that is:
Elixir is a functional language, whereas Ruby is naturally object-oriented (although it also supports functional programming). Wrapping your head around the difference in approach to programming in this way can be an obstacle. But it’s not impossible to switch from one paradigm to the other—it’s just a matter of acquiring a new way of thinking about software development.
We already mentioned that Elixir has full interoperability with Erlang libraries. However, even with those aboard, programming in Elixir might often require building new features from scratch.
When creating Ruby, Yukihiro Matsumoto aimed to build a programming language that would make developers happy working with it. Its clean and lean syntax clearly helps with both reading and writing the code.
When most people hear Ruby, they immediately think of Ruby on Rails - testifying to how ingrained in the language the framework became. That’s because Ruby on Rails has revolutionized the way modern Web applications are created.
Both Ruby and Ruby on Rails have a huge ecosystem of libraries. There’s a gem created for just about any feature you might want to implement. Whatever you need to build a full-fledged app, you’ll find a tool that’ll help you do it. The abundance of gems is what makes Ruby and Ruby on Rails fast and battle-proven solutions for building such an application.
The Ruby and Rails communities are both vibrant and packed with contributors publishing ready-made solutions with open-source access.
In the popularity contest of Elixir vs. Ruby, the latter is the unquestionable winner. Greater popularity means more resources, a bigger community, and a broader pool of developers experienced in writing code in this language.
In this second popularity ranking below, Elixir rates below the first 50 programming languages.
Ruby’s popularity. Source: TIOBE Index for June 2023
Also, working with Rails, you can expect a lot more support and ready-made third-party software, than in the case of less popular Phoenix.
Compared to Elixir, Ruby is not that good of a choice for concurrent Web apps.
It is possible to write web applications using Concurrent Ruby tools; however, without the additional tools, Ruby’s global interpreter lock (GIL) allows for only one thread to be executed at a time. Without built-in concurrency, developers can’t manage the available hardware resources efficiently—a necessity in every traffic-heavy app.
Ruby isn’t slow, but it’s not as fast as Elixir. Poor performance, however, is, in this particular case, usually the result of inexperience.
Experienced Ruby developers can create even enterprise-grade apps decently fast. But if you design a large-volume traffic app, keep in mind that whatever you do, Ruby might not be up for the job.
Gems are what make Ruby and Rails a battle-proven solution for developers who prefer the fuss-free approach to code while writing web applications, but they can cause many problems when it comes to long-term maintenance.
In the Ruby realm, convenience is favored over configuration to keep the code concise and make developers more productive. But when less experienced developers don’t know the ins and outs of what goes on behind the Rails' curtain, so to speak, mistakes that hinder productivity and maintenance are likely to happen.
After looking at the differences between the two languages, let's put Elixir’s and Ruby’s characteristics into the best use cases.
Also, you can take the best of the two and mix and match them to use given features where they would produce an optimal result.
* Limited audience and medium-sized web apps are relative concepts. Generally speaking, Ruby might struggle with an app with huge Twitter-like traffic or similar demand.
Sadly, there is no single, definite answer to that question. Both Elixir and Ruby are great tools for building various apps, software, or systems. The important thing is always to pick the technology that seems the most appropriate feature-wise for your project.
Elixir has been gaining traction for a while now, and many software companies do in fact incorporate it into their offer — hey, we did it too because it’s a great piece of technology that can yield absolutely mind-bending results!
One example: think 1.3M simultaneous connections on a single server! But it might be overkill for projects that don’t need Elixir’s distinct features—so just because this technology is getting more and more attention doesn’t mean you should be following along at all costs.
Here goes the shortcut to picking Elixir vs. Ruby - pick Elixir if you want to write a Web application of the type listed in the best use cases section in the article, and you’ll experience great results. But trust the good old Ruby code for projects that pretty much scream for it.