Let it crash is not "ignore errors". It is the opposite

Every Erlang tutorial mentions "let it crash", usually in a sentence that makes it sound reckless. Do not handle errors. Let the process die. Something will restart it.

Put that in front of anyone who has operated a production system and you get a reasonable objection: that is not a philosophy, that is giving up. Which is fair, because the slogan is a bad summary of the idea.

Here is the better one. Error recovery belongs in code whose only job is error recovery. Everything else should state what it expects and stop immediately if it does not get it.

The code this replaces

Start with what defensive programming actually looks like once a few error cases have accumulated. This is a function that reads a config file, parses it, validates it and applies it, written the way most languages encourage:

apply_config(Path) ->
    case file:read_file(Path) of
        {ok, Binary} ->
            case parse(Binary) of
                {ok, Parsed} ->
                    case validate(Parsed) of
                        {ok, Config} ->
                            case apply(Config) of
                                ok         -> ok;
                                {error, E} -> {error, {apply_failed, E}}
                            end;
                        {error, E} -> {error, {invalid, E}}
                    end;
                {error, E} -> {error, {parse_failed, E}}
            end;
        {error, enoent} -> {error, no_config};
        {error, E}      -> {error, {read_failed, E}}
    end.

Four levels of nesting, and the shape of the happy path is now impossible to see. But the nesting is the cosmetic problem. There are three real ones.

It returns an error tuple to a caller that has no idea what to do with it. {error, {parse_failed, badarg}} goes up to something that was trying to start a server. What is that caller supposed to do? In practice it adds its own case, wraps the error in another tuple, and passes it up again. The error travels through five functions, accumulating layers, and is eventually logged by something that has lost all the context in which it made sense.

It makes failure a normal return value. apply_config/1 now has two kinds of result and every caller must remember to distinguish them. Miss one — write apply_config(Path), carry_on() — and the program continues with no config at all, in a state nobody designed. Nothing crashed. Nothing was logged. It just quietly does the wrong thing.

It only handles what the author imagined. parse/1 might also throw. The disk might be full. The file might be a directory. Each of those escapes this careful structure anyway, so all the nesting bought is coverage of the cases somebody thought of in advance.

What the same function looks like in Erlang

apply_config(Path) ->
    {ok, Binary} = file:read_file(Path),
    {ok, Parsed} = parse(Binary),
    {ok, Config} = validate(Parsed),
    ok           = apply(Config).

Four lines. The happy path is the only path, which makes it readable. And every line is an assertion: if file:read_file/1 returns {error, enoent}, the match against {ok, Binary} fails, and the process dies right there with a badmatch and a stack trace naming the line and the actual value.

That is not an error being ignored. That is an error being detected at the first possible moment, reported with full context, and refusing to let execution continue in a state the author did not intend.

Compare what you get in your logs. From the defensive version: {error, {parse_failed, badarg}}, logged five functions away from where it happened, with the stack long since unwound. From this one: the exact line, the exact value that did not match, the full call stack, and the state of the process when it happened.

The part that makes it work

If the story ended there it would be a trick for writing shorter code while making outages more likely. It does not, and this is the half the slogan leaves out.

The process that just died was a child of a supervisor — a process whose entire job is to notice that and start a replacement from a known-good initial state. There is no business logic in it at all. It contains a list of children, a restart strategy, and a limit.

init([]) ->
    SupFlags = #{strategy => one_for_one, intensity => 3, period => 60},
    Children = [#{id    => config_server,
                  start => {config_server, start_link, []},
                  restart => permanent}],
    {ok, {SupFlags, Children}}.

The restart is the recovery, and it is complete in a way try/catch can never be. A caught exception leaves you in the middle of a function with some work done and some not, holding whatever half-updated state existed when things went wrong, and you have to reason about what to clean up. A restarted process begins at init/1 with nothing carried over. There is no partially-applied state to reason about, because there is no state at all.

This is why Erlang's answer is more thorough than the defensive one rather than less. Defensive code tries to continue in a damaged state. Erlang refuses to.

And the limit is the part people miss

intensity => 3, period => 60 says: if this supervisor restarts children more than three times in a minute, give up and terminate — which is itself an abnormal exit, seen by its supervisor, which may restart a larger subtree.

That escalation is the whole design, and it is what makes the strategy honest rather than a loop that pretends to be working.

Think about what it does to the config example. The file is corrupt. The process crashes, is restarted, reads the same corrupt file, crashes again. Without a limit that is an infinite loop burning a core. With one, the supervisor gives up after three attempts and escalates to its parent — which supervises both the config server and whatever fetches configuration from the network. Restarting that whole branch re-fetches the file. If the problem persists, that supervisor exceeds its own limit, and eventually the application stops, loudly, having tried every level of recovery available to it.

A node that cannot start is much better than a node that appears to be running and is serving nothing. Defensive code gives you the second one.

Where the line actually falls

So does an Erlang program never handle errors? Of course it does. The distinction is between errors that are expected and errors that are exceptional, and the test is simple: do you have a specific, sensible action for this case?

A user submitting a withdrawal larger than their balance is expected. That is not a fault, it is a normal outcome of a banking system, and the answer is to reply with it:

handle_call({withdraw, Amount}, _From, State)
        when Amount =< State#state.balance ->
    {reply, {ok, State#state.balance - Amount}, ...};

handle_call({withdraw, _}, _From, State) ->
    {reply, {error, insufficient_funds}, State}.

No crash. The account is valid, the request was not, and the server carries on. Equally: a cache miss, a timeout you intend to retry, a file you can create if it is missing, a validation failure you are going to show the user. These all have answers and so they get handled.

A corrupt binary where a protocol frame should be, a gen_server that got a message no clause covers, a disk error on a write that was supposed to succeed — these have no sensible local answer. Handling them means inventing one, and the invented answer is nearly always "log it and continue", which is how a system ends up running on bad data.

You are probably already doing this, badly

Here is the thing that makes the idea feel less exotic. If you run anything on Kubernetes, you have adopted let-it-crash already — you just did it at the worst possible granularity.

A liveness probe fails. The container is killed. A new one starts from a known-good image. A CrashLoopBackOff is restart intensity: after enough failures in a window, the system stops trying and escalates to a human. That is precisely the supervisor model, implemented by an orchestrator instead of by the language.

What differs is the unit and the cost. Kubernetes restarts a whole process, which takes seconds, drops every in-flight request it was serving, and loses all of its state. Erlang restarts one process out of a million, in microseconds, affecting nothing else on the node — the other connections do not notice, and the supervisor above it decides whether anything else needed resetting too.

Same philosophy, five or six orders of magnitude apart in blast radius. Which is why an Erlang node can lose a thousand processes a second and keep its availability numbers, and a pod cannot lose itself once without someone seeing a graph.

It also explains why the slogan sounds irresponsible when you first hear it and sensible once you have operated a system. Everyone accepts "restart the container" as sound engineering. "Restart the function call" is the same sentence, applied where the failure actually happened.

When it goes wrong

There are three reliable ways to get this wrong, and all three come from applying half the idea.

A supervisor with no limit, or one so high it never triggers. The restarts become an infinite loop, the logs fill with the same stack trace, and nothing escalates. The system looks alive and does nothing. The limit is not a tuning parameter you can leave at a default and ignore; it is the mechanism by which failure becomes visible.

A catch-all that swallows everything. Writing handle_info(_, State) -> {noreply, State} is correct and necessary — it stops a stray message crashing the server. Writing the same thing in handle_call for every unmatched request is not: you have now rebuilt the defensive version inside the behaviour, and the server will happily run forever while answering nothing. Log what you did not expect. A catch-all that is silent is the worst of both designs.

State that cannot survive a restart. A process holding the only copy of something expensive, under a supervisor that restarts it cheerfully, is a design that loses data on the first crash. The crash is not the bug; putting irreplaceable state somewhere restartable is. ETS owned by a longer-lived process, disk, or a parent that passes it back in — pick one deliberately.

The honest objections

This does not transfer wholesale, and it is worth being clear about why.

It depends on cheap processes and total isolation. A BEAM process costs about 300 words and starts in microseconds, and shares no memory with any other — so killing one is genuinely safe and genuinely cheap. In a language where the unit of failure is a thread sharing a heap, or the whole OS process, "let it crash" means something very different and much worse.

It depends on state you can afford to lose, or keep elsewhere. A restart wipes the process's state. If that state was expensive to build, you need it in ETS owned by another process, on disk, or passed back in — and deciding which is real design work that the slogan does not mention.

And it is not a licence to skip input validation. Crashing on malformed input from the network, on a process per connection, is fine. Crashing the process that holds a connection pool because somebody sent a bad byte is not. Where the crash lands in your supervision tree is the design, and it is the part that takes judgement.

What it actually is

Joe Armstrong's thesis is called Making reliable distributed systems in the presence of software errors, and that last clause is the premise. Not "in the absence of" — software has bugs, and the ones left in a mature system are by definition the ones nobody anticipated. You cannot handle them in advance, because if you could imagine them you would have fixed them.

So the question Erlang asks is not "how do we prevent failure", but "what should happen when something fails in a way nobody predicted". Defensive programming's answer is to continue in an undefined state. Erlang's is to kill the affected piece, restart it clean, escalate if that does not work, and keep the rest of the system serving throughout.

That is a strictly more rigorous answer than the one it replaces. It only sounds casual because somebody shortened it to three words.

erlang otp fault tolerance error handling supervisors let it crash