Chapter 15. Actor persistence
In this chapter
- Using event sourcing for durability
- Recording and recovering durable state with persistent actors
- Clustering persistent actors
The in-memory state of an actor is lost when an actor is stopped or restarted, or when the actor system crashes or shuts down. This chapter is all about how to make this state durable using the akka-persistence module.
It’s quite common to use a database API for creating, retrieving, updating, and deleting records (also known as CRUD operations). Database records are often used to represent the current state of a system. The database acts as a container for shared mutable state in this case.
It should come as no surprise that Akka persistence prefers a more immutable approach. The design technique on which Akka persistence is based is called event sourcing and is covered in the first section of this chapter. In short, you’ll learn how to capture state changes as a sequence of immutable events in a database journal.
Next we’ll look at the PersistentActor. A persistent actor makes it easy for an actor to record its state as events and to recover from the events after a crash or restart.