mercredi 9 février 2022

Pattern to Orchestrate sequence of API calls C#

I have 3 microservices exposing APIs for interaction.

The order microservice receives order from UI and makes an API call to Inventory microservice to update the inventory details to reduce the itemCount.

Once the above operation succeeds, the order microservice will make calls to Payment microservice to initiate payments. If payment succeeds, the order microservice will return success to UI. If payment fails, the order microservice has to rollback the itemCount by calling Inventory microservice.

I know that this is a typical Saga based pattern and can be achieved using messaging bus. But all the microservices in this case are capable of only handling API calls. Thinking about other patterns, I am not sure this scenario fits into a state pattern .

Note: For the sake of example, I have used Order,Payment and Inventory microservices. But typically my question is about orchestrating sequence of API calls without excessive if-else. Failure of one of the API call should rollback the other API call by calling appropriate API (eg: If PATCH call succeeds on service A , but not on service B, then the PATCH call on service A has to be rolled back on Service A)

Aucun commentaire:

Enregistrer un commentaire