akka-blog-example
akka-blog-example copied to clipboard
Consistency in Application
Hello ,
In the sample code sending events on event stream and persisting state is not in a single transaction , this may lead into missing events for upstream for making a consistent view state(CQRS).
How do we tackle this.
In my example, the event is persisted before being published to the event stream. The snapshots are only relevant for performance and can be recomputed in case of failure from the persistent event log, so I don't think there's an issue there. The state is always computed by "folding over" the stream of events (in my case, I use the BlogState.+()
function as my fold operation), so as long as commands are validated before generating an event from them, there shouldn't be an inconsistencies.
I recently read a book, Functional and Reactive Domain Modeling, which goes into a lot more detail about this which I recommend.