System Design (High-Level Design) Module 3 – Performance and reliability fundamentals
Availability maths: nines, series and parallel
Turn nines into allowed downtime, compute the availability of parts in series and in parallel, and see why shared causes break the redundancy you counted.
What you will learn
- Convert availability targets into allowed downtime over a day, a month and a year
- Compute the availability of components in series and in parallel
- Compare rarer failures with faster recovery, using MTBF and MTTR
- Explain why independence assumptions often fail, and what removes shared causes
Before you start
What you’ll learn · Before you start
What you will learn
- Convert availability targets into allowed downtime over a day, a month and a year
- Compute the availability of components in series and in parallel
- Compare rarer failures with faster recovery, using MTBF and MTTR
- Explain why independence assumptions often fail, and what removes shared causes
Before you start
On this page
Availability is the share of time, or of requests, for which a service works. It is written in “nines”: 99.9% is three nines and allows 43.2 minutes of downtime in a 30-day month; 99.99% is four nines and allows 4.32 minutes. To estimate a design’s availability, combine its parts. Parts that are all needed, one after another, are in series, and their availabilities multiply, so the whole is weaker than its weakest part. Redundant parts of which any one is enough are in parallel, and the whole is down only when all of them are, so two 99% replicas give 99.99%. Both formulas assume that parts fail independently, and real failures often share a cause. Each step below is worked through with numbers.
Each nine divides the allowed downtime by ten
A target means little until it is turned into minutes, and the period it is measured over matters as much as the number. This calculator turns targets into downtime for five periods, and a month’s outages back into a percentage; change the lists at the top and run it again:
"""Availability targets as allowed downtime, and downtime as availability.
Edit TARGETS or OUTAGES and run it again. The year is 365.25 days and the quarter a quarter of it; the month is
30 days, the month most availability tables use. "Nines" is -log10(1 - availability): 99.9% is 3 nines.
"""
import math
TARGETS = [99.0, 99.5, 99.9, 99.95, 99.99, 99.999] # percent
OUTAGES = [(1, 43.2), (2, 12.0), (3, 4.5)] # (outages in a 30-day month, minutes each)
PERIODS = [("day", 1), ("week", 7), ("30-day month", 30), ("quarter", 365.25 / 4), ("year", 365.25)]
def readable(minutes):
"""Minutes as the largest unit that keeps the number at 1 or more."""
if minutes >= 60:
return f"{minutes / 60:.2f} h"
if minutes >= 1:
return f"{minutes:.2f} min"
return f"{minutes * 60:.1f} s"
print(f"{'target':>8}{'nines':>7}" + "".join(f"{name:>14}" for name, _ in PERIODS))
for target in TARGETS:
down = 1 - target / 100
nines = -math.log10(down)
print(f"{target:>7}%{nines:>7.1f}" + "".join(f"{readable(days * 1440 * down):>14}" for _, days in PERIODS))
print("\nWhat a month of outages leaves")
for count, minutes in OUTAGES:
down = count * minutes
availability = 100 * (1 - down / (30 * 1440))
outages = "1 outage" if count == 1 else f"{count} outages"
print(f"{outages} of {minutes:g} min = {down:g} min down: {availability:.3f}% for the month") Output
target nines day week 30-day month quarter year 99.0% 2.0 14.40 min 1.68 h 7.20 h 21.92 h 87.66 h 99.5% 2.3 7.20 min 50.40 min 3.60 h 10.96 h 43.83 h 99.9% 3.0 1.44 min 10.08 min 43.20 min 2.19 h 8.77 h 99.95% 3.3 43.2 s 5.04 min 21.60 min 1.10 h 4.38 h 99.99% 4.0 8.6 s 1.01 min 4.32 min 13.15 min 52.60 min 99.999% 5.0 0.9 s 6.0 s 25.9 s 1.31 min 5.26 min What a month of outages leaves 1 outage of 43.2 min = 43.2 min down: 99.900% for the month 2 outages of 12 min = 24 min down: 99.944% for the month 3 outages of 4.5 min = 13.5 min down: 99.969% for the month
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 nines.py
Runs on this device, in your browser. The first run downloads Python (about 13.5 MB), which is kept for the next runs.
Your run, in this browser
Each extra nine divides the allowed downtime by ten. At 99.9%, a day allows 1.44 minutes and a year 8.77 hours (with a year of 365.25 days); at 99.99%, a year allows 52.6 minutes and a day only 8.6 seconds. The second block runs the other way: one 43.2-minute outage spends the whole of a month’s 99.9%, while three outages of 4.5 minutes leave 99.969%. The quality-attributes lesson showed what each downtime budget: The time a service may be unavailable over a stated period and still meet its availability target. At 99.9% a 30-day month allows 43.2 minutes, at 99.99% only 4.32. More in “Quality attributes and how to trade them off” means for how a team works; this lesson is about how the parts of a design add up to one number.
Availability can be counted in two ways. AWS’s availability whitepaper defines it by time, as uptime divided by uptime plus downtime. Google’s SRE book counts requests instead: the share of requests that succeed, because a service that runs in many places is almost never down everywhere at once, so minutes of total outage say little about what users met. A service that answers 2.5 million requests a day with a daily target of 99.99% may fail 250 of them. Counting requests also captures the partial outages that a time-based count misses, which the SLO lesson of this module builds on.
Key idea
A target is a downtime budget over a stated period: 99.9 % is 43.2 minutes in a 30-day month and 8.77 hours in a year, and each further nine divides it by ten.
Checkpoint
Check: Nines as downtime
Parts in series multiply
If a request needs every part of a chain, it succeeds only when all of them work at once. With independent parts, the availability of the chain is the product of theirs:
Two 99.9% services in a row give 99.8001%: their unavailabilities, 0.1% each, roughly add up. That rule of thumb is the quickest check in a design round: a load balancer at 99.99%, an app tier at 99.95% and a database at 99.9% leave about 0.01 + 0.05 + 0.1 = 0.16% of failure, so the path is about 99.84%. Every extra hard dependency: A part that every request needs, so the service fails whenever it does. Hard dependencies are in series, and each one lowers the availability the whole service can reach. lowers the ceiling, which is why AWS’s whitepaper says that reducing dependencies improves availability, and that a workload’s dependencies should have goals at least as high as its own. The same paper adds that the product is only a rough estimate: published figures are targets, and dependencies often do better than their stated SLAs. Step along that three-part path, one part at a time:
The drawing shows the whole scene; its 4 steps are listed below.
Every step as text
- The load balancer. The request needs the load balancer first. On its own the path is as available as that one part, 99.99 %.
- Times the app tier. It also needs the app tier, so multiply, 0.9999 × 0.9995 = 0.9994. The path is now weaker than either part.
- Times the database. And the database, 0.9994 × 0.999 = 0.9984. Three good parts make a path of 99.84 %, below the weakest of them.
- The quick check. For small numbers the unavailabilities add instead, 0.01 % + 0.05 % + 0.1 % = 0.16 %, which also gives 99.84 %. Each extra hard dependency adds its own share.
Checkpoint
Check: Parts in series
Redundant parts fail only when all of them fail
If any one of several parts is enough, the group fails only when all of them have failed at the same time. With independent parts, multiply the chances of failure instead:
Two 99% replicas give 1 − 0.01 × 0.01 = 99.99%, and three give 99.9999%. Two things change this in practice. First, redundancy often has to cover capacity as well: if the peak needs two of three instances, the tier is up only while at least two are, which is a weaker condition than “any one”. Second, failing over takes time: a standby that needs a minute to take over adds a minute of downtime to every failure of the primary. This program puts both into one checkout path; its 14 versions, one per tab, printed exactly the lines shown below them:
Python 3.14 · main.py
from math import comb
MONTH = 30 * 24 * 60
def series(*parts: float) -> float:
"""All parts are needed: multiply."""
result = 1.0
for a in parts:
result *= a
return result
def parallel(*parts: float) -> float:
"""Any one part is enough: down only when all are down."""
down = 1.0
for a in parts:
down *= 1 - a
return 1 - down
def at_least(k: int, n: int, a: float) -> float:
"""At least k of n identical parts must be up."""
return sum(comb(n, up) * a**up * (1 - a) ** (n - up) for up in range(k, n + 1))
def from_mtbf(mtbf: float, mttr: float) -> float:
return mtbf / (mtbf + mttr)
def show(name: str, a: float) -> None:
print(f" {name:38}{a * 100:8.4f}% down {(1 - a) * MONTH:4.1f} min a month")
print(f"any 2 of 3 replicas at 99%: {at_least(2, 3, 0.99) * 100:.4f}%")
lb, payments = 0.9999, 0.9995
app = at_least(2, 3, 0.995)
db = parallel(0.999, 0.999) - 2 / MONTH # less 2 one-minute failovers
print("\nCheckout path")
show("load balancer", lb)
show("app tier (2 of 3)", app)
show("database pair", db)
show("payment provider", payments)
show("whole path", series(lb, app, db, payments))
print("\nRarer failures or faster recovery")
show("every 30 days, 60 min to recover", from_mtbf(720, 1))
show("every 60 days, 60 min to recover", from_mtbf(1440, 1))
show("every 30 days, 5 min to recover", from_mtbf(720, 5 / 60)) In Python: math.comb counts the ways to choose k of n, and *parts collects any number of availabilities into a tuple; a**up is the power.
Recorded with CPython 3.14.8 on macOS 26 arm64. It runs in your browser with Pyodide 314.0.7 (CPython 3.14.2). To run it yourself: python3 main.py
JavaScript Node 24 · main.mjs
const MONTH = 30 * 24 * 60;
// All parts are needed: multiply.
const series = (...parts) => parts.reduce((result, a) => result * a, 1);
// Any one part is enough: down only when all are down.
const parallel = (...parts) => 1 - parts.reduce((down, a) => down * (1 - a), 1);
function comb(n, k) {
let ways = 1;
for (let i = 1; i <= k; i++) ways = (ways * (n - k + i)) / i;
return ways;
}
// At least k of n identical parts must be up.
function atLeast(k, n, a) {
let sum = 0;
for (let up = k; up <= n; up++) sum += comb(n, up) * a ** up * (1 - a) ** (n - up);
return sum;
}
const fromMtbf = (mtbf, mttr) => mtbf / (mtbf + mttr);
function show(name, a) {
const down = ((1 - a) * MONTH).toFixed(1).padStart(4);
console.log(` ${name.padEnd(38)}${(a * 100).toFixed(4).padStart(8)}% down ${down} min a month`);
}
console.log(`any 2 of 3 replicas at 99%: ${(atLeast(2, 3, 0.99) * 100).toFixed(4)}%`);
const [lb, payments] = [0.9999, 0.9995];
const app = atLeast(2, 3, 0.995);
const db = parallel(0.999, 0.999) - 2 / MONTH; // less 2 one-minute failovers
console.log("\nCheckout path");
show("load balancer", lb);
show("app tier (2 of 3)", app);
show("database pair", db);
show("payment provider", payments);
show("whole path", series(lb, app, db, payments));
console.log("\nRarer failures or faster recovery");
show("every 30 days, 60 min to recover", fromMtbf(720, 1));
show("every 60 days, 60 min to recover", fromMtbf(1440, 1));
show("every 30 days, 5 min to recover", fromMtbf(720, 5 / 60)); In JavaScript: The rest parameter ...parts takes any number of availabilities, and reduce multiplies them; JavaScript has no binomial function, so comb is written out.
Recorded with Node.js 24.21.0 LTS (V8 13.6) on macOS 26 arm64. It runs in your browser with QuickJS (quickjs-emscripten 0.32.0). To run it yourself: node main.mjs
Java 25 LTS · Main.java
import java.util.Locale;
public class Main {
static final double MONTH = 30 * 24 * 60;
// All parts are needed: multiply.
static double series(double... parts) {
double result = 1;
for (double a : parts) {
result *= a;
}
return result;
}
// Any one part is enough: down only when all are down.
static double parallel(double... parts) {
double down = 1;
for (double a : parts) {
down *= 1 - a;
}
return 1 - down;
}
static long comb(int n, int k) {
long ways = 1;
for (int i = 1; i <= k; i++) {
ways = ways * (n - k + i) / i;
}
return ways;
}
// At least k of n identical parts must be up.
static double atLeast(int k, int n, double a) {
double sum = 0;
for (int up = k; up <= n; up++) {
sum += comb(n, up) * Math.pow(a, up) * Math.pow(1 - a, n - up);
}
return sum;
}
static double fromMtbf(double mtbf, double mttr) {
return mtbf / (mtbf + mttr);
}
static void show(String name, double a) {
System.out.printf(" %-38s%8.4f%% down %4.1f min a month%n", name, a * 100, (1 - a) * MONTH);
}
public static void main(String[] args) {
Locale.setDefault(Locale.ROOT);
System.out.printf("any 2 of 3 replicas at 99%%: %.4f%%%n", atLeast(2, 3, 0.99) * 100);
double lb = 0.9999;
double payments = 0.9995;
double app = atLeast(2, 3, 0.995);
double db = parallel(0.999, 0.999) - 2 / MONTH; // less 2 one-minute failovers
System.out.println("\nCheckout path");
show("load balancer", lb);
show("app tier (2 of 3)", app);
show("database pair", db);
show("payment provider", payments);
show("whole path", series(lb, app, db, payments));
System.out.println("\nRarer failures or faster recovery");
show("every 30 days, 60 min to recover", fromMtbf(720, 1));
show("every 60 days, 60 min to recover", fromMtbf(1440, 1));
show("every 30 days, 5 min to recover", fromMtbf(720, 5.0 / 60));
}
} In Java: The varargs double... parts take any number of availabilities, and main sets Locale.ROOT, so printf's decimal point cannot become a comma.
Recorded with OpenJDK 25.0.4.1 LTS (Eclipse Temurin) on macOS 26 arm64. It runs in your browser with a TeaVM 0.16.0 build in QuickJS (quickjs-emscripten 0.32.0). To run it yourself: java Main.java
C++23 · main.cpp
#include <cmath>
#include <initializer_list>
#include <print>
#include <string_view>
constexpr double month = 30 * 24 * 60;
// All parts are needed: multiply.
double series(std::initializer_list<double> parts) {
double result = 1;
for (const double a : parts) {
result *= a;
}
return result;
}
// Any one part is enough: down only when all are down.
double parallel(std::initializer_list<double> parts) {
double down = 1;
for (const double a : parts) {
down *= 1 - a;
}
return 1 - down;
}
long long comb(int n, int k) {
long long ways = 1;
for (int i = 1; i <= k; ++i) {
ways = ways * (n - k + i) / i;
}
return ways;
}
// At least k of n identical parts must be up.
double at_least(int k, int n, double a) {
double sum = 0;
for (int up = k; up <= n; ++up) {
sum += comb(n, up) * std::pow(a, up) * std::pow(1 - a, n - up);
}
return sum;
}
double from_mtbf(double mtbf, double mttr) { return mtbf / (mtbf + mttr); }
void show(std::string_view name, double a) {
std::println(" {:<38}{:8.4f}% down {:4.1f} min a month", name, a * 100,
(1 - a) * month);
}
int main() {
std::println("any 2 of 3 replicas at 99%: {:.4f}%",
at_least(2, 3, 0.99) * 100);
const double lb = 0.9999;
const double payments = 0.9995;
const double app = at_least(2, 3, 0.995);
const double db =
parallel({0.999, 0.999}) - 2 / month; // less 2 one-minute failovers
std::println("\nCheckout path");
show("load balancer", lb);
show("app tier (2 of 3)", app);
show("database pair", db);
show("payment provider", payments);
show("whole path", series({lb, app, db, payments}));
std::println("\nRarer failures or faster recovery");
show("every 30 days, 60 min to recover", from_mtbf(720, 1));
show("every 60 days, 60 min to recover", from_mtbf(1440, 1));
show("every 30 days, 5 min to recover", from_mtbf(720, 5.0 / 60));
} In C++: An initializer_list lets series and parallel take any number of availabilities, and std::println writes the fixed decimals.
Recorded with Apple clang 21.0.0 (C++23) and GCC 16.2.0 on macOS 26 arm64. It runs in your browser with Clang in WebAssembly (YoWASP) 22.0.0-git20542-10. To run it yourself: clang++ -std=c++23 -O2 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined main.cpp -o main && ./main
C# 14 · .NET 10 · app.cs
using System.Globalization;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
const double Month = 30 * 24 * 60;
Console.WriteLine($"any 2 of 3 replicas at 99%: {AtLeast(2, 3, 0.99) * 100:F4}%");
double lb = 0.9999, payments = 0.9995;
double app = AtLeast(2, 3, 0.995);
double db = Parallel(0.999, 0.999) - 2 / Month; // less 2 one-minute failovers
Console.WriteLine("\nCheckout path");
Show("load balancer", lb, Month);
Show("app tier (2 of 3)", app, Month);
Show("database pair", db, Month);
Show("payment provider", payments, Month);
Show("whole path", Series(lb, app, db, payments), Month);
Console.WriteLine("\nRarer failures or faster recovery");
Show("every 30 days, 60 min to recover", FromMtbf(720, 1), Month);
Show("every 60 days, 60 min to recover", FromMtbf(1440, 1), Month);
Show("every 30 days, 5 min to recover", FromMtbf(720, 5.0 / 60), Month);
// All parts are needed: multiply.
static double Series(params double[] parts) => parts.Aggregate(1.0, (result, a) => result * a);
// Any one part is enough: down only when all are down.
static double Parallel(params double[] parts) => 1 - parts.Aggregate(1.0, (d, a) => d * (1 - a));
static long Comb(int n, int k)
{
long ways = 1;
for (int i = 1; i <= k; i++)
{
ways = ways * (n - k + i) / i;
}
return ways;
}
// At least k of n identical parts must be up.
static double AtLeast(int k, int n, double a) => Enumerable.Range(k, n - k + 1)
.Sum(up => Comb(n, up) * Math.Pow(a, up) * Math.Pow(1 - a, n - up));
static double FromMtbf(double mtbf, double mttr) => mtbf / (mtbf + mttr);
static void Show(string name, double a, double month) =>
Console.WriteLine($" {name,-38}{a * 100,8:F4}% down {(1 - a) * month,4:F1} min a month"); In C#: params double[] takes any number of availabilities and Aggregate folds them; the month's minutes are a const passed to Show.
Recorded with C# 14 on .NET 10.0.12 (SDK 10.0.401) on macOS 26 arm64. It runs in your browser with the .NET runtime for WebAssembly 10.0.12. To run it yourself: dotnet run app.cs
C23 · main.c
#include <math.h>
#include <stddef.h>
#include <stdio.h>
constexpr double month = 30 * 24 * 60;
// All parts are needed: multiply.
static double series(const double parts[], size_t n) {
double result = 1;
for (size_t i = 0; i < n; i++) {
result *= parts[i];
}
return result;
}
// Any one part is enough: down only when all are down.
static double parallel(const double parts[], size_t n) {
double down = 1;
for (size_t i = 0; i < n; i++) {
down *= 1 - parts[i];
}
return 1 - down;
}
static long long comb(int n, int k) {
long long ways = 1;
for (int i = 1; i <= k; i++) {
ways = ways * (n - k + i) / i;
}
return ways;
}
// At least k of n identical parts must be up.
static double at_least(int k, int n, double a) {
double sum = 0;
for (int up = k; up <= n; up++) {
sum += (double)comb(n, up) * pow(a, up) * pow(1 - a, n - up);
}
return sum;
}
static double from_mtbf(double mtbf, double mttr) {
return mtbf / (mtbf + mttr);
}
static void show(const char *name, double a) {
printf(" %-38s%8.4f%% down %4.1f min a month\n", name, a * 100,
(1 - a) * month);
}
int main(void) {
printf("any 2 of 3 replicas at 99%%: %.4f%%\n", at_least(2, 3, 0.99) * 100);
const double lb = 0.9999;
const double payments = 0.9995;
const double app = at_least(2, 3, 0.995);
// less 2 one-minute failovers
const double db = parallel((double[]){0.999, 0.999}, 2) - 2 / month;
puts("\nCheckout path");
show("load balancer", lb);
show("app tier (2 of 3)", app);
show("database pair", db);
show("payment provider", payments);
show("whole path", series((double[]){lb, app, db, payments}, 4));
puts("\nRarer failures or faster recovery");
show("every 30 days, 60 min to recover", from_mtbf(720, 1));
show("every 60 days, 60 min to recover", from_mtbf(1440, 1));
show("every 30 days, 5 min to recover", from_mtbf(720, 5.0 / 60));
return 0;
} In C: A C function receives an array as a pointer and a count, so compound literals such as (double[]){0.999, 0.999} pass each list with its length.
Recorded with Apple clang 21.0.0 (C23) and GCC 16.2.0 on macOS 26 arm64. It runs in your browser with Clang in WebAssembly (YoWASP) 22.0.0-git20542-10. To run it yourself: clang -std=c23 -O2 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined main.c -o main && ./main
PHP 8.5 · main.php
<?php
declare(strict_types=1);
const MONTH = 30 * 24 * 60;
/** All parts are needed: multiply. */
function series(float ...$parts): float
{
return array_reduce($parts, fn(float $result, float $a): float => $result * $a, 1.0);
}
/** Any one part is enough: down only when all are down. */
function parallel(float ...$parts): float
{
return 1 - array_reduce($parts, fn(float $down, float $a): float => $down * (1 - $a), 1.0);
}
function comb(int $n, int $k): int
{
$ways = 1;
for ($i = 1; $i <= $k; $i++) {
$ways = intdiv($ways * ($n - $k + $i), $i);
}
return $ways;
}
/** At least k of n identical parts must be up. */
function atLeast(int $k, int $n, float $a): float
{
$sum = 0.0;
for ($up = $k; $up <= $n; $up++) {
$sum += comb($n, $up) * $a ** $up * (1 - $a) ** ($n - $up);
}
return $sum;
}
function fromMtbf(float $mtbf, float $mttr): float
{
return $mtbf / ($mtbf + $mttr);
}
function show(string $name, float $a): void
{
printf(" %-38s%8.4f%% down %4.1f min a month\n", $name, $a * 100, (1 - $a) * MONTH);
}
printf("any 2 of 3 replicas at 99%%: %.4f%%\n", atLeast(2, 3, 0.99) * 100);
[$lb, $payments] = [0.9999, 0.9995];
$app = atLeast(2, 3, 0.995);
$db = parallel(0.999, 0.999) - 2 / MONTH; // less 2 one-minute failovers
echo "\nCheckout path\n";
show('load balancer', $lb);
show('app tier (2 of 3)', $app);
show('database pair', $db);
show('payment provider', $payments);
show('whole path', series($lb, $app, $db, $payments));
echo "\nRarer failures or faster recovery\n";
show('every 30 days, 60 min to recover', fromMtbf(720, 1));
show('every 60 days, 60 min to recover', fromMtbf(1440, 1));
show('every 30 days, 5 min to recover', fromMtbf(720, 5 / 60)); In PHP: The ** operator binds tighter than *, so the k-of-n term needs no brackets, and float ...$parts takes any number of availabilities.
Recorded with PHP 8.5.11 (CLI) on macOS 26 arm64. It runs in your browser with php-wasm 0.2.0 (PHP 8.5.2). To run it yourself: php main.php
Rust 1.99 · main.rs
const MONTH: f64 = 30.0 * 24.0 * 60.0;
/// All parts are needed: multiply.
fn series(parts: &[f64]) -> f64 {
parts.iter().product()
}
/// Any one part is enough: down only when all are down.
fn parallel(parts: &[f64]) -> f64 {
1.0 - parts.iter().map(|a| 1.0 - a).product::<f64>()
}
fn comb(n: u32, k: u32) -> u64 {
(1..=u64::from(k)).fold(1, |ways, i| ways * (u64::from(n - k) + i) / i)
}
/// At least k of n identical parts must be up.
fn at_least(k: u32, n: u32, a: f64) -> f64 {
(k..=n)
.map(|up| comb(n, up) as f64 * a.powi(up as i32) * (1.0 - a).powi((n - up) as i32))
.sum()
}
fn from_mtbf(mtbf: f64, mttr: f64) -> f64 {
mtbf / (mtbf + mttr)
}
fn show(name: &str, a: f64) {
println!(
" {name:38}{:8.4}% down {:4.1} min a month",
a * 100.0,
(1.0 - a) * MONTH
);
}
fn main() {
println!(
"any 2 of 3 replicas at 99%: {:.4}%",
at_least(2, 3, 0.99) * 100.0
);
let (lb, payments) = (0.9999, 0.9995);
let app = at_least(2, 3, 0.995);
let db = parallel(&[0.999, 0.999]) - 2.0 / MONTH; // less 2 one-minute failovers
println!("\nCheckout path");
show("load balancer", lb);
show("app tier (2 of 3)", app);
show("database pair", db);
show("payment provider", payments);
show("whole path", series(&[lb, app, db, payments]));
println!("\nRarer failures or faster recovery");
show("every 30 days, 60 min to recover", from_mtbf(720.0, 1.0));
show("every 60 days, 60 min to recover", from_mtbf(1440.0, 1.0));
show(
"every 30 days, 5 min to recover",
from_mtbf(720.0, 5.0 / 60.0),
);
} In Rust: product() multiplies an iterator's values, and powi raises a float to a whole power, which is all the k-of-n term needs.
Recorded with rustc 1.99.0 (edition 2024) on macOS 26 arm64. It runs in your browser with a WebAssembly build on the WASI runner (browser_wasi_shim 0.4.2). To run it yourself: rustc --edition 2024 -O main.rs && ./main
TypeScript 6.0 · main.ts
const MONTH = 30 * 24 * 60;
// All parts are needed: multiply.
const series = (...parts: number[]): number => parts.reduce((result, a) => result * a, 1);
// Any one part is enough: down only when all are down.
const parallel = (...parts: number[]): number => 1 - parts.reduce((down, a) => down * (1 - a), 1);
function comb(n: number, k: number): number {
let ways = 1;
for (let i = 1; i <= k; i++) ways = (ways * (n - k + i)) / i;
return ways;
}
// At least k of n identical parts must be up.
function atLeast(k: number, n: number, a: number): number {
let sum = 0;
for (let up = k; up <= n; up++) sum += comb(n, up) * a ** up * (1 - a) ** (n - up);
return sum;
}
const fromMtbf = (mtbf: number, mttr: number): number => mtbf / (mtbf + mttr);
function show(name: string, a: number): void {
const down = ((1 - a) * MONTH).toFixed(1).padStart(4);
console.log(` ${name.padEnd(38)}${(a * 100).toFixed(4).padStart(8)}% down ${down} min a month`);
}
console.log(`any 2 of 3 replicas at 99%: ${(atLeast(2, 3, 0.99) * 100).toFixed(4)}%`);
const [lb, payments] = [0.9999, 0.9995];
const app = atLeast(2, 3, 0.995);
const db = parallel(0.999, 0.999) - 2 / MONTH; // less 2 one-minute failovers
console.log("\nCheckout path");
show("load balancer", lb);
show("app tier (2 of 3)", app);
show("database pair", db);
show("payment provider", payments);
show("whole path", series(lb, app, db, payments));
console.log("\nRarer failures or faster recovery");
show("every 30 days, 60 min to recover", fromMtbf(720, 1));
show("every 60 days, 60 min to recover", fromMtbf(1440, 1));
show("every 30 days, 5 min to recover", fromMtbf(720, 5 / 60)); In TypeScript: The rest parameter is typed number[]; the rest is the JavaScript program, on the same doubles.
Recorded with TypeScript 6.0.3 (strict), run by Node.js 24.21.0 on macOS 26 arm64. It runs in your browser with QuickJS (quickjs-emscripten 0.32.0) after Sucrase 3.35.1. To run it yourself: npx -p typescript@6.0.3 tsc --noEmit --strict main.ts && node main.ts
Go 1.27 · main.go
package main
import (
"fmt"
"math"
)
const month = 30 * 24 * 60
// series: all parts are needed, so multiply.
func series(parts ...float64) float64 {
result := 1.0
for _, a := range parts {
result *= a
}
return result
}
// parallel: any one part is enough, so it is down only when all are.
func parallel(parts ...float64) float64 {
down := 1.0
for _, a := range parts {
down *= 1 - a
}
return 1 - down
}
func comb(n, k int) int {
ways := 1
for i := 1; i <= k; i++ {
ways = ways * (n - k + i) / i
}
return ways
}
// atLeast: at least k of n identical parts must be up.
func atLeast(k, n int, a float64) float64 {
sum := 0.0
for up := k; up <= n; up++ {
sum += float64(comb(n, up)) * math.Pow(a, float64(up)) * math.Pow(1-a, float64(n-up))
}
return sum
}
func fromMtbf(mtbf, mttr float64) float64 {
return mtbf / (mtbf + mttr)
}
func show(name string, a float64) {
fmt.Printf(" %-38s%8.4f%% down %4.1f min a month\n", name, a*100, (1-a)*month)
}
func main() {
fmt.Printf("any 2 of 3 replicas at 99%%: %.4f%%\n", atLeast(2, 3, 0.99)*100)
lb, payments := 0.9999, 0.9995
app := atLeast(2, 3, 0.995)
db := parallel(0.999, 0.999) - 2.0/month // less 2 one-minute failovers
fmt.Println("\nCheckout path")
show("load balancer", lb)
show("app tier (2 of 3)", app)
show("database pair", db)
show("payment provider", payments)
show("whole path", series(lb, app, db, payments))
fmt.Println("\nRarer failures or faster recovery")
show("every 30 days, 60 min to recover", fromMtbf(720, 1))
show("every 60 days, 60 min to recover", fromMtbf(1440, 1))
show("every 30 days, 5 min to recover", fromMtbf(720, 5.0/60))
} In Go: Variadic parameters ...float64 take any number of availabilities, and math.Pow takes its exponent as a float64.
Recorded with Go 1.27.1 on macOS 26 arm64. It runs in your browser with the Go compiler in WebAssembly 1.27.1. To run it yourself: go run main.go
Swift 6.4 · main.swift
#if canImport(Darwin)
import Darwin
#elseif canImport(WASILibc)
import WASILibc
#endif
let month = 30.0 * 24 * 60
/// All parts are needed: multiply.
func series(_ parts: Double...) -> Double { parts.reduce(1, *) }
/// Any one part is enough: down only when all are down.
func parallel(_ parts: Double...) -> Double { 1 - parts.reduce(1) { $0 * (1 - $1) } }
func comb(_ n: Int, _ k: Int) -> Int {
(0..<k).reduce(1) { ways, i in ways * (n - k + i + 1) / (i + 1) }
}
/// At least k of n identical parts must be up.
func atLeast(_ k: Int, _ n: Int, _ a: Double) -> Double {
(k...n).reduce(0) { $0 + Double(comb(n, $1)) * pow(a, Double($1)) * pow(1 - a, Double(n - $1)) }
}
func fromMtbf(_ mtbf: Double, _ mttr: Double) -> Double { mtbf / (mtbf + mttr) }
/// Fixed decimals, since there is no String(format:) without Foundation.
func fixed(_ x: Double, _ digits: Int, width: Int) -> String {
let scale = Int(pow(10, Double(digits)))
let scaled = Int((x * Double(scale)).rounded())
let fraction = String(scaled % scale)
let text =
"\(scaled / scale)." + String(repeating: "0", count: digits - fraction.count) + fraction
return String(repeating: " ", count: max(0, width - text.count)) + text
}
func show(_ name: String, _ a: Double) {
let label = name + String(repeating: " ", count: max(0, 38 - name.count))
let down = fixed((1 - a) * month, 1, width: 4)
print(" \(label)\(fixed(a * 100, 4, width: 8))% down \(down) min a month")
}
print("any 2 of 3 replicas at 99%: \(fixed(atLeast(2, 3, 0.99) * 100, 4, width: 0))%")
let (lb, payments) = (0.9999, 0.9995)
let app = atLeast(2, 3, 0.995)
let db = parallel(0.999, 0.999) - 2 / month // less 2 one-minute failovers
print("\nCheckout path")
show("load balancer", lb)
show("app tier (2 of 3)", app)
show("database pair", db)
show("payment provider", payments)
show("whole path", series(lb, app, db, payments))
print("\nRarer failures or faster recovery")
show("every 30 days, 60 min to recover", fromMtbf(720, 1))
show("every 60 days, 60 min to recover", fromMtbf(1440, 1))
show("every 30 days, 5 min to recover", fromMtbf(720, 5.0 / 60)) In Swift: pow comes from the platform's C library (Darwin on macOS, WASILibc in WebAssembly), and fixed writes the decimals by hand, since there is no String(format:) without Foundation.
Recorded with Apple Swift 6.4 on macOS 26 arm64. It runs in your browser with a WebAssembly build on the WASI runner (browser_wasi_shim 0.4.2). To run it yourself: swiftc -O main.swift -o main && ./main
Ruby 4.0 · main.rb
# frozen_string_literal: true
MONTH = 30 * 24 * 60
# All parts are needed: multiply.
def series(*parts)
parts.reduce(1.0) { |result, part| result * part }
end
# Any one part is enough: down only when all are down.
def parallel(*parts)
1 - parts.reduce(1.0) { |down, part| down * (1 - part) }
end
def comb(count, chosen)
(1..chosen).reduce(1) { |ways, i| ways * (count - chosen + i) / i }
end
# At least k of n identical parts must be up.
def at_least(needed, count, share)
(needed..count).sum { |up| comb(count, up) * (share**up) * ((1 - share)**(count - up)) }
end
def from_mtbf(mtbf, mttr)
mtbf.fdiv(mtbf + mttr)
end
def show(name, share)
puts format(' %<name>-38s%<pct>8.4f%% down %<down>4.1f min a month',
name: name, pct: share * 100, down: (1 - share) * MONTH)
end
puts format('any 2 of 3 replicas at 99%%: %.4f%%', at_least(2, 3, 0.99) * 100)
lb = 0.9999
payments = 0.9995
app = at_least(2, 3, 0.995)
db = parallel(0.999, 0.999) - 2.0 / MONTH # less 2 one-minute failovers
puts "\nCheckout path"
show('load balancer', lb)
show('app tier (2 of 3)', app)
show('database pair', db)
show('payment provider', payments)
show('whole path', series(lb, app, db, payments))
puts "\nRarer failures or faster recovery"
show('every 30 days, 60 min to recover', from_mtbf(720, 1))
show('every 60 days, 60 min to recover', from_mtbf(1440, 1))
show('every 30 days, 5 min to recover', from_mtbf(720, 5.0 / 60)) In Ruby: Integer#fdiv divides as floats, so 720.fdiv(721) needs no conversion, and sum adds the k-of-n terms.
Recorded with CRuby 4.0.7 on macOS 26 arm64. It runs in your browser with ruby.wasm 2.10.1 (Ruby 4.0.0). To run it yourself: ruby main.rb
Kotlin 2.4 · Main.kt
import kotlin.math.pow
import kotlin.math.roundToLong
const val MONTH = 30.0 * 24 * 60
// All parts are needed: multiply.
fun series(vararg parts: Double) = parts.fold(1.0) { result, a -> result * a }
// Any one part is enough: down only when all are down.
fun parallel(vararg parts: Double) = 1 - parts.fold(1.0) { down, a -> down * (1 - a) }
fun comb(
n: Int,
k: Int,
) = (1..k).fold(1L) { ways, i -> ways * (n - k + i) / i }
// At least k of n identical parts must be up.
fun atLeast(
k: Int,
n: Int,
a: Double,
) = (k..n).sumOf { up -> comb(n, up) * a.pow(up) * (1 - a).pow(n - up) }
fun fromMtbf(
mtbf: Double,
mttr: Double,
) = mtbf / (mtbf + mttr)
// Fixed decimals, since the common standard library has no String.format.
fun fixed(
x: Double,
digits: Int,
): String {
val scale = 10.0.pow(digits).toLong()
val scaled = (x * scale).roundToLong()
return "${scaled / scale}.${(scaled % scale).toString().padStart(digits, '0')}"
}
fun show(
name: String,
a: Double,
) {
val down = fixed((1 - a) * MONTH, 1).padStart(4)
println(" ${name.padEnd(38)}${fixed(a * 100, 4).padStart(8)}% down $down min a month")
}
fun main() {
println("any 2 of 3 replicas at 99%: ${fixed(atLeast(2, 3, 0.99) * 100, 4)}%")
val (lb, payments) = 0.9999 to 0.9995
val app = atLeast(2, 3, 0.995)
val db = parallel(0.999, 0.999) - 2 / MONTH // less 2 one-minute failovers
println("\nCheckout path")
show("load balancer", lb)
show("app tier (2 of 3)", app)
show("database pair", db)
show("payment provider", payments)
show("whole path", series(lb, app, db, payments))
println("\nRarer failures or faster recovery")
show("every 30 days, 60 min to recover", fromMtbf(720.0, 1.0))
show("every 60 days, 60 min to recover", fromMtbf(1440.0, 1.0))
show("every 30 days, 5 min to recover", fromMtbf(720.0, 5.0 / 60))
} In Kotlin: vararg collects the availabilities into a DoubleArray, and fixed writes the decimals, since the common standard library has no String.format.
Recorded with Kotlin 2.4.20 on Java 25.0.4.1 on macOS 26 arm64. It runs in your browser with a WebAssembly build on the WASI runner (browser_wasi_shim 0.4.2). To run it yourself: kotlinc Main.kt -include-runtime -d main.jar && java -jar main.jar
Dart 3.13 · main.dart
import 'dart:math';
const month = 30 * 24 * 60;
/// All parts are needed: multiply.
double series(List<double> parts) => parts.fold(1.0, (result, a) => result * a);
/// Any one part is enough: down only when all are down.
double parallel(List<double> parts) =>
1 - parts.fold(1.0, (d, a) => d * (1 - a));
int comb(int n, int k) {
var ways = 1;
for (var i = 1; i <= k; i++) {
ways = ways * (n - k + i) ~/ i;
}
return ways;
}
/// At least k of n identical parts must be up.
double atLeast(int k, int n, double a) {
var sum = 0.0;
for (var up = k; up <= n; up++) {
sum += comb(n, up) * pow(a, up) * pow(1 - a, n - up);
}
return sum;
}
double fromMtbf(double mtbf, double mttr) => mtbf / (mtbf + mttr);
void show(String name, double a) {
final down = ((1 - a) * month).toStringAsFixed(1).padLeft(4);
print(
' ${name.padRight(38)}${(a * 100).toStringAsFixed(4).padLeft(8)}% down $down min a month',
);
}
void main() {
print(
'any 2 of 3 replicas at 99%: ${(atLeast(2, 3, 0.99) * 100).toStringAsFixed(4)}%',
);
const lb = 0.9999, payments = 0.9995;
final app = atLeast(2, 3, 0.995);
final db =
parallel([0.999, 0.999]) - 2 / month; // less 2 one-minute failovers
print('\nCheckout path');
show('load balancer', lb);
show('app tier (2 of 3)', app);
show('database pair', db);
show('payment provider', payments);
show('whole path', series([lb, app, db, payments]));
print('\nRarer failures or faster recovery');
show('every 30 days, 60 min to recover', fromMtbf(720, 1));
show('every 60 days, 60 min to recover', fromMtbf(1440, 1));
show('every 30 days, 5 min to recover', fromMtbf(720, 5 / 60));
} In Dart: pow from dart:math returns a num, which the double arithmetic around it accepts, and ~/ is integer division in comb.
Recorded with Dart 3.13.5 on macOS 26 arm64. It runs in your browser with a WebAssembly build by dart2wasm 3.13.5. To run it yourself: dart run main.dart
What every language printed
any 2 of 3 replicas at 99%: 99.9702% Checkout path load balancer 99.9900% down 4.3 min a month app tier (2 of 3) 99.9925% down 3.2 min a month database pair 99.9953% down 2.0 min a month payment provider 99.9500% down 21.6 min a month whole path 99.9278% down 31.2 min a month Rarer failures or faster recovery every 30 days, 60 min to recover 99.8613% down 59.9 min a month every 60 days, 60 min to recover 99.9306% down 30.0 min a month every 30 days, 5 min to recover 99.9884% down 5.0 min a month
Runs on this device, in your browser. The first run downloads Python (about 13.5 MB), which is kept for the next runs.
Runs on this device, in your browser. The first run downloads Python (about 13.5 MB), which is kept for the next runs. Runs on this device, in your browser. The first run downloads JavaScript (about 0.6 MB), which is kept for the next runs. Runs on this device: a JavaScript build of this program (about 66 KB), made when the page was built. The first run also downloads the JavaScript runner (about 0.6 MB), which is kept for the next runs. To change the code, copy it and run it with the command below. Runs on this device: a WebAssembly build of this program (about 151 KB), made when the page was built. Edit runs your changes in the browser: the first edited run downloads the C and C++ compiler (about 29.1 MB), which is kept for the next runs. It is best on a computer. Runs on this device, in your browser. The first run downloads the C and C++ compiler (about 29.1 MB), which is kept for the next runs. It is best on a computer. Runs on this device: a .NET build of this program (about 3 KB), made when the page was built. The first run also downloads .NET (about 3.6 MB), which is kept for the next runs. Edit runs your changes in the browser: the first edited run downloads .NET (about 8.9 MB), which is kept for the next runs. Runs on this device, in your browser. The first run downloads .NET (about 8.9 MB), which is kept for the next runs. Runs on this device: a WebAssembly build of this program (about 8 KB), made when the page was built. Edit runs your changes in the browser: the first edited run downloads the C and C++ compiler (about 29.1 MB), which is kept for the next runs. It is best on a computer. Runs on this device, in your browser. The first run downloads the C and C++ compiler (about 29.1 MB), which is kept for the next runs. It is best on a computer. Runs on this device, in your browser. The first run downloads PHP (about 4.3 MB), which is kept for the next runs. Runs on this device: a WebAssembly build of this program (about 29 KB), made when the page was built. To change the code, copy it and run it with the command below. Runs on this device, in your browser. The first run downloads the JavaScript runner (about 0.9 MB), which is kept for the next runs. Runs on this device: a WebAssembly build of this program (about 720 KB), made when the page was built. Edit runs your changes in the browser: the first edited run downloads the Go compiler (about 18.7 MB), which is kept for the next runs. Runs on this device, in your browser. The first run downloads the Go compiler (about 18.7 MB), which is kept for the next runs. Runs on this device: a WebAssembly build of this program (about 1.7 MB), made when the page was built. To change the code, copy it and run it with the command below. Runs on this device, in your browser. The first run downloads Ruby (about 10.2 MB), which is kept for the next runs. Runs on this device: a WebAssembly build of this program (about 183 KB), made when the page was built. To change the code, copy it and run it with the command below. Runs on this device: a WebAssembly build of this program (about 11 KB), made when the page was built. To change the code, copy it and run it with the command below.Your run, in this browser
One checkout path: four parts in series, two of them redundant inside
Text description of the diagram
The diagram shows the parts a checkout request passes through, from top to bottom. The request needs every part, so the parts are in series.
- A load balancer, 99.99% available.
- An app tier of three instances, each 99.5% available. The peak needs any two of them, which makes the tier 99.9925% available.
- A database pair, a primary and a standby, each 99.9% available. Either one can serve, so the pair is down only when both are, plus about two minutes a month of failover gaps: 99.9953% in all.
- An outside payment provider, 99.95% available.
The whole path is about 99.928% available, and the payment provider alone accounts for about two thirds of its downtime. All the numbers are the assumptions and results of the checkout program above the diagram.
Two of three 99% instances give 99.9702%, against 99.9999% when any one would do. On the checkout path, the redundant app tier and database pair are down only 3.2 and 2.0 minutes a month, while the payment provider, a single outside dependency at 99.95%, accounts for 21.6 of the path’s 31.2 minutes. The path is 99.928% available, and more app instances would not change that: the next improvement has to come from the payment provider, for example a second provider to fail over to, or from not making the payment a hard dependency of every checkout.
AWS’s whitepaper makes the same point about spares from the other side: each spare costs as much as the original, and beyond about three spares for a part that is at least 99% available the extra availability is not worth it. It also warns about the unit of failure: ten instances in one Availability Zone are one failure if the zone goes, so the spare should be a second zone, or three zones of five instances each, which still leaves ten when one zone is lost.
Key idea
Redundancy multiplies the chances of failure, so two independent 99 % parts give 99.99 %; needing two of three, or waiting for a failover, gives less, and a single dependency left in series sets the ceiling.
Checkpoint
Check: Redundant parts in parallel
Faster recovery buys more nines
Availability can also be written in mean times: a part that runs for its mean time between failures (MTBF): The average time a part runs between one failure and the next. With the mean time to recover, it gives the part's availability: MTBF divided by MTBF plus MTTR. (MTBF) and then takes its mean time to recover (MTTR): The average time from a failure until the part works again, detection included. Cutting it from 60 minutes to 5 took a monthly failure from 99.8613 % to 99.9884 %. (MTTR) is available
The last block of the program compares two ways to improve a service that fails once every 30 days and needs an hour to recover (99.8613%). Halving how often it fails gives 99.9306%. Recovering in 5 minutes instead of 60 gives 99.9884%, more than either, and often at a lower cost: automatic detection, automatic failover and a fast rollback are usually easier to build than a system that fails half as often. AWS’s whitepaper names the same three levers: fewer failures, faster detection, which is part of recovery, and faster repair. In minutes of a 30-day month, from the same block:
| The same service | Availability | Down in a 30-day month |
|---|---|---|
| Fails every 30 days, recovers in 60 minutes | 99.8613 % | 59.9 minutes |
| Fails every 60 days, recovers in 60 minutes | 99.9306 % | 30.0 minutes |
| Fails every 30 days, recovers in 5 minutes | 99.9884 % | 5.0 minutes |
Halving the failures halves the downtime; cutting the recovery to a twelfth cuts it to a twelfth.
Checkpoint
Check: MTBF and MTTR
Correlated failures break the parallel formula
The parallel formula’s promise, 99.99% from two 99% parts, holds only if one part’s failure tells you nothing about the other’s. Replicas that share a power feed, a network switch, a configuration push, a deploy or a software bug fail together. This simulation gives two replicas the same individual availability twice, once with independent failures and once with a shared cause that takes both down about four times a year for about an hour:
"""Two replicas, each up 99% of the time: independent failures against a shared cause.
Each replica fails on its own about once a month and takes about 7.3 hours to repair, so it is down about 1% of
the time. In the second case the pair also shares a cause (one power feed, one configuration push, one region)
that takes both down at once about four times a year, for about an hour. Failures are simulated over 2,000 years
with a fixed seed; the numbers are assumptions for the sketch.
"""
import random
HOURS = 2_000 * 8_766 # 2,000 years of 365.25 days
rng = random.Random(3)
def outages(mtbf_h, mttr_h):
"""Random down intervals (start, end) in hours: up for about mtbf_h, then down for about mttr_h."""
t, spans = 0.0, []
while True:
t += rng.expovariate(1 / mtbf_h)
if t >= HOURS:
return spans
down = rng.expovariate(1 / mttr_h)
spans.append((t, min(t + down, HOURS)))
t += down
def merged(spans):
"""The same down time as non-overlapping intervals, in order."""
out = []
for start, end in sorted(spans):
if out and start <= out[-1][1]:
out[-1] = (out[-1][0], max(out[-1][1], end))
else:
out.append((start, end))
return out
def both_down(a, b):
"""Hours during which both replicas are down."""
a, b, total, i, j = merged(a), merged(b), 0.0, 0, 0
while i < len(a) and j < len(b):
total += max(0.0, min(a[i][1], b[j][1]) - max(a[i][0], b[j][0]))
if a[i][1] < b[j][1]:
i += 1
else:
j += 1
return total
replica_a, replica_b = outages(720, 7.27), outages(720, 7.27)
shared = outages(8_766 / 4, 1) # about four times a year, about an hour each
alone = sum(end - start for start, end in merged(replica_a)) / HOURS
print(f"one replica on its own: {100 * (1 - alone):.3f}% available")
for name, extra in [("two replicas, independent", []), ("two replicas, shared cause", shared)]:
down = both_down(replica_a + extra, replica_b + extra) / HOURS
print(f"{name + ':':33}{100 * (1 - down):.3f}% available, down {down * 8_766:.1f} h a year")
print(f"formula for independent replicas: {100 * (1 - alone**2):.3f}%") Output
one replica on its own: 98.992% available two replicas, independent: 99.989% available, down 0.9 h a year two replicas, shared cause: 99.944% available, down 4.9 h a year formula for independent replicas: 99.990%
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 correlated.py
Runs on this device, in your browser. The first run downloads Python (about 13.5 MB), which is kept for the next runs.
Your run, in this browser
Each replica on its own is about 99% available, and independently the pair reaches 99.989%, about 0.9 hours of downtime a year, close to the formula’s 99.990%. Four hour-long shared events a year cost the pair five times as much downtime, 4.9 hours, and the shared cause now dominates: once failures are correlated, adding replicas that share the cause adds almost nothing. Step through the four kinds of failure the simulation draws:
The drawing shows the whole scene; its 5 steps are listed below.
Every step as text
- Replica A fails alone. Replica A's disk fails. Replica B answers every request, so users see nothing. Each replica is down about 1 % of the time.
- Replica B fails alone. Later B fails on its own and A carries the load. Independent failures overlap only by chance, about 1 % of 1 % of the time.
- Both by chance. Rarely, both are down at once by bad luck. Over the simulated years the pair was down 0.9 hours a year this way, close to the formula's 99.99 %.
- The shared feed fails. The power feed both replicas use fails, and both go down at the same moment. Redundancy did nothing, because the two shared the cause.
- What it costs. Four such hour-long events a year raise the pair's downtime from 0.9 to 4.9 hours a year. Separate what the replicas share before adding a third.
Measurements of real fleets agree. A year-long study of Google’s storage clusters by Ford and colleagues found that a large share of node failures came in bursts, that most large bursts were tied to a rack or a group of racks, and that modelling the same failures as independent typically overestimated how long data stays available by two orders of magnitude or more. Correlation also shrank the gain from adding replicas.
Amazon’s Builders’ Library describes correlated failure: Several parts failing at once from one cause they share, such as a power feed, a configuration push, a deploy or a software bug. It breaks the parallel formula, which assumes independent failures. as several components failing from the same underlying cause, and lists causes beyond the obvious ones: data-centre power, networking and cooling; shared dependencies such as DNS; deployments and tools that act on many servers at once; every server running the same software with the same limits; and many clients changing their behaviour at the same moment. Its remedies are the design moves that the rest of this track uses:
- Independent zones. Run separate copies of the service in each zone, sharing as little as possible with other zones, so a facility problem stays in one zone.
- Staggered changes. Deploy and change configuration in one zone, or one cell, at a time, so a bad change fails small.
- Cells and shuffle sharding: Giving each customer its own small, random set of workers from a shared fleet, so that two customers rarely share all of their workers and one customer's bad requests reach few others. More in “Cells, deployment stamps and blast radius”. Split the fleet into independent cells, and give customers different combinations of servers, so that no single failure or bad workload reaches everyone.
- Jitter. Add a little randomness to timers, retry delays, cache expiry and limits, so that servers do not all hit the same edge at the same moment.
Key idea
The parallel formula holds only for independent failures; replicas that share a cause fail together, so separate what they share before you add another one.
Checkpoint
Check: Correlated failures
Practise: availability from parts
Write four helpers in Python: the downtime a target allows, and the availability of parts in series, in parallel and from MTBF and MTTR. Their sample tests run here:
Exercise · Easy · Python
Downtime budgets and composite availability
Write four helpers in availability.py. Availabilities go in and come out as percentages, so 99.9 means 99.9%.
downtime_minutes(target_pct, days) returns the minutes of downtime that a target allows over days days. For example, downtime_minutes(99.9, 30) is 43.2.
series(*parts_pct) returns the availability of parts that are all needed for a request to succeed, such as a load balancer, an app tier and a database called one after the other. For example, series(99.9, 99.9) is 99.8001.
parallel(*parts_pct) returns the availability of redundant parts of which any one is enough, assuming they fail independently. For example, parallel(99, 99) is 99.99.
from_mtbf(mtbf_hours, mttr_hours) returns the availability of a part that runs for mtbf_hours on average between failures and takes mttr_hours on average to recover. For example, from_mtbf(720, 1) is about 99.8613.
Starter code · availability.py
def downtime_minutes(target_pct, days):
"""Minutes of downtime that target_pct allows over `days` days."""
# Replace this line with your code.
return 0
def series(*parts_pct):
"""Availability, in percent, of parts that are all needed."""
# Replace this line with your code.
return 0
def parallel(*parts_pct):
"""Availability, in percent, of independent redundant parts of which any one is enough."""
# Replace this line with your code.
return 0
def from_mtbf(mtbf_hours, mttr_hours):
"""Availability, in percent, from the mean time between failures and the mean time to recover."""
# Replace this line with your code.
return 0 The sample tests · test_availability.py
import math
from availability import downtime_minutes, from_mtbf, parallel, series
def close(a, b):
return math.isclose(a, b, abs_tol=1e-6)
def test_downtime_minutes():
"""turns a target into minutes of downtime over a period"""
assert close(downtime_minutes(99.9, 30), 43.2)
assert close(downtime_minutes(99.95, 30), 21.6)
assert close(downtime_minutes(99.99, 365.25), 52.596)
assert close(downtime_minutes(100, 30), 0)
def test_series():
"""multiplies the availabilities of parts that are all needed"""
assert close(series(99.9, 99.9), 99.8001)
assert close(series(99.99, 99.95, 99.9), 99.840064995)
assert close(series(99.5), 99.5)
def test_parallel():
"""is down only when every redundant part is down"""
assert close(parallel(99, 99), 99.99)
assert close(parallel(99.5, 99.5), 99.9975)
assert close(parallel(90, 90, 90), 99.9)
assert close(parallel(80), 80)
def test_from_mtbf():
"""is the share of time up between failures"""
assert close(from_mtbf(720, 1), 100 * 720 / 721)
assert close(from_mtbf(720, 5 / 60), 100 * 720 / (720 + 5 / 60))
assert close(from_mtbf(99, 1), 99) A hint
Turn each percentage into a fraction first (p / 100) and back at the end. In series, multiply the fractions. In parallel, multiply the chances that each part is down (1 - fraction) and subtract the product from 1. For the mean times, the part is up for MTBF out of every MTBF + MTTR hours.
Results of the sample tests
| Test | Result | Details |
|---|
What your code printed
The sample tests run on this device, in your browser (Pyodide): nothing is sent to mysmartcopilot.com. The first run downloads Python (about 13.5 MB), which is kept for the next runs. A check in your browser is feedback for you, not proof that the code is right for every input.
Then practise on new paths and replicas, one question at a time, starting from the formula you have missed most:
Practice that adapts to you
Practise this lesson
11 questions about 5 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.
Design practice: targets you can defend
Availability targets are where a design round checks your arithmetic and your scepticism. Commit to a first answer for each brief, then check it with the checkout path and the shared-cause simulation:
Checkpoint
Your first decision
Model answers open with any pass: ₹79 for 1 week ($2.99), one payment that never renews.
-
Mid to senior
Product wants the checkout service at 99.99% availability, but the database it depends on is rated 99.95%. Is the target reachable? Explain with numbers, and say what you would change.
-
Mid to staff
A teammate says that three replicas, each 99% available, give the service 99.9999% availability. What do you ask before you accept that number, and what would you estimate instead?
Interview questions
Warm-up (fresher to mid level): two services, each 99.9% available, must both work for a request to succeed. What availability can the pair offer, and why? About 99.8%. The request needs both, so it succeeds only when both are up at once: 0.999 × 0.999 = 0.998001, assuming they fail independently. A quick way to see it is that the unavailabilities roughly add up: 0.1% + 0.1% = 0.2% of failures, about 86 minutes a month instead of 43. That is why every hard dependency lowers the ceiling of a design, and why designs remove dependencies from the critical path, add redundancy inside them, or make them soft dependencies that the service can work without for a while.
Key takeaways
- Turn targets into downtime over a stated period: 99.9% is 43.2 minutes per 30-day month and 8.77 hours per year; each nine divides it by ten.
- In series, availabilities multiply and unavailabilities roughly add: every hard dependency lowers the ceiling.
- In parallel, the group fails only when every part has failed: two independent 99% replicas give 99.99%, but “any 2 of 3” and failover time give less.
- A = MTBF ÷ (MTBF + MTTR): faster detection and recovery often buy more nines than rarer failures.
- Shared causes (power, deploys, configuration, software, zones) make replicas fail together; separate what they share before adding more of them.
Terms in this lesson
- correlated failure
- Several parts failing at once from one cause they share, such as a power feed, a configuration push, a deploy or a software bug. It breaks the parallel formula, which assumes independent failures.
- hard dependency
- A part that every request needs, so the service fails whenever it does. Hard dependencies are in series, and each one lowers the availability the whole service can reach.
- mean time between failures (MTBF)
- The average time a part runs between one failure and the next. With the mean time to recover, it gives the part's availability: MTBF divided by MTBF plus MTTR.
- mean time to recover (MTTR)
- The average time from a failure until the part works again, detection included. Cutting it from 60 minutes to 5 took a monthly failure from 99.8613 % to 99.9884 %.
References
- Availability and Beyond: Understanding and Improving the Resilience of Distributed Systems on AWS (Amazon Web Services)
- Availability and Beyond: Understanding availability (MTBF and MTTR) (Amazon Web Services)
- Availability and Beyond: Availability with dependencies (Amazon Web Services)
- Availability and Beyond: Availability with redundancy (Amazon Web Services)
- Minimizing correlated failures in distributed systems (Amazon Builders' Library) (Amazon Web Services)
- Site Reliability Engineering, chapter 3: Embracing Risk (Google (O'Reilly Media))
- Availability in Globally Distributed Storage Systems (Ford et al.) (USENIX OSDI 2010)
Related tools
Report a problem with this lesson
Kept only in this browser. Your Learn progress