liveBook · Manning

restartWithBackoff

As explained in Akka in Action, Second Edition

restartWithBackoff is an Akka supervision strategy that restarts an actor after exponentially increasing delays bounded by configured minimum and maximum backoff intervals.

restartWithBackoff supervises an actor that fails while depending on an external service. It recreates the actor after an exponentially increasing delay, bounded by minimum and maximum intervals, instead of retrying continuously. section 5.3.3

The strategy combines actor restart semantics with controlled recovery:

  • A failing actor receives PreRestart, is re-created and reinitialized, and otherwise remains the same to the rest of the system. section 5.3.3
  • Standard actor state is lost during restart; persistent actors can maintain state through more difficult failures. section 5.3.3
  • The delay grows exponentially between configured minimum and maximum backoff values, while randomization reduces synchronized reconnection spikes. section 5.3.3
  • Persistence failures can restart an event-sourced actor while preserving commands buffered during persistence. section 9.2.3

Recovering from persistence failure

An EventSourcedBehavior can use onPersistFailure with minBackoff = 10.seconds, maxBackoff = 60.seconds, and randomFactor = 0.1. Recovery attempts begin after roughly 10 seconds, then increase through 20, 30, 40, and 50 seconds up to the 60-second maximum. section 9.3.1

EventSourcedBehavior[Command, Event, State](
  persistenceId = ...,
  emptyState = ...,
  commandHandler = ...,
  eventHandler = ...,
).onPersistFailure(                           #1
    SupervisorStrategy.restartWithBackoff(
       minBackoff = 10.seconds, 
       maxBackoff = 60.seconds, 
       randomFactor = 0.1))

Use the configuration listing to inspect restartWithBackoff applied to EventSourcedBehavior.onPersistFailure. section 9.3.1

How Akka in Action, Second Edition covers it

How deep it goes
Explains restart lifecycle, state loss, exponential delays, jitter, and persistent-command preservation through a concrete configuration.
Examples
Uses an EventSourcedBehavior example with ten-second initial backoff, sixty-second maximum backoff, and ten-percent randomization.
What it assumes
Assumes familiarity with actors and failures while explaining restart state loss and persistent recovery behavior.
What you can do after
Operate/configure Akka supervision to restart actors with bounded exponential delays and randomized recovery attempts.
How it connects
Connects actor supervision with persistence, event sourcing, and command stashing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.