Example

Price the design's own numbers before anyone builds it

Price two candidate architectures against the same latency, load and consistency rows and see one FAIL row reject a shape regardless of its prose.

A design document that claims “meets latency goals” while listing per-hop latencies that sum past the budget does not need a load test. It needs adding up. The chapter’s method is a constraint table where each row is a bound, the design’s own line items, and a verdict, and where one FAIL row rejects the shape and one UNVERIFIABLE row rejects the document. This program prices two candidates on identical rows.

Run it

Save this as design_pricing.py and run it with Python 3.11 or later. It uses the standard library only.

"""Chapter 27: price the design's own numbers before anyone builds it.

The arithmetic is the chapter's. The verdict rule is the chapter's rule: one
FAIL row rejects the shape, one UNVERIFIABLE row rejects the document.
"""

BUDGET_P99 = 200      # ms, from the intent contract (Ch25)
QUOTA_RPS = 250       # downstream quota
STALENESS_BOUND_S = 5  # the read-your-write bound the design must state

# name, per-hop p99 ms, overlap, fan-out, rps, staleness bound (None = none)
CANDIDATES = [
    ("A: 3-way fan-out (proposed)",
     {"auth": 80, "profile": 190, "reco": 180}, "none", 3, 100, None),
    ("B: cached profile + collapsed hops",
     {"auth": 80, "cache": 40}, "stated", 2, 55, 30),
]

VERDICTS = [("FAIL", "REJECT the design SHAPE regardless of prose quality"),
            ("UNVERIFIABLE", "REJECT the design DOCUMENT regardless of shape"),
            ("WAIVER", "VIABLE with bound waiver")]


def price(c):
    """Price one candidate against the bounds, row by row."""
    _, hops, overlap, fanout, rps, staleness = c
    total, floor, load = sum(hops.values()), max(hops.values()), fanout * rps

    if total <= BUDGET_P99:
        latency = "PASS", f"{total} ms sequential"
    elif overlap == "stated":
        latency = "PASS", f"{total} ms, overlapped to {floor} ms"
    else:
        latency = "FAIL", f"{total} ms sequential, no overlap stated"

    if staleness is None:
        consistency = "UNVERIFIABLE", "no bound stated"
    elif staleness > STALENESS_BOUND_S:
        consistency = "WAIVER", f"{staleness} s staleness"
    else:
        consistency = "PASS", f"{staleness} s staleness bound"

    return [("p99 latency", *latency),
            ("peak load", "PASS" if load <= QUOTA_RPS else "FAIL",
             f"{load} rps vs quota {QUOTA_RPS}"),
            ("consistency", *consistency)]


for candidate in CANDIDATES:
    print(candidate[0])
    rows = price(candidate)
    for label, verdict, items in rows:
        print(f"  {label:12} | {items:34} | {verdict}")
    seen = {v for _, v, _ in rows}
    for trigger, outcome in VERDICTS:
        if trigger in seen:
            print(f"  -> {outcome}")
            break

print("RULE: one FAIL row rejects the design shape regardless of prose quality.")
print("One UNVERIFIABLE row rejects the design document regardless of shape.")

Expected outcome

A: 3-way fan-out (proposed)
  p99 latency  | 450 ms sequential, no overlap stated | FAIL
  peak load    | 300 rps vs quota 250               | FAIL
  consistency  | no bound stated                    | UNVERIFIABLE
  -> REJECT the design SHAPE regardless of prose quality
B: cached profile + collapsed hops
  p99 latency  | 120 ms sequential                  | PASS
  peak load    | 110 rps vs quota 250               | PASS
  consistency  | 30 s staleness                     | WAIVER
  -> VIABLE with bound waiver
RULE: one FAIL row rejects the design shape regardless of prose quality.
One UNVERIFIABLE row rejects the design document regardless of shape.

The two verdicts match the chapter’s tradeoff matrix: the proposed fan-out is rejected, and the cached design is viable only with an explicit staleness waiver, a tradeoff the original document never stated.

The table is the design review

The proposed design declares “parallel fan-out keeps latency flat” and states no overlap, so its latency row is the sum, 450 ms against a 200 ms budget: FAIL. The load row is 3 reads at 100 rps against a 250 rps quota: FAIL. The consistency row states no staleness bound: UNVERIFIABLE, rejecting the document even if the shape were survivable. The chapter’s arithmetic:

budget_p99 = 200  # ms, from intent contract (Ch25); UNKNOWN if contract lacks it
hops = {"auth": 80, "profile": 190, "reco": 180}  # design's own stated per-hop p99
parallel_floor = max(hops.values())  # 190ms before overhead, queueing, retries

Rejection here costs an envelope, not a staging environment.

Mechanism and limitations

Documented: the chapter states that the proposed fan-out sums to 450 ms against a 200 ms budget and fans out to 300 downstream rps against a 250 rps quota, with no staleness bound stated; that one FAIL row rejects the shape and one UNVERIFIABLE row rejects the document; that a single design is not a tradeoff because tradeoffs need two priced candidates; and that the arithmetic must be executed, not asserted.

Observed: the run above. Candidate A failed on latency and load and was unverifiable on consistency, so it was rejected as a shape. Candidate B passed both numeric rows and was marked viable with a bound waiver, its 30 s staleness exceeding the 5 s bound.

Not shown. The numbers are the chapter’s constructed illustration, not a measurement of any system. The verdict rule is a veto, not a decision procedure: it can reject a shape but not choose the right one, and the program does not compare cost, blast radius or team risk. The consistency row is a staleness bound only, so a conflict rule is priced as absent.

Read the chapter .

Understand this example

Copy this prompt into your AI tool. No code runs here.

Apply this example

Copy this prompt into your AI tool. No code runs here.