Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Akka Persistence and Akka Persistence Query?

Akka persistence query complements Persistence by providing a universal asynchronous stream based query interface that various journal plugins can implement in order to expose their query capabilities.

This is the description of 'Akka Persistence Query' from akka documentation. What I wonder that is it using only for querying, in other words for read-side?

like image 614
znkomurcu Avatar asked Jan 28 '23 19:01

znkomurcu


2 Answers

Probably the better question is why isn't Akka persistence query part of Akka persistence? What good is persistence if you can't query it?

Akka persistence seeks to solve one thing and one thing only, make the state of an actor persistent. It doesn't care whether that actor represents a domain entity, or if it's just an operational actor whose state needs to survive restarts (such as is the case for the cluster sharing manager, which used to store its state in Akka persistence before switching to distributed data). It's just a general purpose "make this actors state persistent" feature.

Now, a common use for Akka persistence is to implement event sourced domain entities. Event sourced domain entities however need more than just "make this actor persistent", they usually also need the ability to execute queries across domain entities. And so Akka persistence query exists to allow this, it allows creating cross entity streams that can be processed to populate read side views.

The thing is, not all event stores necessarily make it easy to do cross entity streaming like that. So those that don't can just implement Akka persistence, and be used to make actors persistent, while stores that provide more functionality can also implement Akka persistence query.

This is all greatly simplified, but hopefully explains some of the motivations.

like image 96
James Roper Avatar answered May 17 '23 07:05

James Roper


The Akka Persistence Query can be used for querying the journal, and this will be in most of simpler cases sufficient enough.

Nevertheless the main purpose of the Persistence Query is to stream stored events to a specific, or multiple separate, read/query-stores where you will execute your actual queries against.

like image 40
Ghashange Avatar answered May 17 '23 07:05

Ghashange