Erlang’s virtual machine, the BEAM

Welcome to the first chapter of the series “Elixir, 7 steps to start your journey”

I know you’re here because you would like to learn more about this programming language, but before talking about Elixir, we need to talk about Erlang and its virtual machine (VM), the BEAM.

The magic behind the concurrency and scalability of an Elixir system happens in this virtual machine. The Elixir code you write runs on it. Therefore, before addressing the features of the programming language, we must understand its fundamentals.

What is Erlang?

Erlang is a development platform composed of:

  • The programming language with the same name, Erlang.
  • The framework OTP.
  • A virtual machine, the BEAM (Bogdan / Björn’s Erlang Abstract Machine).
  • A set of tools.

It should be noted that when we talk about Erlang, we can refer to the platform as such or simply to the programming language. This is probably familiar to you if you have worked with object-oriented programming. The same thing happens with Java. Java can be the ecosystem that includes the JVM or simply the language. 

For this note, when we mention Erlang, we mean the entire platform. With that said, let’s talk about a bit of history.

Erlang is a development platform created by Joe Armstrong, Robert Virding, and Mike Williams in the mid-1980s at Ericsson’s Computer Science Laboratory to facilitate the development of telecommunications systems.

Currently, it is used to develop distributed, concurrent, scalable, and fault-tolerant systems. And although it refers to telecommunications, it is a general-purpose technology that has demonstrated its robustness in production systems for over 30 years.

If you think about it, most of today’s systems require these characteristics: to be distributed, scalable, concurrent, and fault-tolerant, among others- in addition to being expected to work almost without fail and to be able to recover quickly from any error. For example, WhatsApp. In the few times it has crashed, how long does it take to see bug reports on social media? User complaints are almost immediate. Now, imagine the margin of error in more critical sectors, such as health or the stock market, where the slightest mistake can have serious consequences.

By the way, fun fact: WhatsApp uses Erlang.

But let’s be honest; it’s impossible to build a system that is 100 percent bug-free. What we can do is have a recovery mechanism so that no failure breaks or disables the system. This is what Erlang provides by default, all the necessary elements to create this mechanism and develop systems that:

  • Requires a large number of users and support easily adding more if necessary.
  • Can easily detect and recover from errors.
  • Always responds, even if there is an internal error. This means that the system cannot pause or wait indefinitely since that represents uncertainty for the users.
  • Can be updated without stopping or interrupting user activities.
  • Can be distributed.

All this is thanks to its virtual machine, the BEAM.

What is BEAM?

The BEAM (Bogdan / Björn’s Erlang Abstract Machine) is the Erlang virtual machine where Erlang or Elixir code is executed.

Elixir code is compiled into bytecode files that run on the virtual machine, these files have the .beam extension.

Erlang and Elixir are not the only programming languages that can run on the BEAM. But for now, let’s put that information aside and focus on the general features of the virtual machine.

The relevance of the BEAM lies in the fact that it is responsible for a system being able to comply with all the mentioned characteristics:

  • Manages concurrency and parallelism of a system.
  • Errors have a minimal impact.
  • Manages a recovery mechanism against those errors.
  • It makes the most of the computer’s resources on which the system is running.

These characteristics translate into reliable, highly available, fault-tolerant, scalable, and distributed systems. 

What does all this have to do with Elixir? 

Elixir in the BEAM

As we mentioned at the beginning of the post, Erlang is a platform made up of four elements. One of them is the Erlang programming language, which obviously allows you to write code that runs on the virtual machine. But it’s not the only one. There are more programming languages, one of them being Elixir.

So, why would we choose Elixir?

Erlang, the language, is compatible with Elixir code. This means that what you can write in Erlang, you can write in Elixir and vice versa, with the difference that Elixir’s syntax and toolings feel much more friendly and accessible—allowing cleaner, more maintainable code to be written and with a short learning curve.

Although, of course, it will always depend on the tastes and experiences of each person. The characteristics of Elixir have made it more and more popular by developers, with many resources created around it.

In short, with Elixir, the power of BEAM is harnessed through a friendly programming language, a fantastic community, and plenty of resources like documentation and tutorials, allowing you to build projects in no time and experience all of its features.

And this is all thanks to Erlang processes, which we’ll look at in the next chapter. 

The next chapter

I know you’re eager to see the code. Don’t worry, in the following note, we’ll go deeper into what Erlang processes are and how to implement concurrency using Elixir.

Documentation & Resources

Technical advisor: 

See you in the next chapter!

Keep reading

Technical debt and HR – what do they have in common?

Technical debt and HR – what do they have in common?

At first glance, it may sound absurd. Here we have technical debt, a purely engineering problem, as technical as it can get, and another area,...

Blockchain Tech Deep Dive| Meaning of Ownership

Blockchain Tech Deep Dive| Meaning of Ownership

What does 'ownership' really mean in the era of rising prominence of digital assets Let's explore this in third instalment of our blockchain blog series.

Blockchain Tech Deep Dive | Innovating with Erlang and Elixir

Blockchain Tech Deep Dive | Innovating with Erlang and Elixir

We're exploring why Erlang and Elixir are a good fit for innovation in the ever- growing blockchain space.