# 2Pc (Two-Phase Commit)

+ synchronous blocking
+ Single point of failure
+ Network latency


![left](./student-guide/diagram/10-2PC-01-01.png)

------------------------------------------------------------
2PC (Two-Phase Commit)

The most commonly used transaction in the database field is 2PC. The first official proposal of 2PC was in a paper published by Jim Gray in 1977, entitled “Notes on Data Base Operating Systems”, which summarized the research results and practices of database systems at that time. The 2PC process is also divided into two stages: prepare and commit, each of which is completed by the transaction manager and the resource manager. Of these, the transaction manager acts as the coordinator of the transaction only one, while the resource manager is allowed to perform specific actions as a participant in more than one.

Compared to TCC, the biggest advantage of 2PC is that it does not intrude into business logic through database submission and rollback mechanisms. But traditional 2PC has many challenges, including:
- Synchronous blocking
During execution, the database locks the corresponding data rows. If other transaction happen to operate on these rows of data, they can only wait. In fact, synchronous blocking is just a design method, and the real problem is that this design results in high latency and significant performance degradation for distributed transaction.
- Single point of failure
The transaction manager is very important, and in the event of a failure, the database will continue to block. In particular, in the event of a second phase failure, all databases remain locked on transaction resources and cannot continue to complete transaction.
- Network latency
There is a high delay in completing the entire transaction due to multiple network interactions. This in turn affects the concurrent ability of the system in transaction.
