Availability and SLAs
Availability is the fraction of time a system works correctly for its users. It is usually written as a percentage with a number of nines: 99.9% is "three nines", 99.99% is "four nines".
availability = uptime / (uptime + downtime)
= MTBF / (MTBF + MTTR)
MTBF mean time between failures
MTTR mean time to repair (detect + fix + recover)The second form shows the two levers you have: fail less often (higher MTBF) or recover faster (lower MTTR). In practice, recovering faster with automation, health checks and failover is usually the cheaper lever.
SLI, SLO, SLA
| Term | Meaning | Example |
|---|---|---|
| SLI (indicator) | A measured number | Fraction of HTTP requests that returned 2xx in under 300 ms |
| SLO (objective) | The internal target for an SLI | 99.9% over 30 days |
| SLA (agreement) | A contract with customers, with penalties | 99.5% or the customer gets a 10% credit |
The SLA is looser than the SLO so that the team gets warned before money is at stake. The allowed failure (100% - SLO) is the error budget: while you are within it you can ship risky changes; when it's used up, reliability work comes first.
The nines calculator
PERIODS = {"per year": 365 * 24 * 3600, "per month": 30 * 24 * 3600, "per week": 7 * 24 * 3600}
def fmt(seconds):
if seconds >= 86_400:
return f"{seconds / 86_400:.1f} d"
if seconds >= 3_600:
return f"{seconds / 3_600:.1f} h"
if seconds >= 60:
return f"{seconds / 60:.1f} min"
return f"{seconds:.0f} s"
print(f"{'availability':<13}" + "".join(f"{p:>12}" for p in PERIODS))
for a in [99.0, 99.5, 99.9, 99.95, 99.99, 99.999]:
row = "".join(f"{fmt(total * (1 - a / 100)):>12}" for total in PERIODS.values())
print(f"{a:<13}{row}")availability per year per month per week
99.0 3.7 d 7.2 h 1.7 h
99.5 1.8 d 3.6 h 50.4 min
99.9 8.8 h 43.2 min 10.1 min
99.95 4.4 h 21.6 min 5.0 min
99.99 52.6 min 4.3 min 1.0 min
99.999 5.3 min 26 s 6 s
Five nines leaves about 26 seconds per month: no human can even open a laptop in that time, so such systems need fully automatic failover.
Components in series
When a request needs every component to work (load balancer and app and database), availabilities multiply, and the total is always lower than the weakest part:
from math import prod
chain = {"DNS": 0.9999, "load balancer": 0.9995, "app tier": 0.999, "database": 0.999, "payment API": 0.998}
total = prod(chain.values())
print(f"serial availability: {total:.4%}")
print(f"downtime per year: {(1 - total) * 365 * 24:.1f} hours")serial availability: 99.5407%
downtime per year: 40.2 hours
Five components that each look good add up to about 40 hours of downtime a year. Every dependency you add to the critical path costs availability.
Components in parallel (redundancy)
When any one of several replicas can serve a request, the system fails only if all of them fail at once. Assuming independent failures, A = 1 - (1 - a)^n:
def parallel(a, n):
return 1 - (1 - a) ** n
for n in [1, 2, 3]:
print(f"{n} replica(s) of a 99% component: {parallel(0.99, n):.6%}")
# Redundant tiers in series: 2 LBs, 3 app servers, primary + replica database
system = parallel(0.9995, 2) * parallel(0.99, 3) * parallel(0.999, 2)
print(f"redundant system: {system:.5%}")1 replica(s) of a 99% component: 99.000000%
2 replica(s) of a 99% component: 99.990000%
3 replica(s) of a 99% component: 99.999900%
redundant system: 99.99978%
Two cheap 99% servers beat one expensive 99.9% server. That's why redundancy, not perfect hardware, is the foundation of availability.
Note: The independence assumption is the weak point. Replicas in the same rack share a power supply; replicas running the same buggy release fail together. Spread replicas across availability zones, and roll out changes gradually.
Measuring with a simulation
Formulas assume steady averages. A simulation over a year of hours, with a seeded random generator, lets you see failures and repairs play out:
import random
def simulate_year(replicas, fail_prob_per_hour=0.005, repair_hours=8, seed=42):
rng = random.Random(seed)
down_until = [0] * replicas
outage_hours = 0
for hour in range(365 * 24):
for r in range(replicas):
if down_until[r] <= hour and rng.random() < fail_prob_per_hour:
down_until[r] = hour + repair_hours
if all(d > hour for d in down_until):
outage_hours += 1
return outage_hours
for n in [1, 2, 3]:
hours = simulate_year(n)
print(f"{n} replica(s): {hours:3} outage hours, availability {1 - hours / 8760:.4%}")1 replica(s): 280 outage hours, availability 96.8037%
2 replica(s): 10 outage hours, availability 99.8858%
3 replica(s): 0 outage hours, availability 100.0000%
A single replica is down about 280 hours in this simulated year. A second replica cuts that to 10 hours (only the hours when both happened to be broken at once), and with three the system never went down. Real systems don't reach 100%: correlated failures and bad deploys, which this model ignores, dominate once hardware redundancy is in place.
Ways to improve availability
- Redundancy at every tier, across zones (and regions for the highest targets).
- Health checks and automatic failover to cut MTTR.
- Graceful degradation: if recommendations are down, show the page without them.
- Timeouts, retries with backoff and circuit breakers so one slow dependency doesn't take down its callers.
- Careful deploys: canary releases and fast rollback; most outages are caused by changes.
Test yourself
Roughly how much downtime per month does a 99.9% SLO allow?
- About 4 minutes
- About 43 minutes
- About 7 hours
- About 3 days
Three components with 99.9% availability each are all required for a request. What is the system's availability?
- 99.9%
- About 99.7%
- 99.999%
- About 97%
Why might two replicas in the same rack fail together?
- Replication is always synchronous
- They share failure causes such as power or network
- Load balancers send them the same traffic
- Their clocks are synchronised