The CAP theorem (Brewer's conjecture, proved by Gilbert and Lynch) says that when a network partition splits a replicated service, it cannot be both consistent (every read sees the latest acknowledged write) and available (every request to a live node gets an answer). This simulator runs one replicated register on N nodes as a discrete-event simulation: clients send Poisson requests to a random node, replicas answer after exponentially distributed round trips, and a seeded random generator makes every run repeatable.
quorum intersection: R + W > N => every read set meets every write set
write availability: p = sum over sides s of (n_s / N) [ n_s >= W ]
latency of a quorum q out of s replicas (mean delay m):
E[T] = m * sum_{i=0}^{q-1} 1 / (s - i) (order statistic of exponentials)
split brain possible when both sides have n_s >= W, i.e. 2W <= N
anti-entropy: every tau seconds each node syncs with a random peer (last-write-wins)
- CP mode uses the quorums W and R you set. A side of the partition with fewer than W (or R) reachable replicas rejects the request: availability is sacrificed to keep reads fresh. With R + W > N a stale read is impossible.
- AP mode always answers from the nodes it can reach (W = R = 1). Both sides keep accepting writes, versions diverge, stale reads appear, and after the partition heals gossip converges everyone to the newest write; concurrent writes on the losing side are overwritten.
- Split-brain: with W = 2 on 8 nodes both halves reach a write quorum, so a CP-style quorum no longer prevents two competing histories.
Honest simplifications. Timestamps are perfect (one shared counter, so last-write-wins is exact); nodes never crash, only links are cut; there is no leader election, retry, hinted handoff or vector clock; round trips are exponential, not measured network data; one register is modelled. The consistency criterion counted as a stale read is: the value returned is older than the newest write already acknowledged anywhere in the cluster.
Six independent checks run live: exhaustive quorum intersection, simulated write availability versus the analytic formula, simulated quorum latency versus the exponential order-statistic mean, the strict-quorum no-stale-read invariant, the predicted number of sides that accept writes in a split, and convergence of all replicas to the newest version after healing.