Lesson 1 / 25
What Elixir Is and Why the BEAM Matters
Describe Elixir, the Erlang VM and where they shine.
A friendly language on a battle-tested VM
Elixir is a dynamic, functional language created by José Valim and first released in 2012 (version 1.0 arrived in 2014). It runs on the BEAM, the Erlang virtual machine, which Ericsson built for telephone switches that had to stay up for years. From the BEAM, Elixir inherits lightweight processes (millions can run on one machine, each with its own memory and garbage collection), message passing instead of shared memory, preemptive scheduling across all CPU cores, fault tolerance through supervisors, distribution across nodes and hot code upgrades. Elixir adds a modern, Ruby-inspired syntax, macros, the pipe operator, excellent tooling (Mix, Hex, IEx, ExUnit) and documentation as a first-class feature, and it can call any Erlang/OTP library directly. Elixir is used for real-time and highly concurrent systems: chat and messaging (Discord used it to scale), web applications with Phoenix and LiveView, IoT with Nerves, data pipelines with Broadway, and machine learning with Nx and Livebook. Data is immutable, and code is organised into modules of functions.
Elixir on the BEAM
Many small isolated processes talk by messages, watched over by supervisors.
A first taste of Elixir
Pattern matching, the pipe operator and a process.
defmodule Greeter do
def hello(name), do: "Hello, #{name}!"
end
IO.puts(Greeter.hello("Asha"))
# the pipe passes the previous result as the first argument
[49.5, 120, 199]
|> Enum.filter(&(&1 > 100))
|> Enum.sum()
|> IO.inspect(label: "expensive total")
# pattern matching destructures data
{:ok, %{city: city}} = {:ok, %{city: "Pune", total: 1200}}
IO.puts(city)
# spawn a lightweight process and send it a message
parent = self()
spawn(fn -> send(parent, {:greeting, "hi from another process"}) end)
receive do
{:greeting, text} -> IO.puts(text)
end
# run with: elixir hello.exsThink in processes, not threads
On the BEAM a process is cheap (a few kilobytes), so it is normal to give each user connection, game room or background job its own process. That design is what makes Elixir systems both concurrent and resilient.
Quick check: What does Elixir gain by running on the BEAM?
- Lightweight isolated processes, message passing, fault tolerance and distribution
- Manual memory management
- Static typing like Java
- Access to the JVM ecosystem
Answer
Lightweight isolated processes, message passing, fault tolerance and distribution — The Erlang VM provides cheap processes, supervision and distribution.