Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Worked example · 25 min · revision 1

Availability math: nines, dependencies and redundancy

Work out whether an availability target is reachable: turn it into a downtime budget for a stated window, chain dependencies in series, add redundancy with its assumptions spelled out, correct for shared causes, and split the error budget between dependencies and your own releases, with every number printed by a script.

Contentsand lesson path

What you will learn

  • Compute composite availability for serial and redundant dependencies and turn an SLO into error budgets per dependency.

01. The problem

Suppose an online school runs an exam-submission service. For exam weeks the product team asks for a service level objective (SLO), a target for a measured service level indicator (SLI): 99.95% of submissions succeed, over a rolling 30 days. Can this design reach it, and if not, what must change?

Every submission passes through five other systems. The figures below are assumptions for this exercise, each with its real-life source. An SLA, or service level agreement, is a provider's contractual promise:

The submission path and its dependencies (assumed figures, 30-day window)
dependency            availability   where the figure comes from
load balancer         99.99%         provider SLA
identity provider     99.95%         provider SLA (checks every login token)
database, one node    99.9%          our own last six months
object storage        99.99%         provider SLA (holds uploaded answers)
plagiarism API        99.5%          vendor contract (called before saving)

Constraints: the team cannot change the identity provider or the plagiarism vendor, the budget allows one extra database node, and releases happen twice a month. This builds on Non-functional targets you can test, which introduced the nines. The scripts need only the Python 3.12 standard library.

02. Step 1: Turn the target into a budget for a stated window

A percentage is hard to design against; minutes and failed requests are not. The error budget is the share of the window allowed to be bad: 1 minus the target. Its size depends on the window, so say which one: a calendar month has 28 to 31 days, a rolling window a fixed length, a year usually 365 days.

Python 3.12 · nines.py
"""Downtime budgets: how much full outage an availability target allows."""
TARGETS = [99.0, 99.5, 99.9, 99.95, 99.99, 99.999]
WINDOWS = {  # window name -> length in minutes
    "28 days": 28 * 24 * 60,
    "30 days": 30 * 24 * 60,
    "31 days": 31 * 24 * 60,
    "365 days": 365 * 24 * 60,
}

print("Minutes of full outage allowed per window")
print(f"{'target':>8}" + "".join(f"{name:>11}" for name in WINDOWS))
for target in TARGETS:
    bad_share = 1 - target / 100  # the error budget, as a share of the window
    cells = "".join(f"{bad_share * minutes:>11.2f}" for minutes in WINDOWS.values())
    print(f"{target:>7}%{cells}")

# A request-based SLI counts bad requests instead of bad minutes.
rate = 400  # requests per second, averaged over the window
requests = rate * WINDOWS["30 days"] * 60
print(f"\n30 days at {rate} req/s = {requests:,} requests")
for target in (99.9, 99.95):
    print(f"{target}% allows {requests * (1 - target / 100):,.0f} failed requests")
Expected output (python3 nines.py)
Minutes of full outage allowed per window
  target    28 days    30 days    31 days   365 days
   99.0%     403.20     432.00     446.40    5256.00
   99.5%     201.60     216.00     223.20    2628.00
   99.9%      40.32      43.20      44.64     525.60
  99.95%      20.16      21.60      22.32     262.80
  99.99%       4.03       4.32       4.46      52.56
 99.999%       0.40       0.43       0.45       5.26

30 days at 400 req/s = 1,036,800,000 requests
99.9% allows 1,036,800 failed requests
99.95% allows 518,400 failed requests

Our target allows 21.6 minutes of full outage. Two details change how you spend it:

  • The table assumes full outages. Our SLI counts submissions, so ten minutes in which 20% fail costs about two minutes. A time-based SLI (good minutes over all minutes) needs a rule for when a minute counts as bad.
  • The window decides what one incident does: 99.99% over 28 days allows about 4 minutes, however generous 52.56 minutes a year sounds.

Write down exclusions too, such as requests rejected for bad input.

03. Step 2: Chain the dependencies in series

A critical dependency is one whose failure makes the request fail. If a request needs every part, the parts are in series, and the chance that all of them work is the product: A = A1 × A2 × … × An.

The product assumes independence: one part failing does not make another likelier to fail. When unavailabilities are small they roughly add, a quick check: 0.01% + 0.05% + 0.1% + 0.01% + 0.5% is about 0.67%.

The script prints building blocks, then four versions of the design and three variants.

Python 3.12 · composite.py
"""Composite availability: serial chains, redundancy and shared causes."""
from math import comb, prod


def serial(*parts):  # every part must work; failures independent
    return prod(parts)


def parallel(*parts):  # one working part is enough; independent; instant failover
    return 1 - prod(1 - a for a in parts)


def k_of_n(k, n, a):  # at least k of n identical, independent parts must work
    return sum(comb(n, i) * a**i * (1 - a) ** (n - i) for i in range(k, n + 1))


def pair_with_shared_cause(shared, own):
    """Two replicas. Each one is `shared` (zone, deploy, config) in series with its
    `own` hardware and process. The shared part is counted once, in series."""
    return shared * parallel(own, own)


def show(label, a, window_min=30 * 24 * 60):
    print(f"{label:<44}{a * 100:>9.4f}%{(1 - a) * window_min:>9.1f} min/30d")


print("Building blocks")
show("serial: three parts at 99.9%", serial(0.999, 0.999, 0.999))
show("parallel: two replicas at 99.5%", parallel(0.995, 0.995))
show("2 of 3 needed, each at 99.5%", k_of_n(2, 3, 0.995))
show("pair at 99.9%, 1/5 of downtime shared", pair_with_shared_cause(
    0.9998, 0.999 / 0.9998))

print("\nSuppose: exam-submission path, availability per 30 days")
lb, idp, db, storage, plagiarism = 0.9999, 0.9995, 0.999, 0.9999, 0.995
# Assumed: 10% of submissions must refresh a token at the IdP first. Valid only
# while IdP outages are shorter than the token lifetime (see the lesson).
idp_refresh = 1 - 0.10 * (1 - idp)
db_pair = pair_with_shared_cause(0.9999, 0.999 / 0.9999)
queue = 0.9999  # the durable queue the plagiarism check now goes through
show("v1 all five in series", serial(lb, idp, db, storage, plagiarism))
show("v2 check moved behind a 99.99% queue", serial(lb, idp, db, storage, queue))
v3 = serial(lb, idp_refresh, db, storage, queue)
show("v3 tokens checked locally, 10% refresh", v3)
path = (lb, idp_refresh, db_pair, storage)
show("v4 database pair in two zones", serial(*path, queue))
show("v4 with the queue at 99.9%", serial(*path, 0.999))
show("v4 with an outbox table, no queue call", serial(*path))
show("(outbox, if the pair were independent)", serial(lb, idp_refresh, parallel(db, db),
                                                      storage))
Expected output (python3 composite.py)
Building blocks
serial: three parts at 99.9%                  99.7003%    129.5 min/30d
parallel: two replicas at 99.5%               99.9975%      1.1 min/30d
2 of 3 needed, each at 99.5%                  99.9925%      3.2 min/30d
pair at 99.9%, 1/5 of downtime shared         99.9799%      8.7 min/30d

Suppose: exam-submission path, availability per 30 days
v1 all five in series                         99.3309%    289.0 min/30d
v2 check moved behind a 99.99% queue          99.8201%     77.7 min/30d
v3 tokens checked locally, 10% refresh        99.8650%     58.3 min/30d
v4 database pair in two zones                 99.9549%     19.5 min/30d
v4 with the queue at 99.9%                    99.8650%     58.3 min/30d
v4 with an outbox table, no queue call        99.9649%     15.2 min/30d
(outbox, if the pair were independent)        99.9749%     10.8 min/30d

Version 1 reaches only 99.33%: about 289 minutes against 21.6. The plagiarism API alone spends 216 minutes, ten times the budget, and the identity provider at 99.95% would use the whole budget by itself. A service cannot be more available than its critical dependencies together allow, so no care in our own code fixes this.

04. Step 3: Take the weakest links off the critical path

The cheapest dependency to make reliable is one you no longer need on every request. We cannot change the vendors, but we can change when we need them. Each change must be modelled, not assumed away.

  • Plagiarism check (v2). Answers must be saved at submission time, not checked. Save, put a message on a durable queue, and check later with retries. The vendor leaves the path, but the queue joins it in series, at an assumed 99.99%.
  • Identity provider (v3). Login tokens are signed, so the service verifies them with the provider's cached public keys. The provider stays on the path for token refreshes: if 10% of submissions arrive with an expired token, only those fail during a provider outage, and the path pays 10% of its unavailability. That holds only for outages shorter than the token lifetime, since a longer one expires every token. Short lifetimes limit revoked tokens but raise the refresh share. New sign-ins fail too; this SLI does not count them, so give them their own.

After both changes the path is 99.87%, about 58 minutes. What remains is the single database node.

05. Step 4: Add redundancy, and model what the replicas share

With a second database node, the path works if either node works, so the two are in parallel: A = 1 − (1 − A1) × (1 − A2). Two nodes at 99.9% give 1 − 0.001² = 99.9999% on paper, under three assumptions:

  1. Independence: the nodes do not fail for the same reason at the same time.
  2. Instant, correct failover. Real failover takes seconds to minutes (next lesson).
  3. Each copy can carry the full load. If two of three nodes are needed at peak, use k-of-n: three nodes at 99.5% with two required give 99.9925%, less than two nodes with one required.

Independence fails most quietly. Replicas in one zone share its power and network; all replicas share the deploy pipeline, configuration and software version. Model the shared part in series: pair = shared × parallel(own, own). With a fifth of each node's downtime shared, the pair drops from 99.9999% to 99.98%. Google's SRE paper The Calculus of Service Availability agrees: three copies at 99.9% give nine nines only with zero correlation, and real correlation is never zero.

Our v4 puts the second node in another zone with a small shared part (99.99%, for the region and replication link): 99.955%, 19.5 minutes. That is inside the budget only if the queue delivers 99.99%, at most 10% of submissions refresh a token, and provider outages stay shorter than the token lifetime. With a 99.9% queue the path falls back to 99.87%: the queue takes back everything the second node bought. So the team drops the queue call and writes the check request to an outbox table in the same database transaction as the submission; a worker forwards it later. The database is already on the path, so nothing joins it: 99.965%, about 15 minutes, where trusting independence would claim 10.8.

06. Step 5: Split the error budget and check your own share

The kept design (v4 with an outbox) has four critical dependencies, the identity provider counted at its refresh share. What do they spend, and what is left for failures we cause, such as bad deploys?

Python 3.12 · budget.py
"""Split an SLO's error budget across dependencies and your own failures."""
WINDOW_MIN = 30 * 24 * 60
SLO = 0.9995
budget = (1 - SLO) * WINDOW_MIN
deps = {  # design v4 with an outbox; the IdP counts only for the 10% that refresh
    "load balancer": 0.9999,
    "IdP, 10% refresh": 1 - 0.10 * (1 - 0.9995),
    "database pair": 0.9999,
    "object storage": 0.9999,
}


def left_for_us(deps):
    return budget - sum((1 - a) * WINDOW_MIN for a in deps.values())


print(f"SLO {SLO:.2%} over 30 days -> error budget {budget:.2f} min")
for name, a in deps.items():
    print(f"  {name:<17} {a:.3%} spends {(1 - a) * WINDOW_MIN:5.2f} min")
own = left_for_us(deps)
print(f"  left for our own code and deploys: {own:.2f} min")

# What each dependency would need if we kept half the budget for ourselves.
need = 1 - (1 - SLO) / 2 / len(deps)
print(f"\nHalf the budget for us -> each dependency needs {need:.4%}")
one_zone = {**deps, "database pair": 0.9998 * (1 - (1 - 0.999 / 0.9998) ** 2)}
print(f"If the pair shared one zone: {left_for_us(one_zone):.2f} min left for us")

# Our own failures: incidents per window x minutes each x share of traffic hit.
plans = {
    "bad deploy hits all traffic": (2, 6.0, 1.00),
    "canary to 10% catches it first": (2, 6.0, 0.10),
}
for name, (incidents, minutes, share) in plans.items():
    used = incidents * minutes * share
    verdict = "fits" if used <= own else "does NOT fit"
    print(f"{name:<32} {used:5.2f} min of {own:.2f} -> {verdict}")
Expected output (python3 budget.py)
SLO 99.95% over 30 days -> error budget 21.60 min
  load balancer     99.990% spends  4.32 min
  IdP, 10% refresh  99.995% spends  2.16 min
  database pair     99.990% spends  4.32 min
  object storage    99.990% spends  4.32 min
  left for our own code and deploys: 6.48 min

Half the budget for us -> each dependency needs 99.9938%
If the pair shared one zone: 2.13 min left for us
bad deploy hits all traffic      12.00 min of 6.48 -> does NOT fit
canary to 10% catches it first    1.20 min of 6.48 -> fits

The dependencies spend 15.12 minutes, leaving 6.48 minutes for us. To keep half the budget ourselves, each dependency would need 99.9938%. This is the rule of the extra 9 from the same paper: critical dependencies should offer about one more nine than the service, because there are several of them and the service has its own problems. When one cannot, mitigate around it, as Step 3 did, or lower the target.

The last lines test our share with another rule from the paper: availability is limited by how often incidents happen × how long each lasts. Two bad deploys a month, six minutes each to detect and roll back, spend 12 minutes and do not fit. Reducing the scope does: a canary that sends a new version to 10% of traffic first cuts that to 1.2 minutes. The paper's three levers: fewer incidents, smaller scope, faster recovery.

What if the pair had shared one zone, a fifth of its downtime shared? Only 2.13 minutes would be left for us.

07. Step 6: Compare the estimate with what you observe

Everything so far is an estimate built from assumed figures. The SLO is judged on observed attainment, the measured share of good submissions, ideally measured where users are (see SLOs, black-box probes and alerts). Compare the two every month. Attainment well below the estimate means the model misses something: an unlisted shared cause, slower failover than assumed, or a dependency below its SLA.

08. Check your understanding

Practice check · 3 questions

Budgets, shared causes and incident math

Work each one out before you choose.

Q1. Two database replicas are each 99.9% available. Both run in one zone, and about half of each replica's downtime comes from that zone's shared power and network. A spreadsheet treats the replicas as independent and shows 99.9999%. What is a better estimate for the pair?
Q2. A team measures its 99.99% SLO as the share of good minutes over a rolling 28 days. It plans one 40-minute full outage for a migration and argues this is fine, because 99.99% allows about 52 minutes a year. What happens to the SLO?
Q3. A service targets 99.95% over a rolling 30 days. In a typical month it has two incidents, each taking about 7 minutes to detect and 5 to mitigate, and each failing all requests. Its two critical dependencies both run at 99.999%. What do you conclude?
Practice only: not graded, not saved, not evidence.

09. Apply it

Start the skill project: a checkout journey with five dependencies (say a load balancer, an identity provider, a cart database, a payment provider and an inventory service) and a target of 99.95% over 30 days.

  1. List each dependency with an availability figure and its source.
  2. Adapt composite.py: is 99.95% reachable?
  3. Redesign the weakest path, modelling what the change adds or leaves behind, and write down every assumption.
  4. Adapt budget.py: what is left for releases, and which incidents fit?
  5. Add one shared cause (the region, or an identity provider two dependencies use) and recompute. Which claim from step 3 breaks?

10. Review prompt

Without looking back, explain: why the error budget depends on the window and on what the SLI counts; the formulas for serial, parallel and k-of-n availability and the assumption behind each; how to model a cause two replicas share, and a dependency only some requests use; and the three levers for staying inside a budget.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check