DEV Community

Arhan Khan
Arhan Khan

Posted on

Erlang for Beginners: Build Systems That Never Stop

Erlang was built in the 1980s at Ericsson to run telephone switches — systems that must never go down. WhatsApp famously ran on Erlang, handling hundreds of millions of users with a tiny engineering team. The language's ideas are now everywhere (Elixir runs on the same virtual machine), but Erlang itself is still the purest expression of them.

The core idea is the actor model. Your program is made of thousands of lightweight processes that share no memory and talk only by sending messages. If one process crashes, a supervisor restarts it, and the rest of the system keeps running. Here is the shape of it:

%% a process that counts messages, forever
counter(N) ->
    receive
        {add, X} -> counter(N + X);
        {get, From} ->
            From ! {count, N},
            counter(N)
    end.
Enter fullscreen mode Exit fullscreen mode

No locks, no shared state, no race conditions in the usual sense. A process is so cheap — a few hundred bytes — that spawning 100,000 of them is normal. And hot code reloading means you can update a running system without stopping it, which is why telephone switches (and WhatsApp) could stay up for years.

Erlang is a good fit for messaging systems, chat servers, IoT backends, and anything that must stay up and handle many simultaneous connections. If you build real-time systems, Erlang's fault-tolerance model is worth studying even if you end up using Elixir or Go.

The limits: Erlang's syntax is unusual (it looks like Prolog), the ecosystem is small, and jobs are rare. The tooling is less polished than mainstream languages, and Erlang is a poor choice for number crunching or user interfaces. Most people today learn these ideas through Elixir, which shares the VM but has friendlier syntax.

Start today: install Erlang/OTP, open the shell with erl, and spawn two processes that send messages to each other. Then read about supervisors — the "let it crash" philosophy is the most useful idea in the language. Even if you never ship Erlang, it will change how you design systems that must not fail.

Top comments (0)