Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST and transaction rollbacks

I have a few different RESTful services that are hosted on different servers which use different DBs. I have a few RESTful services which call multiple such services above in what is supposed to be a transactional unit. We end up with data consistency issues if any of these RESTful services fail. Is there a neat architectural way of orchestrating a rollback? Or is having transaction managers the way to go?

As a simplistic example, RESTful service 1 has a POST request which reduces item count of thingamajig by 1. RESTful service 2 POSTs a payment. If service 2 fails, how can we cleanly implement a rollback on service 1, without having a new RESTful refund service (it is ok if this has to be the way to go). I am looking for an architectural answer to above issue, which is in keeping with REST principles.

like image 796
cvam Avatar asked Oct 11 '15 02:10

cvam


Video Answer


1 Answers

Distributed transactions are complex and require each participating system to support a notion of rollback. In the case of your services, they would each have to support some form of rollback. Co-ordinating something like this in a distributed system may not be practical or advisable in a synchronous way. In a situation like this, you would want to asynchronously roll back and the system would eventually reach consistency at a certain point in the future. There are obviously many other details (timeouts, error handling, retries, etc.).

For more details on eventual consistency, check out the wikipedia entry here.

like image 184
leeor Avatar answered Nov 15 '22 22:11

leeor