So I'll explain the problem through the use of an example as it makes everything more concrete and hopefully will reduce ambiguity.
The Architecture is pretty simple
1 MicroService <=> 1 Aggregate <=> Transactional Boundry
Each microservice will be using CQRS/ES design pattern which implies
- Each microservice will have its own Aggregate mapping the domain of a real-world problem
- The state of the aggregate will be rebuilt from an event store
- Each event will signify a state change within the aggregate and will be transmitted to any service interested in the change via a message broker
- Each microservice will be transactional within its own domain
- Each microservice will be eventually consistent with other domains
- Each microservice will build there own view models, from events being emitted by other microservices
So the example lets say we have a banking system
current-accountmicroservice is responsible for mapping the Customer Current Account ... Withdrawal, Depositsrewardsmicroservice will be responsible for inventory and stock take of any rewards being served by the bankair-milesmicroservice will be responsible for monitoring all the transaction coming from thecurrent-accountand in doing so award the Customer with rewards, from our reward micro-service
So the problem is this Should the air-miles microservice take decisions based on its own view model which is being updated from events coming from the current-account, and similarly, on picking which reward it should give out to the Customer?
Drawbacks of taking decisions on local view models;
- Replicating domain logic on how to maintain these views
- Bugs within the view might propagate the wrong rewards to be given out
- State changes (aka events emitted) on corrupted view models could have consequences in other services which are taking their own decisions on these events
Advantages of taking a decision on local view models;
The system doesn't need to constantly query the microservice owning the domain
The system should be faster and less resource intense
Or should it use the events coming from the service to trigger queries to the Aggregate owning the Domain, in doing so we accept the fact that view models might get corrupt but the final decision should always be consulted with the aggregate owning the domain?
Please, not that the above problem is simply my understanding of the architecture, and the aim of this post is to get different views on how one might use this architecture effectively in a microservice environment to keep each service decoupled yet avoid cascading corruption scenario without to much chatter between the service.