Erlang
A functional, concurrent programming language designed for building massively scalable, fault-tolerant distributed systems - the backbone of telecommunications and messaging platforms like WhatsApp.
Created by Joe Armstrong, Robert Virding, Mike Williams (Ericsson)
Erlang is a functional programming language designed from the ground up for building concurrent, distributed, and fault-tolerant systems. Created at Ericsson for telecommunications switches, it embodies the principle that software should handle failures gracefully rather than try to prevent them.
History & Origins
Erlang’s story begins in 1986 at Ericsson’s Computer Science Laboratory in Stockholm, Sweden. Joe Armstrong, Robert Virding, and Mike Williams were tasked with finding better ways to program telephone switches - systems that needed to handle millions of simultaneous calls, never go down, and be upgraded without service interruption.
The Problem: Telephone Switches
Traditional telephone switches had extreme requirements:
- 99.999% uptime (about 5 minutes downtime per year)
- Handling millions of concurrent calls
- Hot-swapping code without dropping calls
- Graceful degradation under failure
No existing language could meet these needs, so Armstrong’s team created their own.
From Prolog to Production
The first Erlang implementation was a Prolog interpreter (1987), reflecting Armstrong’s background in logic programming. The name “Erlang” is both a reference to mathematician Agner Krarup Erlang (who invented queuing theory for telephone networks) and a play on “Ericsson Language.”
By 1991, Erlang had its first compiled version using JAM (Joe’s Abstract Machine). The language evolved through real-world use on Ericsson’s AXD301 switch, which achieved legendary reliability.
The Open-Source Era
In 1998, Ericsson made a controversial decision to ban Erlang internally (preferring Java). Rather than let it die, the team convinced management to open-source it. This “Erlang ban” backfired spectacularly - the language found new life in the broader software community, and Ericsson eventually reversed course.
What Makes Erlang Different
1. Lightweight Processes (Not OS Threads)
Erlang processes are incredibly lightweight - you can spawn millions of them:
| |
Each process:
- Has its own heap and garbage collector
- Uses about 300 bytes of memory
- Is preemptively scheduled by the BEAM VM
- Cannot crash other processes
2. Message Passing (No Shared Memory)
Processes communicate only through message passing - there’s no shared mutable state:
| |
3. “Let It Crash” Philosophy
Instead of defensive programming with try/catch everywhere, Erlang embraces failure:
| |
This pattern, called “supervision trees,” means:
- Individual processes can crash without bringing down the system
- Supervisors restart failed processes automatically
- Complex systems self-heal
4. Hot Code Swapping
Change running code without stopping the system:
| |
| |
Compile and load the new version - running processes pick it up on their next function call.
5. Pattern Matching Everywhere
Pattern matching is fundamental to Erlang:
| |
6. Immutable Data
All data in Erlang is immutable - there’s no assignment, only binding:
| |
7. Distribution Built In
Erlang nodes can communicate transparently across machines:
| |
The same message-passing syntax works whether processes are local or remote.
The BEAM Virtual Machine
Erlang runs on the BEAM (Bogdan’s Erlang Abstract Machine), a sophisticated VM optimized for:
- Soft real-time performance - Consistent response times
- Massive concurrency - Efficient scheduling of millions of processes
- Garbage collection - Per-process GC means no global pauses
- Hot code loading - Upgrade code while running
- Distributed computing - Built-in clustering
The BEAM is why Erlang systems achieve remarkable reliability and why Elixir chose to run on it.
OTP: The Secret Weapon
OTP (Open Telecom Platform) is Erlang’s standard library and framework:
Behaviors (Design Patterns)
OTP provides battle-tested implementations of common patterns:
| |
Common behaviors include:
- gen_server - Client-server pattern
- gen_statem - Finite state machines
- supervisor - Process monitoring and restart
- application - Application packaging
Applications
Erlang organizes code into applications - self-contained units with:
- Supervision trees
- Configuration
- Dependency management
- Start/stop procedures
| |
Erlang vs Other Languages
| Feature | Erlang | Go | Java | Elixir |
|---|---|---|---|---|
| Concurrency Model | Actor (processes) | CSP (goroutines) | Threads | Actor (processes) |
| Shared State | None | Channels | Synchronized | None |
| Fault Tolerance | Built-in (OTP) | Manual | Frameworks | Built-in (OTP) |
| Hot Code Swap | Yes | No | Limited | Yes |
| Distribution | Native | Manual | Libraries | Native |
| Runtime | BEAM | Native | JVM | BEAM |
Common Patterns
Ping-Pong Example
The classic Erlang concurrency demonstration:
| |
Simple Key-Value Store
| |
The Erlang Shell
Erlang’s interactive shell is powerful for development:
| |
Useful shell commands:
c(module).- Compile and load a modulel(module).- Load a compiled modulem(module).- Module infoh().- Helpq().- Quit
Tooling
Build Tools
- rebar3 - Standard build tool (like Maven/Gradle)
- mix - If using with Elixir projects
- erlang.mk - Makefile-based alternative
Package Management
- hex.pm - Package repository (shared with Elixir)
- rebar3 - Dependency management
Development
- observer - GUI for monitoring running systems
- dialyzer - Static type analyzer
- debugger - Built-in graphical debugger
- common_test - Testing framework
Getting Started
Erlang files use the .erl extension. A minimal module:
| |
Compile and run:
| |
Or use escript for scripts:
| |
Why Learn Erlang Today?
- Understand concurrency - Erlang’s model influences modern languages
- Build reliable systems - OTP patterns apply everywhere
- Use Elixir better - Understanding Erlang deepens Elixir knowledge
- Career opportunities - High demand, limited supply of Erlang developers
- Think differently - Immutability and message-passing change how you design systems
The Future
While Erlang itself sees steady, conservative development, the BEAM ecosystem is thriving:
- Elixir brings modern tooling and syntax
- Gleam adds static typing
- BEAM languages share the same powerful runtime
The principles Erlang pioneered - actor model, supervision trees, “let it crash” - now appear in Akka (Scala/Java), Orleans (.NET), and influence Go and Rust designs.
Continue to the Hello World tutorial to write your first Erlang program.
Timeline
Notable Uses & Legacy
Handles billions of messages per day with just ~50 engineers using Erlang's concurrency model.
Ericsson
Powers telecommunications infrastructure with nine-nines (99.9999999%) availability in AXD301 switch.
RabbitMQ
Popular message broker written in Erlang, used by millions for reliable messaging.
Discord
Uses Erlang for real-time communication infrastructure serving millions of concurrent users.
Riak
Distributed NoSQL database designed for high availability and fault tolerance.
CouchDB
Document-oriented database with multi-master replication built on Erlang.
Language Influence
Influenced By
Influenced
Running Today
Run examples using the official Docker image:
docker pull erlang:alpineExample usage:
docker run --rm -v $(pwd):/app -w /app erlang:alpine escript hello.erl