September 11, 2019
Over the past couple of years, we wrote extensively about Ruby (and Ruby on Rails), so you know we like it quite a bit. We’ve also dabbled some in Elixir (and Phoenix), but never before have we compared the two side by side to see which one is a better fit and when. So here it goes.The Story of Ruby and Elixir
Ruby and Ruby on Rails probably need no introduction. They are both widely used tools for writing web applications. Ruby, created as far back as 1995, was built to make the developer work more productive and fun. 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 has changed the landscape of Web app development. By introducing tools that facilitate speedy development of apps and focusing on the pleasurable aspect of coding, it set the direction other Web frameworks 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’s best in Ruby and build something entirely different on top of it. Based on the Erlang VM to solve concurrency limitations, Elixir was thus conceived.
As to 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 to his Phoenix project, with an intention to create a framework that would ultimately outperform Rails.
Below is a short table with descriptions of what’s what in each of the four technologies.
|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 basis 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, 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 - industry where it's used to manage simultaneous connections, Elixir supports 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 utilize every core on a single server, and if you need more resources to meet the traffic demand, you can use every core on all of your available servers.
In Elixir, pieces of the code are executed as processes. Sitting at the heart of Elixir’s concurrency capabilities, each process is lightweight, using very little memory and CPU power. You can have as many as hundreds of thousands of these processes running at the same time.
Also thanks to processes, Elixir is great for developing distributed, fault-tolerant systems.
If a system or an application is expected to sustain plenty of traffic in the future, 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 architecture to accommodate the bandwidth demand that a growing number of users generates.
Elixir has clear syntax, patterns, and design that facilitate development and the 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 own software that is capable of handling many concurrent connections.
Coming 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.
Even though it’s been 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 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 Ruby on Rails - testifying to how ingrained in the language the framework became. That’s because Ruby on Rails revolutionized the way modern Web applications are created. By introducing gems, Ruby on Rails made it possible to build MVPs, prototypes, and even small apps very fast and with minimum code.
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/Rails a fast and battle proven solution to building such app.
The Ruby and Rails communities are both vibrant and packed with contributors publishing ready-made solutions with open-source access.
In the popularity battle of Elixir vs Ruby, the latter is the unquestionable winner. Greater popularity means more resources, bigger community, and broader pool of developers experienced in writing code in this language.
Ruby’s popularity. Source: Stack Overflow 2019 Survey
Ruby’s popularity. Source: TIOBE Index for June 2019
In the second popularity ranking, Elixir rates below the first 50 programming languages.
Compared to Elixir, Ruby is not that good of a choice for a concurrent Web app. 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.
This, of course, might change with the rollout of Ruby 3, which is said to have a three-fold increase in performance compared to its former versions.
Gems are what makes Ruby and Rails a battle proven solution to developers who prefer the fuss-free approach to code while writing web applications, but they can also be the cause of 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, lets put Elixir’s and Ruby’s characteristics into 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 optimal result.
* Limited audience and medium-size Web app 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 to always 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!
(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 web applications of the type listed in the best use cases section in the article, and you’ll experience great results. But trust good old Ruby code for projects that pretty much scream for it :)
Confidently build your next app
Regardless of which tech stack you might need, our communicative devs will help you choose the best option for your project. Work with experts who will push hard to understand your business and meet certain deadlines.