Consider 2 microservices, Product and User. User can only browse two Products per day.
The Gateway redirects URL requests to the Product microservice if the limit for viewing is not hit. But those two recently viewed products can be viewed any number of time within that day.
I’m keeping Recently Viewed Products in another aggregate with a viewtable. Every time a product is requested, Create_Recently_Viewed_Product command is executed and rvp_created event is generated.
To solve this problem, every time a new recently viewed product for a certain user is created, I need to read the number of products viewed from the viewtable and send it to the Users microservice which restricts the Gateway from the overlimit requests.
So, I’m handling rvp_created event, writing to the Recently viewed by user to the viewtable. At the same time I’m trying to handle the same event in the saga with execution order 2. This saga’s purpose is to read number of Recently viewed by user and send it to the User microservice. If number of views is more than 2, User microservice will restrict the Gateway.
The problem is that even thought the execution order of the event handlers are correct, when Saga tries to read the viewtable, the Recently viewed is still not written the last entry.
I understand that both events are executing simultaneously, though I’m trying to use execution order.
What is your suggestion? Should I generate custom event after writing to the recently viewed viewtable?
Thanks