Sub topic 9
Availability and reliability targets
This chapter assumes you can read short Python snippets and know what a replica, a load balancer, and a health check are. It also assumes you have met SLIs and SLOs in the previous chapter. Here you turn "the service should almost never be down" into a number, a measurement window, and a design consequence.
Availability and reliability are different promises
Availability is the fraction of time, or of requests, in which the system works when someone uses it. Reliability is the probability that the system performs its function correctly over a period without failing. The two overlap, but they answer different questions.
- Availability asks: "Can I use it right now?"
- Reliability asks: "Will it keep working correctly while I use it?"
A service that is up but returns wrong data is available and unreliable. A service that crashes for one second every hour is reliable enough for batch jobs and poor for live video calls. Write requirements for both when both matter.
Writing an availability requirement
A usable availability requirement has four parts:
- A target, such as 99.9%.
- A measurement window, such as a rolling 30 days.
- A definition of "success", such as an HTTP status below 500 returned within a timeout.
- A measurement point, such as the service edge or the load balancer logs.
"The service must be highly available" has none of these and cannot be tested. NFR-2 from the URL shortener ("Redirects succeed for 99.9% of requests over a 30-day window") has all four once you add where it is measured.
Time-based and request-based measurement
Time-based availability counts minutes in which the service was up. Request-based availability divides successful requests by total requests. Request-based is usually better. A five-minute outage at 3 a.m. and a five-minute outage at peak are equal in minutes, but the peak outage fails far more users. It also handles partial failures, where 20% of requests fail and the service is neither fully up nor fully down.
Turning a target into a downtime budget
The budget is the share of the window you are allowed to fail. For a 30-day window:
def downtime_budget_minutes(availability, days=30):
"""Minutes of allowed downtime for an availability target over a window."""
return (1 - availability) * days * 24 * 60
for target in (0.99, 0.999, 0.9995, 0.9999, 0.99999):
print(target, round(downtime_budget_minutes(target), 1))
# 0.99 432.0
# 0.999 43.2
# 0.9995 21.6
# 0.9999 4.3
# 0.99999 0.4| Target | Allowed downtime per 30 days | What it implies |
|---|---|---|
| 99% | about 7.2 hours | Manual recovery is acceptable |
| 99.9% | about 43 minutes | Automated failover is needed for most incidents |
| 99.99% | about 4.3 minutes | A human cannot respond in time. Recovery must be automatic |
| 99.999% | about 26 seconds | Multi-region design and very careful deployments |
Each extra nine cuts the budget by a factor of ten and usually raises cost by more than that. Ask what an hour of downtime costs the business before agreeing to a number.
The same idea works per request. At 100 million requests in 30 days, a 99.9% target allows 100,000 failed requests. Teams call this the error budget. When it is spent, they slow feature releases and fix stability.
Estimating availability from components
Your system is only as available as the parts it depends on. Two rules cover most cases, and both assume failures are independent.
- Serial dependencies: if a request needs A and B, multiply their availabilities. The result is lower than either part.
- Redundant dependencies: if a request needs A or B, multiply their failure probabilities. The result is higher than either part.
def serial(*parts):
result = 1.0
for p in parts:
result *= p
return result
def parallel(*parts):
all_fail = 1.0
for p in parts:
all_fail *= (1 - p)
return 1 - all_fail
print(round(serial(0.999, 0.999, 0.999), 6)) # 0.997003
print(round(parallel(0.99, 0.99), 6)) # 0.9999
app_tier = parallel(0.99, 0.99)
print(round(serial(0.9999, app_tier, 0.999), 4)) # 0.9988Three services at 99.9% each give only about 99.7% end to end. Two 99% replicas give 99.99%. In the last line, the single database at 99.9% pulls the whole chain under 99.9%, however well the app tier is replicated.
Reliability inputs: MTBF and MTTR
Two numbers describe how a component fails and recovers.
- MTBF (mean time between failures) is the average operating time between failures.
- MTTR (mean time to repair) is the average time from failure to recovery.
Steady-state availability is MTBF / (MTBF + MTTR).
def availability_from_mtbf(mtbf_hours, mttr_hours):
return mtbf_hours / (mtbf_hours + mttr_hours)
print(round(availability_from_mtbf(500, 0.5), 4)) # 0.999
print(round(availability_from_mtbf(500, 0.05), 4)) # 0.9999The second line shows the practical lesson. Cutting repair time from 30 minutes to 3 minutes gives the same improvement as making failures ten times rarer. Failures are hard to prevent, so most availability work goes into detecting and recovering quickly: health checks, automatic failover, fast rollbacks, and tested runbooks.
Requirements that go with an availability target
An availability number rarely stands alone. Pair it with the following when they apply:
- Recovery time objective (RTO): the longest acceptable time to restore service after a failure.
- Recovery point objective (RPO): the largest acceptable window of lost data, measured in time. An RPO of zero means no acknowledged write may be lost.
- Failure scope: which failures must be survived, for example a single instance, a zone, or a region.
- Degraded mode: what may be switched off under stress. A shortener might keep redirects working while link creation is disabled.
- Planned maintenance: whether maintenance counts against the budget. Decide this explicitly. A target that excludes maintenance windows is weaker than one that includes them.
Common errors
- Quoting a target with no window or definition of success, so nobody can tell whether it was met.
- Promising an SLA to customers equal to the internal SLO. Keep the internal target stricter so you have room to react before a contractual breach.
- Counting only total outages and ignoring slow responses. A response that arrives after the client times out is a failure for that user.
- Adding replicas to a tier while a single database, DNS provider, or deployment tool remains the weakest link.
- Treating health checks as proof of availability. A shallow check can pass while real requests fail.
- Choosing five nines because it sounds good, without costing the extra nines.
Exercise
A service must meet 99.95% availability over 30 days. How many minutes of downtime does that allow? Two independent replicas, each 99.5% available, serve the requests in parallel behind a load balancer that is assumed never to fail. Does the replica pair alone meet the target?
Show answer
The budget is (1 - 0.9995) 30 24 60 = 21.6 minutes. The replica pair has availability 1 - (0.005 0.005) = 0.999975, or 99.9975%, which is above 99.95%, so on paper it meets the target. In practice the load balancer, shared dependencies such as the database, and correlated failures reduce the real figure, so you would multiply in those components and check again.