Erlang / Erlang Basics Interview questions
How do you implement a simple supervision tree?
A supervision tree starts with a top-level supervisor whose init/1 callback
declares a restart strategy and a child specification list; each child can itself be a worker or another
supervisor, nesting arbitrarily deep.
init([]) -> SupFlags = #{strategy => one_for_one, intensity => 5, period => 10}, Children = [ #{id => cache_worker, start => {cache_worker, start_link, []}, restart => permanent, type => worker} ], {ok, {SupFlags, Children}}.
Starting the top supervisor with supervisor:start_link/3 automatically starts every declared
child in order. If cache_worker crashes, the one_for_one strategy restarts just that
child (up to 5 times per 10 seconds, per intensity/period); exceeding that threshold
escalates the crash to the supervisor's own parent.
More Related questions...