Search code examples
node.jstransactionsrollback

Can do transaction control on multiple distributed data destination Nodejs?


I have the case write data to multiple data destination in nodejs

writeToMySql(data); //Step 1
postRestApi(data);  //Step 2
writeToSqlServer(data); //Step 3 

So the problems is data destination is distributed. I want to do something like "Transaction", if any step in 3 step fail, all 1,2,3 is rollback

But the Step 2 is rest Api, if data are posted to Api, I cannot roll back because the data is go in another server/ services;

So is there some way to do this concept? Thank everyone;


Solution

  • Generally, it is not something supported by Node JS and other "modern" software development platforms. You would need to rely on older techniques like sagas which would mean the development overhead of detecting and rolling back the transactions programmatically.

    but it is important to remember that this is not a language thing so much as a platform thing. For example HTTP is not transactional, so if you implement REST style API on HTTP, you do not get the other enterprise distributed computing features. If you implemented the REST style with SOAP or CORBA (which was quite common), for example, then yes, features like XA and others are part of those protocols.

    While this is slowly changing, many of the distributed computing features developed in the 1980 and 1990 such as distributed transaction management and security/identity propagation, were not included in "modern" software development due to a lack of awareness. These traditional features are slowly being included in "modern" software development as the proponents gain more experience in the problem space.