Quorum Intersection

easy · distributed-systems, replication, quorum

Quorum Intersection

A replicated system stores one key on N replicas. A read succeeds after R replica responses. A write succeeds after W replica acknowledgments.

Two safety checks matter:

Read/write intersection: R + W > N
Write/write intersection: W + W > N

Return whether each condition holds.

Function signature

func QuorumSafety(n, r, w int) (readWrite bool, writeWrite bool)

Example

N=3, R=2, W=2
readWrite  = true  because 2+2 > 3
writeWrite = true  because 2+2 > 3

Counterexample

N=4, R=2, W=2
R+W == N, not greater than N

A read could use  {0,1}
A write could use {2,3}

No overlap is guaranteed.

Constraints

  • 1 <= n <= 1_000_000_000
  • 0 <= r, w <= n

Expected complexity

O(1) time and O(1) space.

Run tests to see results
No issues detected
    Join Discord