I am currently playing with DDD and CQRS, and I switched to an outdated application.
Let's say I have an Article object that I can vote on.
When voting is submitted for an article, I want to increase or decrease the counter corresponding to the value of the vote.
This counter is part of my query model, and therefore I donโt think it is suitable for the domain model. For these reasons, I decided to write a CastArticleVoteService in which I put the business logic about the vote, and I send the event for processing by a special event handler, which in turn updates the counter in the database.
First of all, I was skeptical because I told myself: "Hey, the counter update process must be in the same transaction as the one that stores the data." But this is clearly not true if I have a polyglot persistence (i.e.: MySQL / Redis).
However, transactions are applied, how can I be sure that all event handlers are processed properly and my data is consistent? (here is my counter). (what about an asynchronous event handler?)
Any tips?
php event-driven domain-driven-design cqrs
Ricola
source share