title: two phase commit in nodeJS application
body: <p>I am currently working on a nodeJS application that will soon need to write simultaneously on two PostgreSQL databases. This is meant for redudancy purposes: the writing operations must be made <strong>in the same time on both databases</strong>, or rollbacked if there is anything wrong with one of the databases.</p>
  
  <p>In order to achieve that, I need to rely on a transaction manager that would (or at least could) <strong>use two-phase commit in the persisting process</strong>.</p>
  
  <p>Currently,  the application uses an out-of-the-box solution to perform actions on the current database (i.e. the <strong>pg-promise</strong> package, which for now stands as the application's transaction manager).</p>
  
  <p>To put it all in a nutshell, I am going to need every persisting action in the Node application to be performed on two databases simultaneously.</p>
  
  <p>For now, I merely use the pg-promise to persist data on one database like on this example:</p>
  
  <pre><code>db.one(mySQLRequest)
  </code></pre>
  
  <p>but I only found to create a db object for one specific database at a time.</p>
  
  <p>I have found no example for such a vast problematic on a NodeJS RESTful application, but I suspect it might be a rather common issue. And I would be glad if it was not necessary that I recode the whole transaction manager on my own...</p>
  
  <p>If you have any lead about how I could allow my NodeJS application to perform two-phase commits, it would be greatly appreciated. :)</p>