0Pricing
Erlang OTP: Distributed & Fault-Tolerant Systems Programming · Lesson

Supervisor Bridges & Mixed Process Hierarchies

Integrate non-OTP processes and external subsystems into your supervision tree using supervisor_bridge, keeping fault tolerance intact.

Supervisor Bridges & Mixed Process Hierarchies is a free Erlang OTP: Distributed & Fault-Tolerant Systems Programming lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Erlang OTP: Distributed & Fault-Tolerant Systems Programming learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why a Supervisor Bridge?

Not every process you depend on is a clean OTP gen_server. Sometimes you must supervise a plain Erlang process, a port, or a third-party subsystem. The supervisor_bridge behaviour lets such a process appear as a normal child in a supervision tree.

The Problem It Solves

A standard supervisor only knows how to start, stop and restart OTP-compliant children. A raw process started with spawn_link does not respond to OTP shutdown protocols. The bridge translates between the two worlds.

Behaviour Callbacks

A supervisor_bridge module implements two callbacks:

  • init/1 starts the real subsystem and returns its pid
  • terminate/2 cleanly shuts the subsystem down

Skeleton Module

The bridge is started like a supervisor but behaves like a worker to its parent.

-module(legacy_bridge).
-behaviour(supervisor_bridge).
-export([start_link/0, init/1, terminate/2]).

start_link() ->
    supervisor_bridge:start_link({local, ?MODULE}, ?MODULE, []).

Implementing init/1

init/1 must start and link the external process, then return {ok, Pid, State}. If start fails, return {error, Reason}.

init([]) ->
    case legacy_server:start() of
        {ok, Pid} -> {ok, Pid, Pid};
        Error -> Error
    end.

Implementing terminate/2

When the bridge is asked to shut down, it calls terminate/2 so you can stop the subsystem gracefully.

terminate(_Reason, Pid) ->
    legacy_server:stop(Pid),
    ok.

Placing the Bridge in a Tree

To its parent supervisor, the bridge is just another child spec with type => worker.

ChildSpec = #{id => legacy,
              start => {legacy_bridge, start_link, []},
              restart => permanent,
              type => worker}.

Failure Propagation

Because the bridge links to the external process, a crash there exits the bridge, which the parent supervisor sees as a normal worker crash and restarts according to its strategy.

Mixed Hierarchies

A real system mixes gen_server workers, sub-supervisors, and bridges. The bridge lets legacy or foreign code participate without weakening the OTP guarantees of the rest of the tree.

When NOT to Use a Bridge

If you can wrap the subsystem in a proper gen_server, prefer that — it gives you full OTP introspection. Reserve the bridge for code you cannot rewrite or that has its own process lifecycle.

Debugging Bridged Subsystems

Because the inner process is not OTP, tools like sys:get_state/1 will not reach it. Add logging inside the subsystem and rely on the bridge state to track the inner pid.

Quick Check

Test your understanding of supervisor bridges.

Recap

You learned to integrate foreign processes into supervision trees:

  • supervisor_bridge wraps non-OTP subsystems
  • init/1 starts and links the subsystem; terminate/2 stops it
  • It appears as a worker child to its parent supervisor
  • Crashes propagate so normal restart strategies apply
  • Prefer a real gen_server when you control the code

Frequently asked questions

Is the “Supervisor Bridges & Mixed Process Hierarchies” lesson free?

Yes — the full text of “Supervisor Bridges & Mixed Process Hierarchies” is free to read here on the web, and the Erlang OTP: Distributed & Fault-Tolerant Systems Programming course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Erlang OTP: Distributed & Fault-Tolerant Systems Programming course, upgrade to CoddyKit PRO.

What will I learn in “Supervisor Bridges & Mixed Process Hierarchies”?

Integrate non-OTP processes and external subsystems into your supervision tree using supervisor_bridge, keeping fault tolerance intact. You practise Erlang OTP: Distributed & Fault-Tolerant Systems Programming with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Erlang OTP: Distributed & Fault-Tolerant Systems Programming?

No prior experience is required. Erlang OTP: Distributed & Fault-Tolerant Systems Programming on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Supervisor Bridges & Mixed Process Hierarchies” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Erlang OTP: Distributed & Fault-Tolerant Systems Programming lesson?

Yes. Every Erlang OTP: Distributed & Fault-Tolerant Systems Programming lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Complex Supervision Trees
  2. Dynamic Process Management
  3. Advanced Restart Strategies
  4. Supervisor Bridges & Mixed Process Hierarchies
← Back to Erlang OTP: Distributed & Fault-Tolerant Systems Programming