3

I'm doing an upsert of a JSON document in Azure CosmosDB SQL API as part of a transaction. I'm using the SDK Microsoft.Azure.DocumentDB.Core.

I also have another SQL Server update which takes place in the same transaction scope (not .NET transaction scope class). If the SQL Server update fails, I want to revert/rollback the change made to the CosmosDB. What command or option I should use from the SDK to do that?

wonderful world
  • 10,969
  • 20
  • 97
  • 194

1 Answers1

1

I think what you are asking here is whether your Cosmos DB update can participate in an automatically managed distributed transaction, and I believe the answer is no. Transaction support in Cosmos is somewhat limited.

  • Any transaction supported by the Cosmos DB engine is scoped to a single partition in a single container, meaning, you cannot update documents in different containers, or even different partitions within the same container as part of a single transaction.
  • Until recently the only way to get transaction support was by using a server-side stored procedure. With version 3.4 of the .Net SDK you can now execute transactions from your .Net code, but the single partition restriction still applies.
  • There is no built-in support for participating in distributed transactions with other databases or services.

In order to perform operations in your Cosmos DB and SQL Server databases as part of a single Atomic transaction you will need to write some code to manage that yourself. Check here for a good primer on distributed transactions.

Paul
  • 597
  • 2
  • 5