Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท Getting Started

What Is Erlang?

Meet Erlang: a functional language built at Ericsson for telephone switches, with lightweight processes, fault tolerance and the BEAM virtual machine.

Erlang is a functional programming language and runtime built for systems that must never stop. It was created in the 1980s at Ericsson, the telecom company, to program telephone switches: machines that handle thousands of calls at once, must be upgraded without hanging up anyone, and must keep working when parts of them fail. Those requirements shaped everything about the language.

Today Erlang powers messaging systems, databases, payment platforms and network equipment. RabbitMQ, CouchDB and parts of the WhatsApp backend are written in it. The language also gave birth to Elixir, another language that runs on the same virtual machine.

Erlang cannot run inside this site's code editors. Examples in the Erlang blocks are read-only, and where we need something you can press "Run" on, we use a small JavaScript stand-in that is clearly labelled. To run real Erlang, install it on your computer in the next lesson.

The four big ideas

Erlang is easiest to understand through four ideas that show up in every program.

  1. Everything is a process. An Erlang process is not an operating-system thread. It is a tiny, isolated unit of work managed by the runtime. A fresh process costs only a few hundred words of memory, so a program can run hundreds of thousands, even millions, at the same time.
  2. Processes share nothing. Each process has its own memory. They talk by sending messages, which are copied from one process to another. There are no locks and no shared variables to corrupt.
  3. Let it crash. Instead of defending against every possible error, you write the normal path, and let a faulty process die. A supervisor process notices and restarts it in a clean state.
  4. Hot code loading. A running system can load a new version of a module without stopping.

Erlang in one picture

Light processes Millions at once
Messages No shared memory
Supervisors Let it crash
Hot upgrades No downtime

These four ideas explain almost every design choice in Erlang.

1 / 2

The BEAM

Erlang code is compiled to bytecode and executed by a virtual machine called the BEAM (Bogdan's Erlang Abstract Machine, named after an early implementer). The BEAM includes a scheduler for the processes, a garbage collector that works per process, and the tools for distribution across several machines. Other languages, such as Elixir and Gleam, compile to the BEAM too and can call Erlang libraries directly.

Because each process has its own heap, garbage collection of one process never pauses the others. This is one reason Erlang systems have steady, predictable response times.

flowchart LR
    A["Erlang source (.erl)"] --> B["erlc compiler"]
    B --> C["BEAM bytecode (.beam)"]
    C --> D["BEAM virtual machine"]
    D --> E["Scheduler runs many processes"]

From source file to running processes.

Erlang, OTP and the shell

People often say "Erlang" when they mean three things at once:

  • The language: syntax, data types, pattern matching.
  • The BEAM runtime: the virtual machine and its scheduler.
  • OTP (Open Telecom Platform): a standard library of ready-made patterns such as gen_server for servers and supervisor for restart strategies. Despite the name, OTP is useful far outside telecom. You will meet it in the chapter on Fault Tolerance and OTP.

A first look at the syntax

Here is a complete Erlang module. Do not worry about the details; each piece gets its own lesson.

ERLANG
-module(greeter).
-export([hello/1]).

hello(Name) ->
    io:format("Hello, ~s!~n", [Name]).

Three things to notice already. Statements end with a period (.) and clauses are separated by semicolons. Variable names start with an uppercase letter (Name). Lowercase words such as greeter and hello are atoms, names that stand for themselves.

A stand-in for the process idea

The code below is JavaScript, not Erlang. It imitates the central idea of Erlang: an actor with a private mailbox that handles one message at a time. In real Erlang you would write Pid ! {greet, "Ada"} and the runtime does the rest.

JS Stand-in: a mailbox actor (JavaScript, not Erlang)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that the last console.log appears first: sending a message never waits for the receiver. Erlang's ! operator behaves the same way. Sending is asynchronous.

JS Stand-in: why isolation matters (JavaScript, not Erlang)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

What Erlang is not

Erlang is not the fastest language for number crunching; heavy math belongs in C or in Rust called through ports. It is not object-oriented, and it has no loops: you use recursion and functions like lists:map/2. Its strings are lists of integers, which is flexible but takes more memory than you may expect. Erlang is strongest where many independent activities run at once and reliability matters more than raw speed.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why was Erlang created?

    Ericsson built Erlang for telecom switches that handle many calls at once and must run without downtime.
  2. 2. How do Erlang processes communicate?

    Processes share nothing. They exchange messages, and the data is copied from the sender to the receiver.
  3. 3. What does the BEAM do?

    The BEAM executes the bytecode in .beam files and schedules the lightweight processes.
  4. 4. What does 'let it crash' mean?

    You write the normal path, and supervisors restart failed processes in a clean state.

Summary

  • Erlang is a functional language and runtime made for highly concurrent, fault-tolerant systems.
  • Processes are lightweight, isolated and communicate only with messages.
  • Supervisors restart failed processes; the philosophy is "let it crash".
  • The BEAM virtual machine runs the compiled code; OTP provides standard patterns.
  • Erlang has no loops and no objects; you use recursion and pattern matching.

Next: The Erlang Shell