The Little Story of Elixir Programming Language
The Elixir language, operating on an Erlang machine, is constantly gaining more and more followers. Where can these languages be used? How was Elixir created and what does it have in common with Erlang?
It is not difficult to find examples of ineffective solutions from the early years of new technologies' life. For example, half of the villages worked with a tiny combine in the past, and light bulbs were more likely to produce heat than light. It was the same with telecommunications networks - the current infrastructure was built gradually, along with technological advances, increasing demand and a deeper understanding of the necessary processes.
- In the photo: Erlang, circa WWII
One of the biggest challenges for rapidly developing telecommunications in the mid-1980s (including mobile telecommunications) was fast and reliable connection switching - a job that manual workers commonly performed until recently! The last operator of manual call transfer only lost his job in 1983. However, the first attempts at automation were very unreliable.
How to make computer programs work reliably for years and even be able to correct some of their mistakes on their own?
The result of this search was Elixir's father, Erlang. Established almost 34 years ago in Swedish Ericsson, it has quickly become one of the technological foundations of today's internet and mobile phone calls from a niche tool. According to the estimates of the digital giant CISCO, presented at the Stockholm-based CodeBEAM, 90% of all internet traffic goes through Erlang-controlled nodes. Therefore, to understand the unique features of Elixir, it is worth following the fate of its progenitor.
"... some of the requirements needed to build a fault-tolerant system are solved with language alone, others with standard libraries. Together, they form the basis of such [reliable] systems ..."
- PhD thesis by Joe Armstrong, one of the founders of Erlang
Write once, run forever. Erlang lightweight processes
In a nutshell, Erlang is designed to write concurrent programs that run "till the end of the world". Erlang uses parallel processes to structure programs, which makes it different from many technologies. In Erlang, processes do not have shared memory but communicate using asynchronous messages.
The 8 largest suppliers of network equipment use components that run on Erlang.
90% of internet traffic goes through nodes controlled by Erlang.
- source: Johan Bevemyr – How Cisco is using Erlang for intent-based networking – Code Beam STO
The infrastructure is very light - the processes are minimal and run inside the language, not the operating system. If an error occurs in one operation, the other functions will not be affected by it - there will be no critical coupling because the programs are not sequentially linked together. It's a bit of a "fail-fast" philosophy; something spilt out? Sorry, a million processes next to it must go on.
The abovementioned abilities, such as fault tolerance and the possibility of limited self-repair, become even more critical given the type of systems Erlang is currently used for. From ATMs to online games and mobile phones and data transfer. Erlang fits great in systems where we require very high reliability with the possibility to handle a high number of simultaneous users.
Lots of traffic, little work.
In the early '90s, we saw a rapid increase in Erlang popularity, which was "freed" by Ericsson in 1998 and thus gained the support of the open-source community. In turn, in the early 2000s, the times caught up with Erlang. New technologies, such as multi-core processors, enormous growth in network traffic and the fast-growing world of mobile applications required quickly scalable and easy-to-maintain systems that did not reject customers with a mass of errors in life-critical services. Erlang code and configuration can be updated virtually live without downtime.
Today we still use Erlang, where concurrency and reliability are required. A billion people will send messages via WeChat and WhatsApp today, a hundred million people will watch something on Netflix, a hundred thousand people will log into the World of Warcraft server - and deep beneath the surface of each action lies a process in Erlang.
Companies using Elixir and Erlang
- Companies using Erlang: Nintendo, Mastercard, T-mobile, Goldman Sachs, WhatsApp, Motorola, Hewlett-Packard, IBM
- Companies using Elixir: Spotify, PepsiCo, Discord, Square Enix, Adobe, Slack, Pinterest, Toyota
From the programmer's point of view, Erlang is still a niche - it has a specific set of applications and is not easy to use. The demand for developers is relatively low. For example, WhatsApp needed less than half a hundred engineers to manage 900 million daily users from A to Z - the system once installed in Erlang requires very little maintenance.
Erlang Extract
Unfortunately, Erlang has its limitations - the ease of writing code may have made an impression several years ago, but Erlang did not fit in with everyday use. So while the great BEAM - Erlang's virtual machine - provides the best performance, the entire language needed refreshing at least.
And here is where José Valim appears in our history - a friendly and highly hard-working Elixir creator. Before working on Elixir, he was a Ruby developer, and the languages share some similarities. It annoyed him in his day-to-day work that Ruby was poor at concurrency. When looking for a solution, Jose appreciated the performance of Erlang's virtual machine and decided to use it.
"Due to the focus on concurrency, Elixir will be perfect where it is required. A classic example would be applications that use persistent connections, such as Web Sockets. Ruby can only cope with them on average (…). On the other hand, Elixir can maintain dozens, if not hundreds of thousands, of such connections without much effort."
- (Paweł Świątkowski, Senior Developer)
Startup Rails applications
Ruby is considered a highly productive language. This feature made many startups use it with their server architecture. The dependency is simple - the faster we can create an application achieving the intended effect, the fewer costs we incur. It is precisely this type of productivity in development that you will not find in Erlang.
José Valim understood it well - in addition to extensibility (that is, the ease of adding new functions), the key assumption of the emerging language was precisely productivity.
Powerful but niche
That is how Elixir was created - a language in many places inspired by Ruby syntax and using OTP, i.e. a collection of libraries and good design practices of the Erlang language. The main advantages of Elixir include:
- code compiled into Bytecode, which is then interpreted by a great BEAM,
- language functionality, which for many people means a much simpler code structure,
- a pretty simple syntax - as a result, the code is short,
- metaprogramming,
- pattern matching, which gives advanced users powerful possibilities,
- the simplicity of the used solutions, which allow writing advanced applications.
Elixir vs Ruby
Elixir also occupied a significant niche in creating web and mobile applications. Thanks to the Phoenix framework, it allows for developing advanced web applications and introduces a lot of freshness through LiveView. We can compare the Elixir / Phoenix framework relationship to Ruby's with Rails. This is one of the reasons why it is relatively easy for RoR (Ruby on Rails) developers to learn Elixir.
Elixir's environment is not very large - it is a specific language, the value of which is excellent when creating MVPs. In this aspect, it has comparable performance and development speed as Ruby on Rails, but it scales incomparably better. It will also be faster than RoR in heavily loaded services and applications. Due to the power of the Elixir programming language in the abovementioned applications, the most significant software houses and large corporations (e.g. Pepsi, Spotify or Square Enix) eagerly use the Elixir language in their projects.
Like other languages, Elixir has several disadvantages that limit its usefulness. First, you need to consider the costs associated with the relatively low availability of qualified programmers in this technology. It has a slightly higher entry threshold than other technologies, so few developers choose it as their first language.
Elixir Community support
The Elixir community is strong and helpful, but we cannot compare it in scale to more popular technologies such as Python or JavaScript. Therefore, before we start an unusual project, it is worth making sure that the necessary libraries are available - if not, you will have to create them!
I encourage you to watch a short documentary with the creator of Elixir, which describes its origins and the community around him.
So… do you want to start programming in Elixir?
As we already know, Elixir is not extremely difficult to learn - although some programmers find it challenging to move from the object-oriented paradigm to the functional paradigm, of which Elixir is a great representative. Elixir has excellent documentation, but if it's not enough for you, take a look at these high-quality study materials below:
Elixir learning resources
- Programming Elixir >=1.6 - for those who begin their adventure with Elixir,
- Leading Elixir screencast - the most extensive collection of video lessons,
- Exercism - open-source, community-driven platform, the go-to resource for interactive, online learning of programming languages,
- Elixirforum - an active discussion forum for the Elixir community,
- Check more here: Top Elixir Learning Media & Resources in 2022 from Michał Buszkiewicz.