Sizing and TCO

ch11 · Headroom and failure domains

Builds on ch06, ch07 and ch10.

A video summary of this chapter, generated from the page by an AI tool (how it was made). The page is the authority; the video needs a network connection.

The question

Why is headroom a rule rather than a number?

Because the number is different for every ceiling, for reasons that have nothing to do with each other. And because the moment it becomes a single number, it becomes a number somebody rounds.

The material

Three margins, three different things being protected

Here is every ceiling in the book’s two models, with its declared margin. First the running example’s, as this chapter leaves it, then the observability platform’s:

CeilingAt the planHeadroomAllowedLimitVerdictOver allowedOver limit
working set against memory0.7525%0.751.00ok49%35%
utilisation, counting coordination0.9530%0.701.00into the margin65%48%
disk fill at horizon0.6725%0.751.00ok44%29%
utilisation with one host down0.6630%0.701.00ok46%30%
utilisation at the busy hour0.6430%0.701.00ok46%30%
fraction of the fleet doing nothing useful0.3250%0.501.00ok1%0%

Source — web_service_headroom-reference · the model to explore; each input with a range has a slider

CeilingAt the planHeadroomAllowedLimitVerdictOver allowedOver limit
ingest utilisation, measurednot yet measured
query path utilisation0.5740%0.601.00ok46%29%
ingest utilisation, quoted0.5140%0.601.00ok44%22%
retention store fill0.5830%0.701.00ok46%30%

Source — observability-reference · the model to explore; each input with a range has a slider · 2 measured constants have no measurement yet, so figures that depend on them say not yet measured (why)

They are all percentages, and they are not the same kind of thing.

A capacity margin protects against a cliff. Two ceilings protect capacity: working set against memory and disk fill at horizon. When the disk fills it shows up as failed writes. When the working set stops fitting in memory, some reads that were served from memory go to disk and the service time per request becomes a different number, from a different regime. ch08 is about why nothing in a chain of multiplications can say what that number is. What the margin buys is the time between noticing and doing something, plus the space a lost host’s copies need to land in.

A queueing margin protects against a slope. Nothing fails and nobody is paged. The fleet slides up ch06’s curve and every request pays in latency, for as long as nobody looks. This margin is larger than the capacity margins in the table, for two reasons. The failure mode is invisible, and recovering from it means adding machines, which ch07 showed works badly.

A scaling margin protects a budget. Nothing fails and nothing gets slow. The fleet costs more than its work is worth. It is the largest percentage in the table, and it is still the loosest ceiling. Its limit is the whole fleet wasted, so the allowed line still lets a large share of the fleet go on coordination before the ceiling objects. It is declared anyway, because a cost that has no bound on it grows.

The right size of each kind of margin is set by a different thing:

So one percentage applied to all three would fit at most one of them, and the reason it was chosen would not apply to the other two. The model file gives a reason beside every margin it declares. Here they are, in its words:

CeilingMarginWhy this margin
working set against memory25%
Past the limit, memory cannot hold the whole working set, so some reads go to disk. A request’s time then includes waiting for those reads, and the model has no term for that wait, so the service time per request is no longer the number this model was built on. Nothing in a chain of multiplications says what it becomes (ch08), and the margin is the working set’s own daily swing.
utilisation, counting coordination30%
This ceiling keeps the queueing margin, the same margin as the ceiling labelled utilisation at the busy hour. It applies the margin to the capacity the fleet can deliver, counting coordination, rather than to the capacity its hosts would have alone. Where the two ceilings disagree, this one is about the system you own (ch07).
disk fill at horizon25%
A fleet whose disks are full cannot take a dead host’s records. A filesystem needs free space to keep allocating well, and the margin carries this as an assumption rather than a measurement. The margin is the same node the sizing used, so the two cannot drift apart (ch11). Over the limit means out of space; inside the margin means the re-replication reserve has been spent on data.
utilisation with one host down30%
One host down at the busy hour: its share of the requests lands on the survivors, and the question is whether they are still inside the queueing margin. N+1 is this ceiling with the margin at zero. The margin here is the queueing margin, because a fleet that has lost a host is still a queue (ch11).
utilisation at the busy hour30%
Not a capacity limit: a fleet that is busy most of the time, but short of fully busy, has not run out of anything; it has a queue in front of it. The margin is large because crossing it is paid for in waiting time by every request, not in a failure that pages the people on call (ch06).
fraction of the fleet doing nothing useful50%
At the margin, half the fleet’s work is lost: one host in two does no useful work. The loss is to contention and to coordination between hosts. Nothing fails and nothing pages anyone; the fleet costs twice what its work is worth. A budget is the only thing this ceiling protects (ch07).

Source — web_service_headroom-reference · the model to explore; each input with a range has a slider

The one margin you can compute

Most headroom is judgement. One piece of it is arithmetic.

A fleet that has to survive losing hosts needs somewhere for their share of the requests to go. That capacity is the failure reserve. It has to be there beforehand. A fleet that finds it needs a failure reserve during a loss is already past its queueing margin.

A failure domain is the set of hosts one fault takes out together. One host is the smallest. Hosts that share a rack, a switch or a power feed make a larger one.

The reserve has to cover the failure domain you plan to survive. This chapter’s arithmetic, and the model’s ceiling below, take it to be one host.

Problem 11.1 asks for one number: the share of the fleet’s capacity that has to be kept free to survive losing a given number of hosts. Every fleet keeps one host free for each host it plans to lose. What changes with fleet size is the share of the fleet that host is. A small fleet keeps a large share of itself free: one host in five is a fifth of the fleet. A large fleet keeps a small share free. That is a capacity argument for larger pools, where each loss is a smaller share. It is not an argument for larger failure domains, which are worse, because more hosts go at once.

The margin is for a loss, not for a failure. A host drained for a kernel upgrade removes the same capacity as one that has died. A rolling upgrade drains hosts on purpose, one after another. So planned work spends the reserve by design, and a reserve sized only for hardware failure is already in use while an upgrade runs.

The running example carries this as a ceiling of its own: the queueing margin again, audited with one host gone, because a host lost at the busy hour is a queueing problem for the survivors:

  hosts_after_failure:
    kind: derived
    unit: host
    label: hosts after one is lost
    formula: hosts - one_host
  utilisation_after_failure:
    kind: derived
    unit: dimensionless
    label: survivors' utilisation
    formula: busy_cores / (hosts_after_failure * cores_per_host)
  failure_headroom:
    kind: ceiling
    unit: dimensionless
    label: utilisation with one host down
    of: utilisation_after_failure
    limit: 1
    headroom: queueing_margin
    because: >-
      One host down at the busy hour: its share of the requests
      lands on the survivors, and the question is whether they
      are still inside the queueing margin. N+1 is this ceiling
      with the margin at zero. The margin here is the queueing
      margin, because a fleet that has lost a host is still a
      queue (ch11).

The graph as ch11 leaves it, with every margin the model declares. Click any ceiling for its reason.

Two generations: the host with the most cores, and the last day

The mixed pool from ch10 is bought for requests routed by capacity, with some old hosts kept to the horizon. In it, some of this chapter’s ceilings mean something different, and one is new.

Surviving the loss of one host means surviving the loss of the host with the most cores, because that is the most processing one fault can take away. In a pool of one kind of host every host has the most cores. In the mixed pool it is a new host. The model’s failure ceiling subtracts that host’s cores from the pool’s total. The old hosts have more memory, so for memory the biggest loss is an old host, and the model has no ceiling for that loss.

A shard has to sit whole on one host, and it can land on the smallest. The pool’s total disk says nothing about whether a shard fits on the smallest host, so the smallest host’s disk sets a ceiling of its own, checked against the disk margin.

The old hosts retire on their own schedule, which need not match the purchase. The check has to hold at the worst point: after they go, while demand is still growing. The model’s old_retired scenario is that point: the same new hosts, and no old ones.

The table checks the pool three ways: as bought, with the old hosts kept; on the day they retire; and against the all-new fleet from ch10’s first column, the purchase the web service model recommends for this workload with no old hosts. Each cell gives the share of futures past the allowed line (Over allowed), then what the plan says at the point estimate: ok, into the margin or over. The table has the web service’s two capacity ceilings as well: working set against memory, and disk fill at horizon.

CeilingOver allowed, old hosts keptOver allowed, old hosts retiredOver allowed, all new hosts
utilisation at the busy hour, routed by capacity49%; plan: ok65%; plan: into the margin46%; plan: ok
the smallest host’s utilisation, routed equally69%; plan: over65%; plan: into the margin46%; plan: ok
utilisation with the host with the most cores down50%; plan: into the margin67%; plan: over46%; plan: ok
working set against memory23%; plan: ok69%; plan: over49%; plan: ok
disk fill at horizon34%; plan: ok68%; plan: over44%; plan: ok
largest shard against the smallest host’s disk2%; plan: ok2%; plan: ok2%; plan: ok

Source — mixed-pool, mixed_pool-reference, mixed_pool-old_retired and mixed_pool-replace · sizing.evaluate

On the day the old hosts retire, three ceilings are over at the plan: memory, disk, and losing the host with the most cores. The old hosts held all of the working set and much of the data. In ch10, with them kept, memory asked for no new hosts and disk for fewer. When they retire, the new hosts hold both alone. At the plan, they have too little of either. The table’s shares are of futures past the allowed line; it does not show how often the retired pool runs out altogether.

With the old hosts kept, routing requests equally is over at the plan, so the pool bought for routing by capacity does not survive equal routing. Once the old hosts retire, the two routing rows agree, because every host in the pool is then the same size.

The shard row does not move, because both generations have the same disk, so the smallest disk is the same whichever generation remains. It reads ok even where the disks are full, because it asks whether one shard fits on an empty host, not whether any host has room left.

The all-new fleet is ok at the plan on every ceiling. It is what buying for the day the old hosts retire comes to. It is the web service’s own count of new hosts, more than the kept pool buys. Keeping the old hosts then saves no purchase.

Buy for the day the old hosts retire, or keep the smaller purchase and plan the next one for that day. The model shows the gap; it does not choose between the two. ch22 prices them.

Margins do not add

A sizing conversation collects margins. Rebuild wants some. Queueing wants some. Growth between now and the next purchase wants some. Each request arrives separately, each is defensible, and each is granted.

Margins do not add. Each takes its share of what the previous one left, so applying them in sequence multiplies them. Take three margins of a quarter each. Added together, they reserve three quarters of the fleet and leave a quarter working. Applied in sequence, they leave a little over two fifths working.

So adding over-reserves: a room that adds its margins sizes the fleet as though only a quarter of it will do the work, and buys hosts that none of the margins it granted asked for. Problem 11.2 is the composition.

Push the margins up and addition stops describing anything. Three margins of ninety per cent add to nearly three whole fleets, and no system has negative capacity. Taking nine tenths three times over leaves a sliver. Multiplying still leaves a fleet with some capacity, where adding said it had less than none.

What a margin is for, written down

Every ceiling in this book carries a because. Not because it is tidy, but because the failure mode of a margin is specific and predictable: it gets copied.

A margin with a reason attached can be argued with, adjusted when the reason changes, and dropped when the reason goes away. A margin that is just a number gets carried into the next model, and the one after that, by people who were not in the room. Ten years later an organisation has a thirty-per-cent rule that everybody follows and nobody can source.

The toolkit refuses a ceiling without a reason. It cannot check that the reason is true; a reviewer reading it can.

The output a margin produces

Not a verdict. A probability.

The two ceiling tables at the top of The material end with two columns that answer two questions. Over allowed shows how often the design ends up past the allowed line (the limit less the margin), and Over limit shows how often it ends up past the limit itself. A verdict at the plan describes one future, but these columns describe all the futures the model thinks could happen.

At utilisation at the busy hour, the verdict is ok, but the Over limit column still shows the design past the limit in a share of the futures. At utilisation, counting coordination, the verdict is already into the margin — the plan has spent part of the reserve before anything has failed. Read its Over limit cell. ch12 prices the difference between a verdict at the plan and what the columns show.

What this cannot tell you

Whether any of these margins is right. Every margin in this book was declared in its model file, with a reason, and the reason is an argument rather than a measurement. This chapter argues that a margin must exist and must be explicable. It does not argue that these particular ones are correct, and it has no way to.

How long you have. A margin buys time between something going wrong and something being done. How much time depends on how fast your load moves and how quickly you notice, and neither is in any model here. A generous margin on a system nobody watches is not generous.

Whether the failure domain is what you think. The failure arithmetic assumes hosts fail independently. They do not. They share racks, power, switches, firmware versions, and the engineer who is applying an update to all of them. A margin sized for one host and spent on a rack is a margin that was not there.

Whether two losses can happen at once. The ceiling utilisation with one host down takes exactly one host away from the fleet. A planned drain during an upgrade and an unplanned loss can overlap: one host is out for a kernel upgrade when another fails. Then two hosts are gone at the busy hour. The model has no term for two hosts down at once. A reserve that covers one loss covers one of them, and the ceiling reports on a fleet that is one host larger than the one serving requests.

Whether the mixed pool’s checks are all the checks it needs. It checks losing the host with the most cores, with requests routed by capacity. It has no check for losing the host with the most memory, which is an old one, and none for a loss when requests are routed equally. It treats retirement as every old host leaving on one day, where real hosts leave a few at a time.

Key takeaways

  • Headroom is a rule because the right number differs for every ceiling. A capacity margin protects against a cliff, a queueing margin against a slope, a scaling margin against a budget, and one percentage cannot serve all three.

  • The failure reserve is the one margin you can compute, and it is for a loss, not a failure. A host drained for an upgrade removes the same capacity as one that has died. Every fleet keeps one host free for each it plans to lose: a small fleet keeps a large share of itself free and a large fleet a small share.

  • In a mixed pool, check the biggest loss and the last day. For processing, the host to keep free is the one with the most cores. The check has to hold on the day the old hosts retire, when memory and disk can be the first to break.

  • Margins multiply. They do not add. Each takes its share of what the one before left, so adding reserves more than the margins call for. A fleet sized by adding buys hosts none of the margins asked for, and for large margins addition reserves more than the whole fleet.

  • A margin without a reason gets copied. Every ceiling carries a because, so that the margin can be argued with, adjusted when the reason changes, and dropped when it goes away.

  • What a margin produces is a probability, not a verdict. Across the model’s futures, Over allowed is how often the design ends up past the allowed line (the limit less the margin). Over limit is how often it ends up past the limit itself. The verdict describes the plan at the point estimate only.

Problems

Four, in tests/headroom_and_failure_domains/. The first three have tests. The last does not.

11.1 — What a host loss costs. The one piece of headroom that is arithmetic rather than judgement. Then notice what it says about small fleets, and what it says about planned work.

tests/headroom_and_failure_domains/stubs.py · failure_reserveyours to edit
def failure_reserve(hosts: int, tolerated_losses: int) -> float:
    """Problem 11.1 - the margin a host loss costs.

    A fleet of ``hosts`` machines has to survive losing ``tolerated_losses`` of them and still
    serve the busy hour. Return the fraction of the fleet's capacity that has to be kept free for
    that, as a number between zero and one.

    Two things follow from the answer. First, every fleet keeps one host free for each host it
    plans to lose, but as a share of the fleet a small fleet pays far more. Losing one host out of
    five costs a fifth of the capacity. If that capacity is not free beforehand, the lost host's
    share of the requests lands on survivors that are already busy. That is a capacity argument
    for larger pools, where each loss is a smaller share. It is not an argument for larger
    failure domains: a failure domain is the set of hosts one fault takes out together, and a
    larger one is worse.

    Second, the margin is for a *loss*, not for a failure. A host drained for a kernel upgrade
    removes the same capacity as one that has died. A rolling upgrade drains hosts on purpose,
    so planned work spends this margin by design.
    """
    raise NotImplementedError("problem 11.1")

The same check at a desk: python3 -m pytest tests/headroom_and_failure_domains/test_problem_1_rebuild.py -m problem

11.2 — Two margins are not one margin twice. Compose several independent margins. Do not add them; the clue that you cannot is what addition does to three large ones. Then look at what three separately reasonable requests leave you.

tests/headroom_and_failure_domains/stubs.py · composeyours to edit
def compose(margins: list[float]) -> float:
    """Problem 11.2 - two margins are not one margin twice.

    ``margins`` are separate reasons to keep capacity free: a rebuild reserve, a queueing
    margin, room for the growth between now and the next purchase. Each is a fraction between
    zero and one.

    Return the combined margin: the fraction of the system kept free once all of them are
    applied. If a quarter of the system is left doing the work, return 0.75.

    Do not add them. Work out what applying one margin and then another does to what is left.
    The combined margin is never as large as the sum. For large margins the sum is not even
    a fraction: three margins of ninety per cent add to more than the whole system, which is
    a clue.

    Then look at what three modest margins leave doing the work, and understand what a sizing
    conversation achieves when each margin is a separate reasonable request.
    """
    raise NotImplementedError("problem 11.2")

The same check at a desk: python3 -m pytest tests/headroom_and_failure_domains/test_problem_2_compose.py -m problem

11.3 — Add a ceiling. The page shows a fragment of the model file: one ceiling, connections per host, with three fields left empty. Fill in the unit, the headroom (the margin) and the because (the reason), and change nothing else. The expression and the limit are given. The limit carries its unit by being multiplied by the constant that holds it, the way the model file does. The unit has to be the one the expression produces. You can find the units of concurrency and host_count by clicking each in the graph above. A margin can be written as a number or as the name of a node that holds one, as headroom: queueing_margin in the listing above does. The toolkit refuses the fragment until all three are right: a missing or wrong unit is refused by the loader or the units check, and a missing margin or a missing reason is refused by the model verifier. Each refusal is a rule this chapter argues for. Once it is accepted, the test evaluates the web service model with the new ceiling and checks that the ceiling reports a verdict and how often the model’s futures take it past its limit: the same Verdict and Over limit the tables at the top of this chapter show. The Check says whether the tests pass; it does not print those values.

tests/headroom_and_failure_domains/problem_3_ceiling.yamlyours to edit
# Problem 11.3 - a ceiling on connections per host, declared the way the model file declares one.
#
# The test splices this node into the web service model under `nodes:`, adds it to the outputs,
# and holds it to the three things declaring a ceiling commits you to: a unit the expression
# produces, a margin, and a reason. Three of the fields below are empty. Fill them in; change
# nothing else. The limit is given, and it carries its unit the way the model file carries
# one: multiplied by the constant that holds it.
connections_per_host:
  kind: ceiling
  label: connections per host
  unit:
  of: concurrency / host_count
  limit: 256 * one_request
  headroom:
  because:

The same check at a desk: python3 -m pytest tests/headroom_and_failure_domains/test_problem_3_ceiling.py -m problem

11.4 — Your margin, and who chose it. No test: the answer is a number somebody chose, and the interesting part is who.

Find the headroom your system is planned to, then find the person or the document that chose it.

Does the margin have a reason attached that is not “it is what we have always used”? Does your failure domain match the physical layout: are the machines you assume fail independently in the same rack, the same power feed, the same availability zone?

A good answer has three things: a number, a name or a document, and a reason. If the reason amounts to a round number, such as twenty or thirty per cent, ask what it would have been had the first person to say it said a different round number.

What would falsify the answer? Any one of these shows the margin is not the one the system needs:

Take the number, the name or document, and the reason that holds up under that test back to whoever sizes the system next.

Where to go next

ch12 assembles Part III: every chain, every margin, and a number at the end of it.

ch13 shows how the Over allowed and Over limit columns, and the shares in the mixed pool’s table, are computed: the model is worked out many times with its inputs drawn at random, and each column is the share of those runs past a line.

By Chris Snow, in collaboration with Claude (Anthropic) · Prose and figures: CC BY-NC 4.0 · Code and models: Apache 2.0