What is the difference between transaction manager 2 phase commit approach and saga SEC approach?

264 views Asked by At

I am researching microservice architecture. I understand there are 3 approaches:

  1. 2 phase commit

  2. SAGA

  3. Eventual consistency

I have a question with respect to the 2 phase commit approach and the saga approach.

In the 2 phase commit we have the transaction manager. Where as in the saga approach we have the saga log and saga SEC. Both ways we have given the responsibilty to the a central system. So what exactly is the difference.

1

There are 1 answers

0
S.N On

Sagas from my understanding are for long-standing transactions. In another way, this could be a solution for a distributed system problem that shall be completed after coordinating various systems internally or externally. The basic idea is to break the overall transaction into multiple steps or activities. These steps can be performed in atomic transactions (units of work) and can be undone/roll-backed through implementing the redo mechanism. Because the overall transactions are split into multiple units of work, there is no blocking between individual units. This non-blocking nature allows long-standing transactions to complete in minutes/hours or even days.

In 2 PC, the protocol works in two phases and the greatest disadvantage of the two-phase commit protocol is that it is a blocking protocol. This could be acceptable within a business system (transactions would be reasonably fast between services), but not ideal for long-standing or coordinating distributed transactions.

Saga use case: If you are a travel agent who provides a package holidays, your booking systems must be capable enough to complete an end to end package processing. This includes your service, accommodation, short trips, flights, food, venue etc. In a typical scenario, the travel agents system would need to perform a series of coordination between internal and external businesses to complete one transaction, or rollback if one of the participating business fails to serve.

2 PC use case: A email confirmation is sent to the customer when their product is ready to collect from the store with the assumption that each task is handled by more than one system.