What is Quorum in Distributed System: Definition and Examples
quorum is the minimum number of nodes that must agree to perform an operation to ensure consistency and fault tolerance. It helps systems avoid conflicts and maintain data correctness even if some nodes fail or are unreachable.How It Works
Imagine a group of friends deciding on a movie to watch. Instead of everyone agreeing, they decide that if a majority agrees, they will pick that movie. This majority is like a quorum in distributed systems.
In a distributed system, data is stored on multiple nodes (computers). To keep data consistent, the system requires a minimum number of nodes (the quorum) to agree before accepting a change. This prevents split decisions and ensures the system behaves correctly even if some nodes are down or slow.
For example, if there are 5 nodes, a quorum might be 3. This means at least 3 nodes must confirm a write or read operation for it to be valid. This balance helps the system stay available and consistent.
Example
This Python example simulates a simple quorum check for a write operation in a distributed system with 5 nodes.
class DistributedSystem: def __init__(self, total_nodes, quorum): self.total_nodes = total_nodes self.quorum = quorum self.nodes = [False] * total_nodes # False means node not responded def node_response(self, node_index): if 0 <= node_index < self.total_nodes: self.nodes[node_index] = True def can_commit(self): # Count how many nodes responded count = sum(self.nodes) return count >= self.quorum # Create system with 5 nodes and quorum of 3 system = DistributedSystem(total_nodes=5, quorum=3) # Simulate responses from nodes system.node_response(0) system.node_response(2) system.node_response(4) # Check if quorum is reached if system.can_commit(): print("Quorum reached: Operation can be committed.") else: print("Quorum not reached: Operation cannot be committed.")
When to Use
Use quorum in distributed systems when you need to balance data consistency and availability. It is especially useful in systems where nodes can fail or network delays happen.
Common real-world use cases include:
- Distributed databases: Ensuring writes and reads are consistent across replicas.
- Consensus algorithms: Like Paxos or Raft, which rely on quorum to agree on system state.
- Distributed locks: To ensure only one process holds a lock at a time.
Quorum helps avoid split-brain problems where parts of the system disagree, improving reliability.
Key Points
- Quorum is the minimum number of nodes needed to agree for an operation.
- It ensures consistency and fault tolerance in distributed systems.
- Quorum size depends on total nodes and system requirements.
- Used in databases, consensus, and distributed locking.
- Helps avoid conflicts and split-brain scenarios.