2

Let's suppose there are two banks, Bank A and Bank B. A transaction needs to happen that transfers money from an account in Bank A to an account in Bank B. Bank A and Bank B have separate banking systems which makes this transaction a distributed one. From what I understand following is what happens, I refer the system of bank A as A and the system of bank B as B,

A initiates the transaction
A sends a message including the amount to B
A waits for a response from B
B adds the amount to the account send a response to A
A receives the response and deduct the amount from account
Transaction completes.

A can complete the transaction if it received the response since it is a guarantee that B has done the addition, but if A doesn't receive a response, it cannot guarantee that B has done the addition, so it cannot complete the transaction. In that case, what if B has done the addition successfully but the response message was lost in transit. Now A hasn't done the deduction while B has done the addition which is an inconsistent state. How do we solve that problem?

1 Answers1

0

May I ask to read about two phase commit, and then three phase commit?(wikipedia has a good enough summary on that)

The high level idea is that there is a transaction coordinator, which makes sure everything goes as it should. That coordinator commits a distributed transaction by first asking every system to prepare for commit; and after every system reports back the coordinator asks to execute the actual commit.

In case the coordinator can't reach a system for a commit - the coordinator will retry forever (or notify admin). During that time, the overall transaction will be partially committed.

It is completely different topic on how to make the coordinator fault tolerant.

AndrewR
  • 259
  • 1
  • 3