Availability Patterns and the Math of Nines (System Design #5)
A CTO asks for “five nines”. You smile and nod, then do the arithmetic and realize five nines means under 5.3 minutes of downtime per year — less than the time it takes to restart a database and verify it. Promising five nines is a promise about every dependency in the chain, including the ones you do not control.
This chapter turns availability from a slogan into arithmetic. You will learn how to compose availabilities in series and parallel, why redundancy is the only real lever, the difference between active-passive and active-active, and how failover actually promotes a new leader without corrupting data.
Availability is a number
Availability is the fraction of time the system serves requests correctly:
\[ A = \frac{\text{uptime}}{\text{uptime} + \text{downtime}} \]
Quoted in “nines”, each nine cuts downtime by 10×:
| Nines | Availability | Downtime / year | Downtime / day |
|---|---|---|---|
| 2 | 99% | ~3.65 days | ~14.4 min |
| 3 | 99.9% | ~8.8 hours | ~1.4 min |
| 4 | 99.99% | ~52.6 min | ~8.6 s |
| 5 | 99.999% | ~5.3 min | ~0.86 s |
The jump from three to four nines is the hard one: you must eliminate almost all human-operated recovery, because a single manual restart can consume the entire annual budget.
Composition: series vs parallel
Availability composes like electrical components.
In series (all must work), multiply: a request hitting an LB and an app server and a database has
\[ A_{\text{series}} = A_1 \times A_2 \times \cdots \times A_n \]
Three 99.9% components in series give \(0.999^3 \approx 99.7\%\) — worse than any one of them. This is the brutal truth of dependencies: a chain is as weak as its product, and long chains erode availability fast. Reducing dependencies is a reliability strategy.
In parallel (any one suffices), the probability that all fail multiplies:
\[ A_{\text{parallel}} = 1 - (1 - A_1)(1 - A_2)\cdots(1 - A_n) \]
Two 99.9% redundant components give \(1 - 0.001^2 = 99.9999\%\). Redundancy is the lever — but only if failures are independent. Redundancy where both copies fail together (same rack, same power, same deploy bug) buys nothing.
\begin{tikzpicture}[font=\rmfamily, >=stealth,
b/.style={draw, thick, rounded corners=3pt, minimum width=1.5cm, minimum height=0.65cm, align=center, font=\rmfamily\small},
a/.style={->, thick}]
\node[b, fill=blue!10] (a1) at (0,0.9) {99.9};
\node[b, fill=blue!10] (a2) at (0,0) {99.9};
\node[b, fill=blue!10] (a3) at (0,-0.9) {99.9};
\node[font=\small, anchor=west] at (1.0,0.9) {series: $0.999^3 \approx 99.7\%$};
\node[b, fill=green!14] (p1) at (4.0,0.9) {99.9};
\node[b, fill=green!14] (p2) at (4.0,0) {99.9};
\node[font=\small, anchor=west] at (5.0,0.45) {parallel: $99.9999\%$};
\draw[a] (a3) -- (a2); \draw[a] (a2) -- (a1);
\end{tikzpicture}
def series(*a):
r = 1.0
for x in a: r *= x
return r
def parallel(*a):
r = 1.0
for x in a: r *= (1 - x)
return 1 - r
print(f"series 3x0.999 = {series(0.999,0.999,0.999):.6f}")
print(f"parallel 2x0.999 = {parallel(0.999,0.999):.6f}")
print(f"realistic chain = {series(0.999,0.999,0.9999,0.999):.6f}") # LB+app+db+cache
# the weakest link dominates the product
Redundancy patterns: active-passive vs active-active
Redundancy needs a plan for which copy serves traffic and what happens when one dies.
- Active-passive (master-slave). One node serves; the standby replicates and waits. On failure, promote the standby (failover). Simple to reason about; wastes the standby’s capacity; failover takes time and can lose recent writes if replication was asynchronous.
- Active-active (master-master). Multiple nodes serve simultaneously. Better utilization and faster failover (traffic just shifts), but concurrent writes to different masters create conflicts that must be resolved (last-write-wins, CRDTs, or partitioned ownership).
\begin{tikzpicture}[font=\rmfamily, >=stealth,
b/.style={draw, thick, rounded corners=3pt, minimum width=1.8cm, minimum height=0.72cm, align=center, font=\rmfamily\small},
a/.style={->, thick}]
% active-passive
\node[font=\small] at (-2.6,1.5) {active-passive};
\node[b, fill=green!14] (ap1) at (-3.8,0.5) {active};
\node[b, fill=gray!12, dashed] (ap2) at (-1.4,0.5) {passive};
\draw[a] (ap1) -- (ap2) node[midway, above, font=\scriptsize] {replicate};
% active-active
\node[font=\small] at (2.6,1.5) {active-active};
\node[b, fill=green!14] (aa1) at (1.4,0.5) {active};
\node[b, fill=green!14] (aa2) at (3.8,0.5) {active};
\draw[a, <->] (aa1) -- (aa2) node[midway, above, font=\scriptsize] {replicate};
\end{tikzpicture}
In practice, most “active-active” databases avoid true master-master by partitioning ownership: each shard has exactly one writer at a time, so writes never conflict. They are active-active at the system level and single-master per partition.
Failover: how a new leader is chosen
Failover is the sequence that turns a dead leader into a live one:
- Detect the failure via health checks, heartbeats, or timeouts.
- Elect a new leader (consensus like Raft/Paxos, or an external coordinator).
- Reconfigure clients to point at the new leader (DNS, service discovery, or a proxy).
- Reconcile — the new leader may be missing the last few writes if replication lagged.
Two dangers:
- Split-brain. A partition makes each side think it is the leader, and both accept writes. Resolved by requiring a quorum (majority) to elect a leader, so only one side can win. This is exactly the CP choice from Chapter 3.
- False failover. A slow-but-alive leader is declared dead, a new one is promoted, and the old one returns. Quorums and fencing tokens prevent the old leader from continuing to write.
\begin{tikzpicture}[font=\rmfamily, >=stealth,
b/.style={draw, thick, rounded corners=3pt, minimum width=1.7cm, minimum height=0.68cm, align=center, font=\rmfamily\small},
a/.style={->, thick}]
\node[b, fill=gray!12] (d) at (-3.6,0) {leader dies};
\node[b, fill=orange!16] (e) at (-1.2,0) {elect};
\node[b, fill=blue!10] (r) at (1.2,0) {redirect};
\node[b, fill=green!14] (n) at (3.6,0) {new leader};
\draw[a] (d) -- (e); \draw[a] (e) -- (r); \draw[a] (r) -- (n);
\end{tikzpicture}
Replication and the availability cost
Replication is the mechanism behind both patterns, and its consistency choice (Chapter 4) changes your availability:
- Synchronous replication — the write is acknowledged only after a replica confirms. No data loss on failover, but if the replica is slow, the primary is slow; if it is down, writes may block. Availability and latency suffer.
- Asynchronous replication — the primary acknowledges immediately and replicates later. Fast and available, but failover can lose the tail of writes.
Half-way options (semi-synchronous, quorum writes like \(W\) of \(N\)) let you tune the point: \(W=1\) favors speed, \(W=\text{majority}\) favors durability.
Designing to a target
To hit a target, work backward. Suppose a service depends on an LB (99.99%), three replicas of an app (99.9% each, in parallel), and a database with a primary plus a quorum-based failover (99.95%). The app pool is \(1-0.001^3 = 99.9999\%\), but the series product with the LB and DB is about \(0.9999 \times 0.999999 \times 0.9995 \approx 99.94\%\) — three nines, not five. The database and the LB dominate. Improving the app replicas further is wasted effort.
That calculation is the whole discipline: measure each component, compose them, and spend the reliability budget where the product is weakest.
Pitfalls
- Promising a number you cannot compose. Five nines across a chain of third-party APIs is usually a fantasy. Do the multiplication first.
- Correlated redundancy. Two replicas in one rack fail together. Independence is required for the parallel formula to help.
- Failover without quorum. Automatic promotion without majority leads to split-brain and double writes.
- Ignoring failover time. “Available” must include the seconds-to-minutes of detection, election, and client reconfiguration; during that window requests fail.
- Synchronous replication by default. It converts replica latency into user latency and replica downtime into write downtime. Choose deliberately.
Why does a chain of 99.9% components give worse than 99.9%? What is the only way to improve availability, and what undermines it?
ASolution
In series, availabilities multiply, so \(0.999^3 \approx 99.7\%\) — dependencies only hurt. The lever is redundancy in parallel, \(1-(1-A)^n\). It is undermined by correlated failures (shared rack, power, network, or a bug deployed everywhere at once), which make the failures less than independent.
Next: Background Jobs (System Design #6) — taking slow work off the request path so availability is not hostage to a mail server.