How to handle error and revert transaction state if one of the API call fails out of sequence of APIs to be called in transaction

447 views Asked by At

I have following type of 3rd party APIs to be called in sequence in c# code.

try
{
    transaction:
    {
        call API 1;
        call API 2
        call API 3
    }

}
Catch
{
    transaction rollback:
    rollback API 4;
    rollback API 5;
}

How should I handle this in Azure function http trigger? Is SAGA or 2 phase commit suitable here? are Azure durable functions suitable? Any other pattern can I use for this?

1

There are 1 answers

0
Rex Henderson On

As you replied that API 1,2,3 return very quickly and I assume they can run in parallel, then I would simply use a Task.WhenAll and perform any necessary rollback if any of them return an Exception (as their means of signalling failure).

Durable Functions could be used, but it sounds like overkill in this scenario. Durable Function are used for more long-lived scenarios