There are more programming languages today than there ever have been. Many of them promise to revolutionise the way we do things, and while some deliver on that promise, a large proportion fall by the wayside. As a start-up, it is important to choose the correct technology from the get-go in order to prevent costly U-turns later on. With so many programming languages and frameworks to choose from, how do you know what's the right choice? In this article, we examine a little known option - a modern programming language that relies on 30 years of getting it right, combined with recent enhancements that make it remarkably productive. The language is called Elixir, and it is built on top of Erlang - a platform for concurrent programming with a proven industrial track record.
A programming language with telecom pedigree
The brainchild of Joe Armstrong at Ericsson, the programming language Erlang was created in 1986 to improve the development of telephony applications. In his doctoral thesis (Making reliable distributed systems in the presence of software errors - highly recommended reading for all software engineers!) Armstrong explains that he didn't set out to create a new programming language. Instead, his focus at the time was to add concurrent processing to Prolog to program a telephony service. Around 1988, Armstrong along with Robert Virding and Mike Williams, discovered that their new creation was remarkably efficient for programming telecoms systems that need to reliably handle large number of processes in parallel. Ericsson released Erlang first as a propriety language, then made it available as open source in 1998.
Despite being almost 30 years old, Erlang is increasingly used in industry today. As a modern example, Facebook uses Erlang to power its chat application and has been doing so since 2007 (after many prototypes based on Armstrong's thesis). WhatsApp handle billions of messages every day using Erlang. The Huffington Post, Amazon and Motorola all currently have critical software components built in-house with Erlang.
The quiet and remarkable success of modern Erlang
Erlang is designed to be fault-tolerant - that is, to be able to gracefully handle system failures and recover quickly, without incurring any system downtime - something that very few mainstream languages today are any good at. Erlang supports distributed, soft real-time and non-stop applications. Its hot-code swapping functionality allows code to be inspected and changed live, in production environments, without stopping the system. It uses a shared-nothing message-passing concurrency model, which means that it reliably supports large numbers of processes running at once and without stepping on each other's toes.
Eugene Letuchy, a programmer at Facebook, describes Erlang's ability to support concurrent interactions in Facebook Chat as a major selling point of the language. Additionally, he states that "cheap parallelism at a massive scale" is another reason Facebook began experimenting with Erlang in 2007. They successfully sent their first chat message in April 2008. In March 2015, Facebook reported an average of 936 million daily active users. That is a lot of concurrent interactions, by almost any standard.
Likewise, WhatsApp (acquired by Facebook in 2014) boasts 800 million monthly active users. Eugene Fooksman, software developer at WhatsApp, explains that they developed the service from ejabberd, an open source instant message server written in Erlang. He cites the main advantages of Erlang as it being perfect for concurrent programming in a multi-user environment, such as communication servers.
Elixir - an exciting twist to an already great story
Elixir is a new, modern programming language built on top of the Erlang virtual machine. It adds to Erlang recent theoretical developments in computer science, fashionable syntax and pragmatic tooling. As we will see, for a new language, Elixir is surprisingly complete and reliable.
"Experts in a particular field can often instantly know that something is right, but they can't explain why," wrote Joe Armstrong about Elixir after he spent a week looking at it in detail. High praise indeed, coming from the creator of Erlang.
José Valim developed Elixir in 2011. He took the functionality of Erlang and the Open Telecom Platform (OTP) framework, and added nice modern features like meta-programming with macros and polymorphism via protocols. Elixir runs on the Erlang virtual machine (BEAM), but uses a different syntax, which is a lot closer to Ruby and Python that to that of Erlang. This was a necessary enhancement, given that even fans of Erlang have long bemoaned the language's weird syntax, which Elixir greatly simplifies.
Along with the new and improved code, there are quite a few more benefits of using Elixir. Chiefly, its homage to Erlang means that it can capitalise on 30 years worth of libraries and power tools. Any Erlang function can be called directly from Elixir code. Existing Erlang tools for debugging, hot-swapping of code, monitoring and optimising applications are at the fingertips of any Elixir developer. In addition, many new tools and packages have been designed specifically for Elixir, thus expanding even further the range of this language's capabilities.
When you use Elixir, you benefit from the tried and tested power of Erlang as well as the improvements and syntax-friendly, functional programming capabilities of Elixir. A comprehensive blog post by Devin Torres really delves into the great many benefits of Elixir and how it improves upon Erlang.
You also, of course, get to take advantage of the language's natural affinity for concurrency and multi-processing. With a well-designed Elixir application, you can often increase performance dramatically by simply throwing more hardware at it - double the number of CPU cores and you almost get double the performance (up to a point). In fact, at A115 we recently developed an open-source library to demonstrate this exact property. Our exmatrix library implements a parallel algorithm for multiplying large numeric matrices in pure Elixir. Multiplying matrices in this way provides a great context for bench-marking parallel performance, because each row and column can be multiplied independently, at the same time, and each operation is rather computationally intensive in its own right. When we ran the numbers, it was immediately obvious (as you can see from the graphs in the README file on GitHub) that performance doubled as we doubled the number of cores. This property makes Elixir particularly suitable for exploiting the advantages of cloud computing, where you can dynamically increase and decrease the number of cores on demand in response to your application's usage intensity.
Phoenix - an Elixir framework for modern web apps
One of the main reasons for the popularity of languages like Python and Ruby is that they come with powerful frameworks for quick prototyping and development of web-based applications and API's (Django and Ruby-on-Rails respectively). Being built on top of the Erlang virtual machine, Elixir is particularly good at concurrency and multi-processing - the main characteristics of all modern web apps. So it only makes sense that, if paired with a good web framework, Elixir should be a particularly good choice for a web back-end programming language.
Enter Phoenix - a web development framework, written in Elixir. Phoenix allows high developer productivity as well as lightning fast performance (HTTP response times for apps built with Phoenix are often measured in microseconds as opposed to milliseconds). Designed to be modular and flexible, Phoenix inherits fault tolerance, concurrency and meta-programming from Elixir, thus making it a powerhouse of a web framework. Essentially, Phoenix builds on Elixir in the same way that Rails builds on Ruby.
Phoenix can be used to build any type of web application, but is particularly well suited for building real-time, interactive web platforms and mobile apps - like trading systems, streaming services, multi-user web-based games, chat rooms, etc. This is achieved via the use of Web Sockets and channels - programming constructs that allow bi-directional data streaming for building interactive apps that communicate with any type of connected device. This is ideal for any start-up that values the speed and flexibility required in order to get a web app live as soon as possible.
Phoenix is currently the most common web framework written in Elixir (there are a few others) and even though it is loosely modelled after Ruby on Rails, it is not simply a Rails clone for Elixir. Instead, it takes full advantage of the concurrency features of Erlang and Elixir to enable truly modern, fault-tolerant, interactive development for the web. Like Rails and Django, Phoenix is well suited for rapid application development (RAD) and agile methodologies. It provides teams with the capacity to build and deploy web applications quickly, which is a big advantage for start-ups needing to quickly get an MVP out there.
Getting started with Elixir
As with any programming language, the paths to learning Elixir are many. We've seen so far that Ruby-turned-Elixir developers have no problem adapting to Elixir's Ruby-like syntax so a "jump right in and get coding" approach would suit many developers. For others, there are a number of options available. A really good starting point is Jordan Dimov's Round Up of Elixir Books and Resources.
When a new language enters the scene, there is understandably, a large amount of initial hype. In many cases, the euphoria wears off quickly and developers find themselves searching (even subconsciously) for the next newest tool. Erlang, however, has withstood the test of time, primarily due to some of the unique attributes it has, which were discussed in this article. In this sense, Elixir and Phoenix are really standing on the shoulders of giants, being built on top of a stable virtual machine that is extensively documented and used in the wild by some of the most successful companies in the world.
While Joe Armstrong and the team at Ericsson were figuring out a solid telephony system, little did they think that their ingenuity would power today's web applications viewed on hand-held devices. José Valimr's Elixir has given a new twist to a 30-year old technology. Elixir uses what is great about Erlang, corrects the not so great specs and makes it an accessible and modern developer friendly language. Industry experts say Elixir is fast, productive, learnable and is suitable for a wide-range of general and web-based programming applications. Start-ups should take notice.
If you want to build your new project in Elixir, or are wondering how your start-up can best take advantage of this powerful new programming language, do not hesitate to contact us!