How to architect the code if there are multiple database update mix with third party API calls

34 Views Asked by At

If my code are like this

  • start transaction
  • first database update
  • first API call
  • second database update
  • second API call
  • third database update
  • third API call
  • end transaction

The rough idea is that all these operations must all success, otherwise this transaction need to be rolled back. What if everything is ok till the third API call. When the third API call failed (after some retries), we should rollback the transaction, but the first and second API call has already been called. What should I do in this case? What is the best architect for this scenario?

0

There are 0 best solutions below