vendredi 11 octobre 2019

Is there a recommended code-based transaction pattern?

Is there a code-based transaction pattern that you would recommend when interacting between two separate databases? I have a project that I need to write to two separate data stores (CosmosDb and table storage) and maybe a rest api. I would like to implement some sort of transaction where if the write to any one of the two data store fails, it would roll back.

Now, I can imagine that if I were doing this by hand, it would work as following:

For an insert: insert record to db 1 and keep track of the new record id. If the insert to second db fails, simply delete record from first db.

For an update: get a copy of the data before modification, modify the data ... if there's a failure, then simply apply the copy back to any updated stores.

I was hoping that hopefully there's a pattern in place that eases the pain of writing all that code. Also, I'd imaging that the rest api would also work in a similar fashion where I would utilize the Get, Post, and Put calls.

Aucun commentaire:

Enregistrer un commentaire