Search code examples
azuretransactionsazure-cosmosdbtransient-failure

Cosmos DB: How to retry failures with TransactionalBatch


I have a few stored procedures in Cosmos DB that I'd like to convert to .NET transactions. Recently, I saw this post https://devblogs.microsoft.com/cosmosdb/introducing-transactionalbatch-in-the-net-sdk/ that goes over transaction support. I was also able to test it, and it seems to be working fine.

I know that .NET has added built-in retry logic into many of its supported packages. Does TransactionalBatch have any built-in retry policy? What is the recommended approach to retrying any failures? The post above is looking at IsSuccessStatusCode. Should we retry once the status is fail?


Solution

  • Does TransactionalBatch have any built-in retry policy?

    For now, it does not support built-in retry policy.

    What is the recommended approach to retrying any failures?

    TransactionalBatch describes a group of point operations that need to either succeed or fail.If any operation fails, the entire transaction is rolled back.

    Because the failed status code will be 424 and 409, so we could not use RetryOptions.MaxRetryAttemptsOnThrottledRequests.

    So, you could use for (int i = 0; i < MaxRetries; i++){} to perform the retry logic.