Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paxos vs two phase commit

I am trying to understand the difference between paxos and two phase commit as means to reach consensus among multiple machines. Two phase commit and three phase commit is very easy to understand. It also seems that 3PC solves the failure problem that would block in 2PC. So I don't really understand what Paxos is solving. Can anyone illuminate me about what problem does Paxos exactly solve?

like image 832
Keeto Avatar asked Dec 04 '14 21:12

Keeto


People also ask

Is Paxos a 2PC?

Two Phase Commit, a.k.a 2pc, is a very well-known and intuitive algorithm, often used for coordinating transactions. Paxos is a well-known consensus algorithm, often used for replication on a stateful service. Paxos is less intuitive and harder to grasp. Atomic commit is a classic 2pc use case.

Is raft 2 phase commit?

Two-phase commit and Raft # We use Raft to get high availability by replicating the data on multiple servers, where all servers do the same thing. This differs from two-phase commit in that 2PC does not help with availability, and all the participant servers here perform different operations.

Is raft better than Paxos?

Although Multi-Paxos might compromise the efficiency, it can restore services quicker when the leader fails. Therefore, Multi-Paxos has better availability than Raft.

Does spanner use two-phase commit?

As with most ACID databases, Spanner uses two-phase commit (2PC) and strict two-phase locking to ensure isolation and strong consistency.


2 Answers

2PC blocks if the transaction manager fails, requiring human intervention to restart. 3PC algorithms (there are several such algorithms) try to fix 2PC by electing a new transaction manager when the original manager fails.

Paxos does not block as long as a majority of processes (managers) are correct. Paxos actually solves the more general problem of consensus, hence, it can be used to implement transaction commit as well. In comparison to 2PC it requires more messages, but it is resilient to manager failures. In comparison to most 3PC algorithms, Paxos renders a simpler, more efficient algorithm (minimal message delay), and has been proved to be correct.

Gray and Lamport compare 2PC and Paxos in an excellent paper titled "Consensus on Transaction Commit".

(In the answer of peter, I think he is mixing 2PC with 2PL (two-phase locking).)

like image 92
danyhow Avatar answered Sep 25 '22 07:09

danyhow


2-PC is the most traditional transaction commit protocol and powers the core of atomicity of transactions. But it is blocking in nature, i.e. if the transaction manager/coordinator fails in between, it will cause the protocol to block and no process will be aware of it. It requires manual intervention to repair the coordinator.

While Paxos being a distributed consensus protocol has multiple such coordinators and if a majority of the coordinators agree to the transaction completion, it becomes a successful atomic transaction.

You should read https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/tr-2003-96.pdf to understand how these two protocols are differentiated in a more granular manner. In the same paper, Gray and Lamport also introduce a protocol i.e. a combination of Paxos and 2-PC for faster performance.

like image 36
Kamal Chaturvedi Avatar answered Sep 26 '22 07:09

Kamal Chaturvedi