4

I am quite familiar with how the PersistentActor and PersistentView work while implementing Akka Persistence.

Consider the following example with the idea as far as I understand.

A Scala case class Contact.

case class Contact(id: String, version: Int, fName: String, lName: String, age: Int)

The PersistentActor persisted events in the journal are :

ContactCreated("123af-232ff-232d", 1, "john", "doe", 25)
FirstNameChanged("123af-232ff-232d", 2, "jan")
AgeChanged("123af-232ff-232d", 3, 27)
FirstNameChanged("123af-232ff-232d", 4, "janet")

Every time the commands are sent from the responsive UI, such new events are persisted if validation succeeds 202 CommandAccepted or any CommandValidationError being fired back.

But without significant delay in the responsive environment, the UI must be able to query the REST API backend and show the latest Contact object after the backend WebSocket push informs the UI that UUID "123af-232ff-232d" is available for read:

Contact("123af-232ff-232d", 4, "janet", "doe", 27)

This result should happen after merging all the events with the latest data available as I understand.

So, my actual concern is: How and where in this backend application I do the processing of those events as soon as they are generated, merge those data, and store the merged data for reading by the query side.

Many many thanks in advance if some could shed light on implementing or correcting my thought.

PainPoints
  • 461
  • 8
  • 20
  • Please also correct me if I have misunderstood the flow from the frontend to the backend and vice-versa in a reactive responsive application. – PainPoints Sep 05 '15 at 13:27
  • Is it where I have to maintain the current state inside the PersistentActor by merging each generated events after they are persisted? and immediately send a GET query command from the UI to read the current state and display the data? – PainPoints Sep 05 '15 at 15:23
  • ...but still... before sending GET query, UI needs to know that the current state is available... – PainPoints Sep 05 '15 at 15:30

1 Answers1

0

The current state of Contact might not be so much a view as the actual state, and in the view you will not accept eventual consistency which will be the case with a view.

I would keep that as the state inside the persistent actor and allow for a query against the actor to get the current Contact and use that.

johanandren
  • 11,249
  • 1
  • 25
  • 30
  • For example I need to query a list of contacts, is it not too heavy to maintain the 'contactList' state inside PersistentActor in memory? – PainPoints Sep 07 '15 at 08:24
  • I found the link to my answers: https://groups.google.com/forum/#!topic/akka-user/MNDc9cVG1To Akka Persistence on the Query Side: The Conclusion – PainPoints Sep 07 '15 at 09:11