liveBook · Manning

Akka Persistence

As explained in Akka in Action, Second Edition

Akka Persistence is an Akka module for building actors whose state can be durably stored and recovered from persisted events or snapshots.

Akka Persistence keeps actor state durable when sharding relocates entities or processes fail. Instead of replacing one stored value, it records each accepted state change as an event in an append-only journal. section 9.1 section 9.2

A persistent actor follows this sequence:

  • Receives a command expressing an intended state change. section 9.2
  • Validates the command against current state and generates an event only when accepted. section 9.2
  • Stores the event in the journal and applies it through an event handler. section 9.2
  • Replays the journal after restart to reconstruct the latest state; snapshots reduce recovery work. section 9.2

Durable wallet

A sharded wallet starts with a zero balance and persists FundsAdded, FundsReserved, or FundsReservationDenied events. It accepts a reservation when the balance is sufficient, rejects it otherwise, and updates the balance by handling the resulting event. Snapshot retention and restart backoff support recovery after failures. section 12.1.1

Figure 9.5 From command to a stored event
CH09_F05_Abraham2.

Trace how a validated command becomes a stored event before examining recovery through journal replay. section 9.2

Figure 9.6 Persistent actor recovery
CH09_F06_Abraham2

Follow the persistent actor’s restart path from journal history back to reconstructed state. section 9.2

How Akka in Action, Second Edition covers it

How deep it goes
Descends from command validation through event storage, replay, snapshots, and restart backoff.
Examples
Uses a sharded wallet with balance commands, persisted funds events, snapshots, and event-handler state updates.
What you can do after
Build it from scratch using event-sourced actors with command handlers, event handlers, snapshots, and recovery settings.
How it connects
Connects event sourcing, actor state, Akka Sharding, snapshots, and cluster failure recovery.

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.