I am trying to understand how to implement this in Event sourcing model / DDD.
Assume a distributed application in which user submits an application for something, say Job/Loan. So the application raises an UserApplied
Event.
There are few micro services like credit service
, criminal record service
.. they consume this UserApplied
event do some validation, responds with CriminalCheckPassed
, CreditCheckPassed
... etc. Assume there are 5 checks to be done. In future we might also add more checks like this.
The app consume these events and take some decision. That is - only if they are all validated successfully app can approve the user application by changing the status to UserApproved
. Any of the validations failed, them it would be UserDeclined
. Something like that.
It sounds simple. But I am banging my head how to implement that correctly?
This is my event store
I have a materialized view
If we have to update the materialized view/aggregate whenever we receive an event, app needs 5 different events to take decision. Till then it will be pending
. Even when I receive the 5th event, the materialized view does not know how many events it has received before. I will end up querying entire event-store.
Another approach is - adding these columns in the materialized view. So that we know if we have received all these events. It will work. But looks super ugly.
My question is - how to use the aggregation properly in this case?