how to handle errors when updating resources in multiple services from a single API | atomic operation

Viewed 58

I am currently working on the use case where there is an existing API which is being called from the client side. Now, I need to update the resources in multiple services. How do I make sure that the operation is atomic.

By atomic, I mean, If request to first service fails for some reason, and request to the second service is successful that means second service updated the resource/s at it's end, then how do we ensure that whole operation is executed not the partial one.

1 Answers

This is a common issue. If you are consuming the api with a framework as Angular, for example, you can use RxJS to make a forkJoin for example that will help you to deal with something like these, where you can analyze the result of all operations or do some if someone fails.

I think that you need to do a way to do it and also to have in your services some way to undo the action in case of some step fails (very important) to restore the full resource previous status.

Related