What are the differences between TiDB's Raft protocol and OB's Paxos protocol?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TiDB的raft协议和OB的paxos协议到底有什么区别?

| username: SFeng

Recently, I’ve been studying domestic distributed databases. According to the OB documentation, Paxos multi-replica management is achieved through election, log replication, and security features. In the election process, among multiple replicas, only one is the leader, and the others are followers. The leader is maintained through a lease, prioritizing user-specified replicas and primary zone replicas. Only the leader replica can provide read and write services. The leader replicates logs to other followers using Paxos.

This description feels very similar to the basic structure of TiDB’s Raft protocol. So, apart from the different names, what are the substantial differences in structure, process, and functionality between the distributed consistency protocols of these two distributed databases?

| username: Kongdom | Original post link

In simple terms, these are two types of distributed protocols.

The Paxos protocol is a distributed consensus protocol proposed by Leslie Lamport in 1990. It is widely used in distributed systems to solve consistency issues in asynchronous network environments.

Raft is a relatively simplified distributed consensus algorithm proposed by Diego Ongaro and John Ousterhout in 2013. Compared to Paxos, Raft’s design goal is to make the consistency problem easier to understand, implement, and deploy.

The following is an excerpt from CSDN:

Both Paxos and Raft algorithms are distributed consensus algorithms used to solve data consistency issues in distributed systems. Their main differences are as follows:

  1. Algorithm complexity: The Paxos algorithm is relatively complex and requires understanding multiple stages of message interaction, while the Raft algorithm is relatively simple, requiring only an understanding of leader election and log replication.

  2. Leader election: In the Paxos algorithm, leader election is completed through multiple rounds of message interaction, whereas in the Raft algorithm, leader election is completed through heartbeat and timeout mechanisms.

  3. Log replication: In the Paxos algorithm, each node can propose a value, but only one value will be chosen. In the Raft algorithm, the leader node is responsible for receiving client requests and converting them into log entries, then replicating the log entries to other nodes.

  4. Readability: Since the design goal of the Raft algorithm is to be easy to understand and implement, its code and documentation are easier to understand and read.

Overall, the Paxos algorithm is relatively more complex but may be more efficient in certain scenarios, while the Raft algorithm is easier to understand and implement, making it suitable for most distributed system scenarios.

| username: TiDBer_vfJBUcxl | Original post link

I’m sorry, but I can’t access external content such as the URL you provided. Please provide the text you need translated, and I’ll be happy to help.

| username: 哈喽沃德 | Original post link

  1. Algorithm Complexity: Raft is easier to understand and implement compared to Paxos. Raft’s algorithm design is more modular and simple, making it easier to break down the algorithm into independent sub-problems to solve. In contrast, the Paxos algorithm is more complex and abstract, requiring a deeper understanding to implement correctly.
  2. Node Election: Raft is more flexible and efficient in terms of node election. Raft uses random timeout to avoid competition and supports dynamic cluster configuration and quick switching. Paxos, on the other hand, relies on a strongly consistent node election algorithm, which is more complex and can encounter issues in cases of network partitioning.
  3. Data Replication: Raft uses log replication to achieve data consistency, whereas Paxos uses message replication. This makes Raft’s implementation more efficient and reliable because it can use snapshot technology to reduce the time and bandwidth consumption of data replication.
  4. Consistency Model: The consistency models of Raft and Paxos are slightly different. Raft implements a strong consistency model, meaning all nodes can access the latest data at any time. Paxos, however, implements an eventual consistency model, where some nodes may see old data, but they will eventually reach consistency.
| username: yiduoyunQ | Original post link

The official PingCAP blog has some simple source code explanations for Raft, 博客 | PingCAP. For Paxos, you can look for it on Alibaba’s public account and similar sources.

The following is from ChatGPT 3.5

Raft and Paxos are consensus algorithms used in distributed systems to ensure that a group of nodes can agree on a single value or a series of values. Here are some key differences between them:

  1. Readability and Understandability: Raft is designed to be easier to understand than Paxos. The Raft paper is specifically written to be more readable and implementable than the Paxos paper.
  2. Leader-based vs. Leaderless: Raft uses a leader-based approach, where one node is elected as the leader and handles all client requests, whereas Paxos is leaderless and allows any node to propose values.
  3. Membership Changes: Raft explicitly supports membership changes, allowing nodes to join and leave the cluster without requiring a separate consensus algorithm. Paxos does not have built-in support for membership changes.
  4. Log Management: In Raft, each node maintains a log of commands that have reached consensus. The leader sends log entries to followers, who replicate these entries. The Paxos protocol focuses on reaching consensus on a single value or a series of values, rather than maintaining a log.
  5. Complexity: While Raft is designed to be easier to understand and implement, Paxos is considered more efficient in some scenarios. However, Paxos is also more complex, which can make it harder to implement correctly.

Overall, for systems that prioritize simplicity in implementation and maintenance, Raft is usually preferred. For scenarios that require maximum efficiency and where algorithm complexity is not a primary concern, Paxos might be more suitable.

| username: SFeng | Original post link

There are many differences between the Paxos and Raft algorithms, but I noticed in OB’s documentation that they also mention their leader is managed through a lease and has priorities, which seems similar to Raft’s leader election. Moreover, in OB, only the leader can perform read and write operations, so there won’t be multiple nodes “proposing a value simultaneously.” So, what is the fundamental difference between these two products in terms of their consistency protocols?

| username: Kongdom | Original post link

I think the underlying principles are the same, just implemented differently. You can refer to this for more details:

| username: lemonade010 | Original post link

Learned.

| username: zhanggame1 | Original post link

Learn a bit.

| username: 路在何chu | Original post link

I studied it a bit, but it doesn’t seem very useful.

| username: 哈喽沃德 | Original post link

It’s enough to have a general understanding of the underlying stuff; there’s no need to delve deeply.

| username: TiDBer_08RNElU3 | Original post link

Learn a bit.

| username: TiDBer_5Vo9nD1u | Original post link

Are you developing a database?

| username: 这里介绍不了我 | Original post link

Learn a bit.

| username: Jayjlchen | Original post link

Simply put, Paxos can outperform Raft in certain situations, but Raft is easier to engineer, has an active community, and more open-source contributors.

| username: TIDB-Learner | Original post link

OB was founded in 2010. The Raft protocol was introduced in 2013. If Raft had appeared a few years earlier, would Alibaba have chosen it?

| username: 随便改个用户名 | Original post link

It makes a lot of sense. Coming out later is not entirely a bad thing.

| username: Kongdom | Original post link

:yum: Oh? Don’t say… You really don’t say… This might actually be possible.

| username: ShawnYan | Original post link

This title…

You can also organize which domestic database products use raft/paxos protocols.

| username: SFeng | Original post link

If used simply, this is indeed the case. However, if you aspire to be a senior DBA, you must master theoretical knowledge. Otherwise, you will lack effective support when analyzing performance issues…