DEV Community

Cover image for Elixir, Erlang, and the BEAM
Cody Daigle
Cody Daigle

Posted on

Elixir, Erlang, and the BEAM

It’s exciting to learn new languages, especially one’s you take an interest in, but a great rule of thumb when taking in that learning process is to understand where they originate from. So, before taking a deep dive into Elixir I’d say it’s a pretty solid Idea to look into Erlang, Elixir’s parent language, in order to properly conceptualize what occurs within Elixir. One important topic to delve into would be Erlang’s virtual machine and the vital role it plays when developing with the language.

Erlang

The Erlang development platform was created, in 1986, by Joe Armstrong, Mike Williams, and Robert Virding while at the Ericsson’s Computer Science Laboratory to aid in the development of telephony applications. Erlang is not only a platform but also a language. One of the large reasons Erlang is praised on it’s error handling is the use of the Open Telecom Platform framework. Although not so much on the telecom part, but instead is directed towards software that has properties of telecom applications, but i digress (I’ll touch on OTP a little later). Modern day systems require aspects like concurrency, fault-tolerance, and scalability in order to perform efficiently, preferable not crash at all, but when then inevitably do fail they recover swiftly. Now in a perfect world a system would be 100% bug and issue free, but sadly that’s not possible. Fortunately for us, by default, Erlang provides necessary assets to create systems with as much relief in those instances as possible. Next I want to go over how BEAM helps achieve this, but here are some of the resolutions that is provide by the use of Erlang/Elixir

  • Detects and recovers from errors with ease
  • Always provides a response regardless of the error so that it doesn’t affect the system impacting the user.
  • Can be updated without disrupting user activities
  • Can be distributed

Beam me up, Scotty

BEAM me up

The impressive concurrency and scalability within Elixir/Erlang systems may seem like witchcraft, but all the code that you write is actually executed on Erlang’s VM, called BEAM (Bogdan / Björn’s Erlang Abstract Machine). The files that are run on the virtual machine are compiled into bytecode with the .beam extension. What makes the virtual machine truly worthy of the spotlight and deserves to be recognized due to it’s unique handling of responsibilities like managing concurrency and parallelism of a system. In situations like simultaneous data processing, BEAM shines by effectively managing these tasks, enhancing the system's productivity and efficiency. Additionally Beam excels in error handling, which is a crucial aspect of any system, and handles those errors with minimal impact. The picture I’m trying to paint is the excellence in handling concurrency and parallelism, its efficient resource utilization, and robust error handling and recovery mechanisms making it a highly reliable and available system.

OTP

Open Telecom Platform, commonly referred to as OTP, is an extensive collection of libraries and tools that form an integral part of the Erlang/OTP distribution. It provides a comprehensive framework that is specifically designed for the creation of robust applications that are not only fault-tolerant but also distributed in nature. This is all made possible through the use of the Erlang programming language, which is renowned for its ability to handle concurrent processes efficiently. Thus, OTP is a crucial tool in the Erlang ecosystem, enabling developers to build complex, reliable, and efficient applications with relative ease.

  • Applications - Packages and manages application’d dependencies, configuration, and startup / shutdown processes
  • Behaviors - Design patterns or abstractions for structuring applications
  • Debugging & Tracing - Erlang Debugger, Profiler, Trace tools
  • Distribution - Processes can run on different nodes and maintain transparent communication
  • Hot Code Upgrades - Upgrading code doesn’t cause down time. AKA Hot Swapping.
  • Libraries - Standard libraries for file handling, networking, and more
  • Supervisor Trees - Creates hierarchical process structures for monitoring child processes.

OTP plays a vital role in the Erlang ecosystem and Elixir inherits it’s features along side the BEAM.

Elixir


Erlang and Elixir code are compatible, so either language can be written interchangeably. The main difference lies in Elixir's more accessible syntax and tooling, which allows for cleaner, more maintainable code with a short learning curve. Elixir, with its friendly programming language, welcoming community, and tons of helpful resources like documentation and tutorials, really lets you tap into the power of BEAM. You'll be able to whip up projects in no time and take full advantage of everything it has to offer!

Personally, I look forward to really having the opportunity to delve as deep as I can into Erlang and Elixir to become proficient with developing technologies. With that being said the next few items I intend to write about will be the Elixir framework, Phoenix, and some of the advantages with using the language like pattern matching!

Top comments (0)