Akka Persistence

Just like objects in OOP, actors keep their state in volatile memory. When a system shuts down (gracefully or because of a crash) all data that was in memory is lost. Akka Persistence provides the means to persist an Actor state using Event Sourcing. Upon startup, events can be replayed to restore the state of the entity hosted by the actor. The event stream can be queried and fed into additional processing pipelines (an external Big Data cluster for example) or alternate views (like reports).

Persistence tackles the following challenges:

  • How to restore the state of an entity/actor when system restarts or crashes.

  • How to ensure reliable delivery of messages in face of network errors and system crashes.

  • How to introspect domain events that have led an entity to its current state.

  • How to leverage Event Sourcing in your application to support long-running processes while the project continues to evolve.

  • How to implement a CQRS system.

The Event Sourced Cart entity in the Microservices tutorial illustrates how to implement an Event Sourced CQRS application with Akka Persistence.

Persistence Plugins

Storage backends for journals and snapshot stores are pluggable in the Akka persistence extension. The following plugins are maintained within the Akka organization.

R2DBC plugin

The Reactive database drivers (R2DBC) support relational databases like PostgreSQL, H2 (As a minimal in-process memory or file based database) and Yugabyte.

The Akka Persistence R2DBC plugin supports the latest feature additions of Akka Persistence and is generally recommended over the JDBC-based plugin.

Cassandra plugin

Akka supports Cassandra’s data model through Akka Persistence Cassandra.

Some later Akka Persistence feature additions (including Durable State) are not supported by the Cassandra plugin.

AWS DynamoDB plugin

AWS DynamoDB can be used as backend for Akka Persistence with the Akka Persistence DynamoDB plugin.

Durable State is not supported by the DynamdDB plugin.

JDBC plugin

Relational databases with JDBC-drivers are supported through Akka Persistence JDBC. For new projects, the R2DBC plugin is recommended.

Some later Akka Persistence feature additions are not supported by the Akka Persistence JDBC plugin.

Learn more