Lesson 6 of 14
Quorum-Based Replication
Quorum-Based Replication
When data is replicated across N nodes, a quorum is the minimum number of nodes that must agree for an operation to succeed. Quorums ensure consistency even when some nodes are unavailable.
The Quorum Rule
For N replica nodes:
- Write quorum (W): minimum nodes that must acknowledge a write.
- Read quorum (R): minimum nodes that must respond to a read.
For strong consistency: W + R > N
This guarantees that every read will overlap with at least one write, so reads always see the latest write.
Common Configurations (N = 3)
| W | R | Guarantee |
|---|---|---|
| 2 | 2 | Strong consistency (W+R=4 > 3) |
| 3 | 1 | Strong consistency, slow writes |
| 1 | 3 | Strong consistency, slow reads |
| 1 | 1 | Fast but inconsistent |
function hasQuorum(n, w, r) {
return w + r > n;
}
function canWrite(n, w, availableNodes) {
return availableNodes >= w;
}
function canRead(n, r, availableNodes) {
return availableNodes >= r;
}
Dynamo-Style Quorums
Amazon DynamoDB uses quorums with N=3. Default settings are W=2, R=2, providing strong consistency while tolerating 1 node failure for both reads and writes.
If you need lower latency, you can use W=1, R=1 (eventual consistency) or W=3, R=1 (all writes acknowledged, fast reads).
Your Task
Implement three functions:
hasQuorum(n, w, r)— returns true ifW + R > N(strong consistency guaranteed)canWrite(n, w, available)— returns true if enough nodes are available to complete a writecanRead(n, r, available)— returns true if enough nodes are available to complete a read
JavaScript loading...
Loading...
Click "Run" to execute your code.