Go C#

Supervisor Strategy Recipes

Supervisors decide what to do when their children fail. The recipes below build on the core Supervision concepts with practical defaults.

Restart with backoff

Restarting too quickly can thrash the system. Apply exponential backoff and give up after repeated failures.

.NET

public override SupervisorStrategy SupervisorStrategy =>
    new OneForOneStrategy(
        maxNrOfRetries: 5,
        withinTimeRange: TimeSpan.FromSeconds(10),
        decider: ex => SupervisorDirective.Restart);

Go

var strategy = actor.NewOneForOneStrategy(5, time.Second*10, func(reason interface{}) actor.Directive {
    return actor.RestartDirective
})

Escalate critical faults

When a child cannot make progress (e.g. invalid configuration), escalate.

var strategy = new OneForOneStrategy(maxNrOfRetries:0, withinTimeRange:TimeSpan.Zero,
    decider: ex => SupervisorDirective.Escalate);

These patterns combine: escalate fatal errors and restart transient ones with backoff.

Icon