Definition : Distributed consensus is a process in distributed systems
where multiple independent nodes agree on a shared decision or value. It addresses challenges such as node failures and communication delays to maintain a consistent system state. The goal is to achieve a unified and reliable view across all nodes despite potential disruptions. Consensus mechanisms, like Raft or Paxos, are used to ensure agreement in decentralized environments. This is crucial for the proper functioning of distributed databases. Paxos Algorithm
The Paxos algorithm is a consensus algorithm designed to achieve
fault tolerance in distributed systems. It was introduced by Leslie Lamport in 1989 and is widely used in distributed computing to ensure that a group of nodes can agree on a single value even if some nodes fail or the communication between them is unreliable. The primary goal of the Paxos algorithm is to allow a group of nodes (or processes) to agree on a single value, even if some nodes may fail or send unreliable messages. The algorithm operates in rounds, and each round consists of a set of phases. The main phases are: 1.Prepare Phase: A node, called the proposer, sends a prepare request to all other nodes with a proposal number. Nodes respond with a promise not to accept any proposal numbered lower than the one they have already promised. 2.Accept Phase: If the proposer receives promises from a majority of nodes, it can send an accept request with the proposed value. Nodes will accept the value if they have not promised to reject proposals with a higher number. 3.Learn Phase: Once a node has accepted a value, it informs all other nodes of the accepted value. Nodes update their accepted value if they receive a proposal with a higher number. (NS , valeur)
The Paxos algorithm ensures that only one value is ultimately
chosen, and that choice is guaranteed to be one of the values proposed by a proposer. The algorithm can tolerate the failure of some nodes and still reach consensus, as long as a majority of nodes are functioning correctly.
While Paxos provides a robust solution for consensus in distributed
systems, it can be complex to understand and implement. Variants and optimizations, such as Multi-Paxos, have been developed to address some of the practical challenges of deploying Paxos in real- world distributed systems.
Raft Algorithm
The Raft algorithm is a consensus algorithm designed to be
understandable and relatively simple to implement. It was introduced by Diego Ongaro and John Ousterhout in 2013. Here is a general description of the main aspects of the Raft algorithm: 1.Leader Election: The process begins with a leader election. Nodes in the system elect a leader among themselves. The leader is responsible for managing write operations to the log. 2.Replication of Log Entries: The leader is responsible for replicating entries from its log to other nodes in the system. Other nodes follow the leader and update their logs to stay synchronized. 3.Log Compaction: Periodically, the leader can compact the log by removing entries already confirmed by the majority of nodes. This helps limit the size of the log and improve system efficiency. 4.Commitment: Before a log entry is considered committed, it must be replicated on a majority of nodes. This ensures that most nodes in the system agree on the current state. 5.Leader Failure and Election: If the leader fails (e.g., due to a crash), a new election process is triggered. Nodes in the system use a voting mechanism to elect a new leader.
The Raft algorithm is designed to be more understandable than other
consensus algorithms, such as Paxos. It breaks down the consensus problem into simpler steps and uses a leader model to simplify coordination. However, it maintains sufficient robustness to ensure consensus even in the presence of node failures.