Course contentsShow
← Databases & SQL
Lesson 1536 of 1,95314. High Availability and DurabilityFree lesson

Leaderless Replication and Quorum Writes

Configure read and write quorum levels to maintain data consistency without a central coordinator.

In this lesson, you will learn how to maintain data consistency in leaderless distributed systems by using quorum configurations to balance read and write operations.

The Leaderless Paradigm

In architectures like Cassandra or Riak, there is no single "leader" node responsible for coordinating writes. Instead, every node can accept writes directly from the client. While this eliminates single-point-of-failure bottlenecks, it introduces the risk of stale data if some nodes miss an update due to network partitioning or temporary downtime. To solve this, we use the concept of a quorum.

Configuring Quorum Levels

A quorum is defined by the variables n, w, and r:

  • n: The number of replicas (nodes) that store a copy of the data.
  • w: The number of nodes that must acknowledge a write for it to be considered successful.
  • r: The number of nodes that must respond to a read request.

To ensure we always read the most recent version of the data, we must satisfy the condition: w + r > n.

How It Works in Practice

Imagine a cluster with n=3 replicas. If we set w=2 and r=2, the inequality 2 + 2 > 3 holds true. Because the set of nodes involved in the write and the set of nodes involved in the read must overlap by at least one node, the reader is guaranteed to see the latest write.

-- Conceptual configuration for a write request
-- w=2 ensures the data is persisted to a majority of nodes
WRITE_REQUEST(key='user_123', value='data_v2', quorum=2);

-- Conceptual configuration for a read request
-- r=2 ensures we query enough nodes to intersect with a quorum write
READ_REQUEST(key='user_123', quorum=2);

By increasing w, you increase durability and consistency at the cost of higher latency (waiting for more nodes to respond). Conversely, decreasing w improves write performance but increases the risk of "dirty" or stale reads if not balanced by a higher r. By carefully tuning these parameters, you orchestrate consistency across a decentralized cluster without ever needing a central coordinator.

Key Takeaway: In leaderless replication, setting quorum levels such that w + r > n guarantees that the read set and write set overlap, ensuring you always retrieve the latest data version.