I am having a microserice architecture with multiple services, each containing their own Database, and a Gateway which is considered as the business logic.
Gateway:
Service 1:
Service 2:
So for example Gateway calls Service 1 to insert some data. Then it calls Service 2 to also insert some data.
Now the problem: What if the call to Service 2 fails, how do I undo the insert to service 1? I know I could call a http://.../delete method, but this cannot be the best solution. So what is the best way to undo the changes?
Considering very specific details of your architecture, a straight forward answer would be distributed transaction management. But that would be a bit difficult not in terms implementation but later in terms of maintenance, performance etc.
But my question, is I feel there is some flaw in the architecture, because if you have to rollback the data in service 1 because of some failure in service 2 then there is a tight coupling between these 2 services and this not something how a microservice should behave like as it is supposed to be independent. So , you may have to change a architecture a bit