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
