Reducing recovery time using snapshots
As we have mentioned in the introduction, Akka persistence uses event sourcing to persist the state of an actor. Event sourcing is a technique to store the changes to the state instead of the state itself. This way, we can have a sequence of what happened. This mechanism is great and has some advantages over the traditional approach, but it might be overkill when you have millions of events to persist and replay when recovering. That is why Akka persistence allows you to take snapshots of our current state to speed up the recovery time. Persistent actors can save snapshots of the internal state by calling the saveSnapShot
method. If saving a snapshot succeeds, the persistent actor receives a SaveSnapshotSuccess
message; otherwise, they receive a SaveSnapshotFailure
message.
Getting ready
To step through this recipe, we need to import the hello-Akka
project in the IDE; other prerequisites are the same as earlier as we have downloaded the akka-persistence...