0

Consider a critical application and I have to make two external calls to do a transaction, the second call depends on the status of the first call. If I have to make this method atomic, ie, I want to make sure either the entire transaction happens or nothing happens. How do I handle if the system fails in between the calls?

How am I supposed to answer this if I get this question in an interview?

Joe
  • 326
  • 3
  • 11

1 Answers1

1

SQL Databases support this scenario via distributed transactions. If you could implement your requirement at database level (i.e. execute your atomic method in a distributed transaction), that would be the simplest way of achieving this.

Another approach (although considerably more complex) would be to implement the distributed transaction protocol yourself. The Two-Phase Commit protocol is commonly used by SQL Databases. Please see https://en.wikipedia.org/wiki/Two-phase_commit_protocol for more details.