Ruby vs Elixir

Ruby vs Elixir — Which One to Choose in 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.

Contents:

The Story of Ruby and Elixir (and Phoenix)

Ruby and Ruby on Rails


Ruby and Ruby on Rails probably need no introduction. They are both widely used tools for writing web applications.

Ruby, created back in 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 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.

Also read:

Why Ruby on Rails Is Still a Good Choice in 2022 [UPDATED]

Elixir and Phoenix

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 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, with an intention 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
When  1993 2012 2004 2014 
Who Yukihiro Matsumoto José Valim David Heinemeier Hansson Chris McCord

What

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

Nailing Down the Pros and Cons of Ruby and Elixir

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.

Pros of Elixir

The Solution that Stood the Test of Time


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.

 Distributed Concurrency


Thanks to Erlang, widely adopted by the telecom - 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 of your available servers.

Lightweight Processes


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.

Scalability


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 app's architecture to accommodate the bandwidth demand that a growing number of users generates.

 Thought-Out Language Design


Elixir has clear syntax, patterns, and design that facilitate the development and the understanding of various, often difficult, concepts of this functional language.

Open-Telecom Platform (OTP)


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.

Erlang Libraries


Coming with full interoperability, Erlang libraries can be easily incorporated into any Elixir project.

Documentation


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's Performance


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.

Cons of Elixir

Narrow Talent Pool


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:

Functional Programming Paradigm


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.

Relatively Small Ecosystem


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.

Pros of Ruby

Productive and Pleasant to Work With


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.

The Genius Framework: Ruby on Rails


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.

By introducing gems, Ruby on Rails made it possible to build MVPs, prototypes, Proofs of Concept, and even small applications very fast and with minimum code.

Ecosystem


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 to building such an application.

Resourceful Community


The Ruby and Rails communities are both vibrant and packed with contributors publishing ready-made solutions with open-source access.

Popularity


In the popularity battle 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.

Stack Overflow 2022 languages

 Source: Stack Overflow 2022 Survey - most popular technologies

In this second popularity ranking below, Elixir rates below the first 50 programming languages.

Tiobe ranking 2022 June

Ruby’s popularity. Source: TIOBE Index for June 2022

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.

Cons of Ruby

Concurrency


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.

Performance and development speed


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.

Maintenance


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 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.

Best Use Cases for Elixir vs Ruby

After looking at the differences between the two languages, let's put Elixir’s and Ruby’s characteristics into the best use cases.

Elixir—Best Use Cases

  • high-traffic applications (messages, chats, etc.)
  • applications with 100–1,000,000 simultaneous connections on a single computer
  • Web applications with a large number of users (thousands or hundreds of thousands)
  • Internet of Things app
  • distributed systems
  • software performing asynchronous tasks
  • apps likely to be scaled and expanded in the future

Ruby—Best Use Cases

  • MVPs, PoCs
  • app concepts
  • prototypes
  • marketplaces
  • small to medium-size Web apps created to cater to a limited audience*

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-size Web app are relative concepts. Generally speaking, Ruby might struggle with an app with huge Twitter-like traffic or similar demand. 

So Then, Should You Choose Elixir or Ruby?

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!

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 :)

New Call-to-action
Flutter vs Ionic: Which Cross-Platform Framework To Use in 2022
Old Ruby Codebase - When to Update, What to Consider (Checklist)
Why Use Flutter for Animations in Mobile App Development?