Skip to content
BytePatterns

Read Quorum for a Write Quorum

EasySystem Design#quorum#pigeonhole~10m

Problem

A replicated key-value store keeps every key on n replicas. A write succeeds once w replicas acknowledge it, and a read asks r replicas and keeps the newest version it sees. A read is guaranteed to see the latest successful write only if every possible read set shares at least one replica with every possible write set. Given n and w, return the smallest such r, together with how many replicas can be down while both reads and writes can still succeed.

Examples

Input:  n = 3, w = 2
Output: (2, 1)
Why:    any 2 of 3 overlap any other 2 of 3, and 1 replica can be lost
Input:  n = 5, w = 3
Output: (3, 2)
Input:  n = 3, w = 3
Output: (1, 0)
Why:    edge case, every write reaches everyone, so one replica is enough to read, but none may fail

Hints

0 / 3

Stuck on the idea rather than the code? Consistency and CAP covers it.