The Complete Erlang Guide: From Zero to Expert

a close up of a computer screen with code on it

The Complete Erlang Guide: From Zero to Expert

Erlang is a functional programming language designed for building massively scalable, real-time systems with exceptional uptime. It excels in concurrency, distribution, and fault tolerance, making it the bedrock for telecom, banking, and instant messaging applications through its powerful OTP framework.

You’ve probably been there. You deploy a new service, and it works beautifully... until the traffic spikes. Suddenly, requests time out, the server crashes, and you're left scrambling to restart everything, praying it holds this time. The traditional approach of defensive programming, wrapping everything in `try-catch` blocks, feels like patching a leaking ship with duct tape. What if there was a fundamentally different way to build systems that are not just robust, but actively anti-fragile? A way to build software that expects failure and heals itself automatically?

This is not a futuristic dream; it's the reality that Erlang has provided for over three decades. Born from the demanding world of telecommunications at Ericsson, where systems needed to run uninterrupted for years, Erlang was built on a philosophy that is radically different from mainstream languages. It's a language designed for concurrency and fault tolerance from the ground up. This guide is your comprehensive roadmap to mastering Erlang, taking you from the basic syntax to architecting self-healing, massively concurrent systems using the legendary OTP framework, all based on the exclusive kodikra.com learning curriculum.


What is Erlang? The Language of Nine Nines Availability

Erlang is a general-purpose, concurrent, functional programming language and a garbage-collected runtime system. The name is an acronym for ERicsson LANGuage, but it's also a nod to the Danish mathematician Agner Krarup Erlang, who pioneered the field of traffic engineering—a fitting tribute for a language designed to manage communication systems.

Developed by Joe Armstrong, Robert Virding, and Mike Williams in the mid-1980s, its primary goal was to improve the development of telephony applications. These systems have incredibly strict requirements: high availability, massive scalability, and the ability to be updated without being taken offline. Erlang was designed to meet these needs, and its core features directly reflect this heritage.

The BEAM Virtual Machine: Erlang's Secret Weapon

Erlang code doesn't run directly on your machine's OS. Instead, it compiles down to bytecode that runs on a virtual machine called the BEAM (Bogdan's/Björn's Erlang Abstract Machine). The BEAM is a masterpiece of engineering responsible for many of Erlang's most famous features:

  • Lightweight Processes: An Erlang "process" is not an OS process. It's an extremely lightweight thread of execution managed by the BEAM. You can have millions of them running on a single machine, each with its own isolated memory, without breaking a sweat.
  • Preemptive Scheduler: The BEAM's scheduler is preemptive. It ensures that every process gets a small slice of CPU time, preventing any single process from hogging resources and making the system unresponsive. This is crucial for soft real-time systems.
  • Garbage Collection Per Process: Unlike languages like Java where a "stop-the-world" garbage collection can pause the entire application, Erlang's garbage collection happens on a per-process basis. This means the system as a whole remains responsive, as only one tiny process is paused at a time.

The "Let It Crash" Philosophy

Perhaps the most iconic concept in the Erlang world is the "Let It Crash" philosophy. Instead of writing complex defensive code to handle every possible error within a function, Erlang encourages you to write "happy path" code. If something unexpected happens, the process is allowed to crash quickly and cleanly.

This isn't chaos; it's a controlled strategy. Crashes are contained within isolated processes. A special type of process, called a Supervisor, is responsible for monitoring other processes (called workers). If a worker crashes, the supervisor's job is to restart it in a clean, known-good state. This creates self-healing systems that are incredibly resilient to runtime errors.

    ● Supervisor
    │
    ├─ Monitoring ─▶ ◆ Worker Process 1
    │                │ (Running Task A)
    │                └─────────┬─────────┘
    │                          │
    ├─ Monitoring ─▶ ◆ Worker Process 2
    │                │ (Running Task B)
    │                └─────────┬─────────┘
    │                          │
    └─ Monitoring ─▶ ◆ Worker Process 3
                     │ (Running Task C)
                     │
                     ▼
                  💥 CRASH! (e.g., bad input)
                     │
    ┌────────────────┘
    │
    ▼
  ┌─────────────┐
  │ Supervisor  │
  │ Detects     │
  │ Crash       │
  └──────┬──────┘
         │
         ▼
  ┌─────────────┐
  │ Restart     │
  │ Process 3   │
  │ in a clean  │
  │ state       │
  └──────┬──────┘
         │
         ▼
    ● System Healed
      (Processes 1 & 2 were unaffected)

Why Learn Erlang? The Unfair Advantage in a Concurrent World

In an era of multi-core processors, distributed microservices, and IoT devices, the problems Erlang was built to solve are more relevant than ever. While languages like Go, Rust, and Java have added concurrency features, Erlang has had them at its core for decades. This deep integration provides a unique and powerful development experience.

Unmatched Concurrency with the Actor Model

Erlang's concurrency is based on the Actor Model. An "actor" is a process that communicates with other actors by sending and receiving asynchronous messages. Key characteristics include:

  • Complete Isolation: Processes share no memory. The only way to exchange information is by sending a message. This eliminates an entire class of bugs related to race conditions and deadlocks that plague shared-state concurrency models.
  • Asynchronous Communication: Sending a message is non-blocking. A process can send a message and immediately continue with its work without waiting for a response.
  • Location Transparency: It doesn't matter if the process you're sending a message to is on the same machine or on a different continent. The code for sending the message is exactly the same. This makes building distributed systems astonishingly simple.
  ┌──────────────┐         ┌──────────────┐
  │  Process A   │         │  Process B   │
  │  (PID: 0.101)│         │  (PID: 0.102)│
  └──────┬───────┘         └──────┬───────┘
         │                        │
         │ Executes Logic         │ Executes Logic
         │                        │
         ▼                        │
  ┌──────────────┐                │
  │  Needs data  │                │
  │  from B      │                │
  └──────┬───────┘                │
         │                        │
         │ Send Message           │
         │ {self(), {request}}    │
         └───────────⟶            │
                                  ▼
                            ┌──────────────┐
                            │ Mailbox of B │
                            │ 📥           │
                            └──────────────┘
                                  │
                                  │ Receives Message
                                  │
                                  ▼
                            ┌──────────────┐
                            │ Process      │
                            │ Message      │
                            └──────┬───────┘
                                   │
                                   │ Send Reply
                                   │ {PidA, {reply}}
                        ⇜──────────┘
         │
         ▼
  ┌──────────────┐
  │ Mailbox of A │
  │ 📥           │
  └──────────────┘
         │
         │ Receives Reply
         │
         ▼
    ● Continue

Extreme Fault Tolerance and High Availability

The combination of supervisors and isolated processes allows for systems with incredible uptime, often referred to as "nine nines" (99.9999999%) availability. This translates to just milliseconds of downtime per year. Another powerful feature is Hot Code Swapping, which allows you to update the code in a running system without stopping it—a critical feature for services that cannot afford any downtime.

Scalability: Vertical and Horizontal

Erlang scales effortlessly in two ways:

  1. Vertically: The BEAM VM is designed to use all available CPU cores on a machine efficiently, distributing the load of its lightweight processes across them automatically.
  2. Horizontally: Thanks to location transparency, you can easily distribute your Erlang application across a cluster of machines. The system behaves like a single, cohesive unit, a concept known as an "Erlang cluster."

Who Uses Erlang? Industry Titans and Innovators

Erlang isn't just an academic language; it powers some of the most demanding applications on the planet. Its robustness has made it a trusted choice for industries where failure is not an option.

  • WhatsApp: Famously used Erlang to scale their messaging backend to handle billions of messages per day with a very small team of engineers.
  • Ericsson: As the creator, Ericsson uses Erlang extensively in its telecom switches and network control nodes, which form the backbone of global mobile networks.
  • Klarna: The fintech giant uses Erlang for its core payment processing systems, relying on its reliability and fault tolerance for financial transactions.
  • - Riot Games: The company behind League of Legends uses Erlang for its in-game chat system and other real-time communication services to handle millions of concurrent players.
  • Cisco: Utilizes Erlang in its routers and cloud communication platforms for high-throughput, reliable message routing.
  • Bet365: One of the world's largest online betting companies uses Erlang to handle the massive concurrency and real-time demands of its platform.

This is just a small sample. The common thread is the need for systems that are concurrent, distributed, and highly available. The principles of Erlang are also the foundation for the popular language Elixir and its web framework Phoenix, which have brought the power of the BEAM to a new generation of developers.


How to Get Started with Erlang

Getting your Erlang development environment set up is straightforward. We recommend using a version manager like `asdf` to easily switch between different Erlang/OTP versions.

1. Installation

Using `asdf-vm` is the most flexible way to manage Erlang and other language installations.


# First, install asdf (instructions on asdf-vm.com)

# Add the Erlang plugin
asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git

# Install required dependencies (example for Ubuntu/Debian)
sudo apt-get -y install build-essential autoconf m4 libncurses5-dev libwxgtk3.2-dev libwxgtk-webview3.2-dev libgl1-mesa-dev libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev xsltproc fop libxml2-utils libssl-dev

# List all available Erlang versions
asdf list-all erlang

# Install the latest stable version (e.g., 27.0)
asdf install erlang 27.0

# Set the global version
asdf global erlang 27.0

After installation, verify it by opening the Erlang shell:


$ erl
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Eshell V15.0 (abort with ^G)
1>

You can exit the shell by typing q(). or pressing Ctrl+C twice.

2. Your First Erlang Program: Hello World

Erlang code is organized into modules. Let's create a file named hello.erl.


-module(hello).
-export([start/0]).

start() ->
    io:format("Hello, world!~n").

To compile and run this:

  1. Start the Erlang shell: erl
  2. Inside the shell, compile the module: c(hello).
  3. Run the exported function: hello:start().

1> c(hello).
{ok,hello}
2> hello:start().
Hello, world!
ok

3. Essential Tooling

  • Rebar3: This is the official build tool for Erlang. It handles dependencies, compilation, testing, and releases. It is the equivalent of `cargo` for Rust or `npm` for Node.js. You'll use it for any non-trivial project.
  • IDE/Editor Setup: Visual Studio Code with the "Erlang LS" extension is the recommended setup. It provides syntax highlighting, code completion, debugging, and integration with `rebar3`.

The Erlang Learning Roadmap: A Structured Path

Our curriculum is designed to guide you step-by-step through the world of Erlang and OTP. Each module builds upon the last, ensuring a solid foundation before moving on to more complex topics. This is the official learning path for Erlang on kodikra.com.

Stage 1: The Core Language

This stage focuses on the fundamental syntax and data structures of the Erlang language itself, without touching on concurrency yet.

  • Module 1: Foundations & Syntax

    Start your journey here. You'll learn about Erlang's immutable variables, its basic data types like atoms, tuples, and lists, and how to perform basic arithmetic and list operations. This module sets the groundwork for everything to come.

  • Module 2: Control Flow & Functions

    Discover Erlang's unique approach to control flow. Master pattern matching, the powerful `case` statement, and function guards. You will also learn how to define and use anonymous functions (funs), a cornerstone of functional programming.

  • Module 3: Code Organization with Modules and Records

    Learn how to structure your code cleanly using modules. This module introduces records for creating structured data types, similar to structs in other languages, and explores how to define and export functions to create a public API for your module.

Stage 2: The Concurrency Model

Now we dive into the heart of what makes Erlang special: its model for concurrency and communication.

  • Module 4: Concurrency Fundamentals

    This is where the magic begins. You'll learn how to spawn thousands of lightweight processes, understand process identifiers (PIDs), and use the `!` (send) and `receive` constructs to pass messages between them. This is the raw power of the Actor Model.

  • Module 5: Error Handling & Fault Tolerance

    Embrace the "Let It Crash" philosophy. Learn about process linking and monitoring to detect when a process fails. This module covers the different exit signals and how to build simple, resilient systems by separating the code that does the work from the code that supervises it.

Stage 3: The OTP Framework

The Open Telecom Platform (OTP) is a set of libraries and design principles that provide battle-tested abstractions for building robust, production-ready systems.

  • Module 6: OTP Behaviours - GenServer and Supervisor

    Move from raw processes to industry-standard abstractions. You will master `GenServer`, the workhorse for creating client-server logic within a process, and `Supervisor`, the key to building self-healing supervision trees that automatically restart failed components.

  • Module 7: Building Real Applications with Rebar3

    It's time to build a complete application. Learn how to use the `rebar3` build tool to manage dependencies, structure an OTP application, write tests, and create a final release. This module bridges the gap between theory and production-ready code.

  • Module 8: The BEAM Ecosystem and Advanced Topics

    Explore the wider ecosystem. This module provides an overview of Mnesia (Erlang's built-in distributed database), interoperability with Elixir, and advanced concepts like Native Implemented Functions (NIFs) for integrating C code when you need maximum performance.


Erlang: Pros, Cons, and Future Trends

No language is a silver bullet. Understanding Erlang's strengths and weaknesses is key to knowing when to use it.

Erlang's Strengths and Weaknesses

Pros (Strengths) Cons (Weaknesses)
Massive Concurrency: Can handle millions of lightweight processes with ease. Unfamiliar Syntax: The Prolog-inspired syntax can be a hurdle for developers coming from C-style languages.
Extreme Fault Tolerance: The supervisor/worker model creates self-healing systems. Niche Ecosystem: The library ecosystem is smaller compared to giants like Python or JavaScript.
High Availability: Hot code swapping and robust error handling lead to incredible uptime. CPU-Intensive Tasks: Not the best choice for heavy number-crunching or "long-running" single-threaded tasks. Better to offload to a NIF or another service.
Distributed by Nature: Built-in features make creating distributed clusters straightforward. String Handling: Historically, string manipulation was considered cumbersome, though recent OTP versions have made significant improvements.
Mature & Stable: Over 30 years of development and use in production systems. Steeper Learning Curve: The functional paradigm and OTP principles require a shift in thinking.

Future-Proofing Your Skills: Erlang in the Modern Era

The demand for concurrent and fault-tolerant systems is only growing. The rise of IoT, 5G networks, microservice architectures, and real-time applications like multiplayer games and financial trading platforms means Erlang's core strengths are more valuable than ever.

Furthermore, the BEAM ecosystem is vibrant. The success of Elixir, a modern language built on the BEAM, has brought renewed attention and new libraries to the platform. Learning Erlang not only gives you a powerful tool but also a deep understanding of the principles that make Elixir and other BEAM languages possible. Expertise in the BEAM is a highly sought-after and future-proof skill.


Frequently Asked Questions (FAQ)

1. Is Erlang still relevant?
Absolutely. While not as mainstream as Python or Java, Erlang's relevance is growing in areas that require massive concurrency and high reliability, such as IoT, fintech, messaging platforms, and distributed databases. Its principles have heavily influenced modern languages like Go and frameworks like Akka.
2. Is Erlang hard to learn?
Erlang has two learning curves. The basic functional syntax is relatively simple and can be picked up quickly. The more challenging part is mastering the OTP principles and learning to "think in Erlang"—designing systems around processes, messages, and supervisors. Our structured kodikra learning path is designed to make this transition smooth.
3. What is the difference between Erlang and Elixir?
Elixir is a newer language that also runs on the BEAM virtual machine. It was designed to provide a more modern, Ruby-inspired syntax and a stronger focus on developer productivity and metaprogramming. Elixir and Erlang are fully interoperable. Learning Erlang gives you a fundamental understanding of the platform that powers both.
4. What is OTP?
OTP (Open Telecom Platform) is often called Erlang's "standard library" but it's much more. It's a collection of battle-tested libraries, tools, and design principles (behaviours like `GenServer` and `Supervisor`) for building production-grade, fault-tolerant systems. Using OTP is the standard way to write professional Erlang code.
5. What exactly is the BEAM?
The BEAM is the Erlang runtime system, or virtual machine. It's responsible for scheduling millions of processes, managing memory with per-process garbage collection, and handling distributed communication. It's the magic that makes Erlang's concurrency and fault tolerance possible.
6. Can I use Erlang for web development?
Yes. While not as common as frameworks like Django or Rails, Erlang has its own powerful web frameworks, most notably Chicago Boss and the Cowboy web server (which is the foundation for Elixir's Phoenix framework). It excels at handling a massive number of persistent connections, making it ideal for WebSockets, APIs, and real-time applications.
7. What are Erlang processes and how do they differ from OS threads?
Erlang processes are extremely lightweight, memory-isolated units of concurrency managed by the BEAM, not the operating system. They have a tiny memory footprint (a few KBs) and context switching between them is incredibly fast. This is why you can run millions of them, whereas you can typically only run a few thousand OS threads on the same hardware.

Conclusion: Build Systems That Don't Break

Learning Erlang is more than just adding another language to your resume; it's about fundamentally changing the way you think about software architecture. You move from a defensive mindset of preventing errors to an offensive one of containing and recovering from them. You learn to build systems that are not just robust, but truly resilient—systems that heal themselves and scale effortlessly to meet demand.

The world needs more developers who understand these principles. Whether you're building the next big messaging app, a high-frequency trading platform, or the backend for a massive IoT network, the lessons from Erlang and OTP will give you a significant competitive edge. We invite you to begin this journey with our comprehensive learning path and discover the power of building systems the Erlang way.

Disclaimer: All code examples and recommendations are based on Erlang/OTP version 27.0 and later. While many concepts are backward-compatible, we always recommend using the latest stable version for new projects.


Published by Kodikra — Your trusted Erlang learning resource.