liveBook · Manning

Restart strategy

As explained in Akka in Action, Second Edition

A restart strategy terminates and recreates a failed actor while retaining its actor reference and mailbox for subsequent message processing.

A restart strategy is a supervision decision for an actor that fails while processing a message. The failed actor instance is removed and a new incarnation of the same behavior is created. Its ActorRef remains valid, so other actors keep sending through the same reference; the mailbox continues receiving messages for the replacement instance. section 5.1.2 section 5.3.3

Restart is a clean-state recovery choice: ordinary actor state is lost, unlike resume, which retains the existing instance and state. The message that caused the failure is normally not reprocessed, avoiding a poisoned mailbox where one corrupted input repeatedly prevents later work. section 5.1.2 section 5.3.1 section 5.3.3

Supervise an actor with restart

Wrap a behavior and choose restart for a selected failure type: Behaviors.supervise(behavior).onFailure[IndexOutOfBoundException](SupervisorStrategy.restart). On failure, processing is halted, the actor receives PreRestart, and setup code runs again when the new actor is spawned. section 5.3.3

Use restart deliberately around the failure boundary:

  • Choose restart when discarding in-memory actor state and rebuilding the actor is safer than continuing after an exception. section 5.3.1 section 5.3.3
  • Handle only relevant exception types when different failures need different outcomes; uncaught exception types terminate the actor under that strategy. section 5.3.1
  • Use restartWithBackoff for failures from external services such as HTTP servers or databases, so retries wait and increase exponentially rather than reconnecting continuously. section 5.3.3
Figure 5.9 Actor with a restart supervision strategy
CH05_F09_Abraham2

Follow the failure path from a message exception through PreRestart, actor removal, mailbox continuity, and replacement actor initialization. section 5.3.3

How Akka in Action, Second Edition covers it

How deep it goes
Explains configuration, lifecycle signals, state loss, failed-message handling, and exponential backoff; defers durable state recovery to persistent actors.
Examples
Uses corrupted LogProcessor input, IndexOutOfBoundException supervision, and external HTTP or database failures to motivate restart choices.
What you can do after
Operate/configure it by wrapping a behavior, selecting exception types, and applying restart or restartWithBackoff.
How it connects
Connects restart to supervision, ActorRef, mailboxes, resume, stop, PreRestart, Behavior.setup, backoff, and persistent actors.

Also explained in

Compare how 2 books explain restart strategy →

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.