Highlights

Contents

Part VII
07

Case study: capacity estimation

We turn resource arithmetic into a design claim someone can review. A total without its workload and failure assumptions cannot defend an architecture. We will trace Heron’s paths, count their budgets, and state the evidence still needed.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Latency, throughput andLittle's law2p50, p95 and p99 latency3IOPS, bandwidth andstorage4CPU-bound, I/O-bound andbottlenecks5Scaling and Amdahl's law6Queueing and backpressure7Case study: capacityestimation

#Section 31Failure capacity and headroom

Heron’s illustrative application fleet has five servers, each assumed to sustain 300 requests per second for the chosen workload. All together provide 1,500 requests per second. Losing one leaves 4×300=1,2004\times300=1,200, which exceeds the assumed 1,000-request peak by 200.

Headroom is service capacity intentionally left unused for bursts, failures, and variance. Normal utilization of this capacity model is 1,000/1,500=66.6667%1,000/1,500=66.6667\%, rounded to four decimals. After one failure it is 1,000/1,200=83.3333%1,000/1,200=83.3333\%. These ratios alone do not prove the tail objective holds.

To survive one unavailable server under the same per-server capacity assumption, the fleet needs ⌈1,000/300⌉+1=5\lceil1,000/300\rceil+1=5 servers. The added server protects an application-server failure. It does not protect a shared database, a rack containing all servers, or a routing failure that isolates the whole fleet.

Run the workload with the failed node absent, not merely with a lower offered rate while all nodes remain healthy. Observe uneven routing, reconnect bursts, cache warm-up, and shared dependency usage. The failure budget is credible only when the surviving path meets its useful completion and latency objectives under those conditions.

ILLUSTRATIVE ONE-SERVER FAILURE BUDGETall five up, demand 1,000 req/s2002002002002005 × 300 = 1,500 req/s capacity1,000 / 1,500 = 66.6667%one server lost2502502502504 × 300 = 1,200 req/s capacity1,000 / 1,200 = 83.3333%300 req/s eachservers for one spare: ⌈1,000 / 300⌉ + 1 = 5test the path while a component is missing
Figure 2.36Illustrative normal capacity is 1,500 requests/s; one-server failure leaves 1,200 against demand of 1,000.

#Section 32The API request budget

Follow one Heron score request from arrival to response. Admission reserves a bounded application slot; the handler consults the appropriate read path; the response returns and releases the slot. A cache miss adds dependency work, while a cache hit can avoid that work. Both still consume response bandwidth.

At the assumed peak and mean residence time, the API has 200 active requests. Its response payload is 2,000,000 bytes per second. If the illustrative CPU demand is 2 ms per request, it needs two CPU-seconds per second. Each figure counts a different resource, so none can substitute for the others.

For the four-page query example with a 90% page-reference hit ratio, physical read demand is 400 pages per second. At 4,096 bytes each, that is 1,638,400 read bytes per second. This model does not include writes, prefetch, or maintenance. It is a specific query-cost hypothesis to compare with storage measurements.

The pool’s ideal 2,000-operation-per-second occupancy ceiling also belongs beside its assumptions. Check query hold time and actual dependency throughput during failures. Then retain a margin for changed request mix and misses. A single “requests per second” label on a box cannot describe the path’s CPU, I/O, connection, and payload demands.

ONE REQUEST CONTRIBUTES TO SEVERAL RESOURCE LEDGERSviewer200 active1,000/s × 0.2 s2 CPU-s/s1,000 × 2 ms≤ 2,000 ops/s20 slots / 10 ms4,000 refs/s90% hit in memory400 reads/s1,638,400 B/sadmissionCPUpoolpage cachediskresponse: 1,000/s × 2,000 B = 2,000,000 B/seach tag has its own unit and boundary; none substitutes for another
Figure 2.37Computed illustrative request budgets attach distinct units to CPU, pool, storage, and response work.

#Section 33The live delivery budget

A scorer emits an update, and Heron’s gateways distribute it to subscribed viewers. Event production is 20 events per second; delivery is 1,000,000 recipient messages per second. The distinction determines where batching and coalescing can help without altering authoritative history.

With five illustrative gateways, each receives the event stream once. Upstream payload across those gateway copies is 20,000 bytes per second. Viewer output is 200,000,000 bytes per second. A diagram that draws only one arrow to a viewer conceals that delivery multiplication, so annotate the recipient count explicitly.

A gateway’s connection budget is a separate limit from its send rate. Slow recipients retain outgoing buffers and can consume memory even when average link usage fits. Bound per-recipient buffers, detect stalled connections, and reconnect using a known score version or event position. Decide whether an expired snapshot can be replaced by a newer one.

Do not claim that a gateway can serve its nominal connection count at every possible event rate. Test the combination of active recipients, payload size, write rate, encryption cost, and slow readers. A successful connection-opening test establishes neither a delivery-latency objective nor the capacity to recover every recipient together.

PRODUCTION AND RECIPIENT DELIVERY ARE DIFFERENT RATESscorer: 20 events/s5 gateway copies = 100 copies/sbuffer20 events/s × 50,000 viewers = 1,000,000 sends/sone dot = 250 viewers, 10,000 per gatewayslow readers also retain buffers
Figure 2.38Illustrative event production, gateway copies, and recipient delivery are separate resource counts.

#Section 34The complete resource ledger

Now reconcile the totals without changing their assumptions. The API workload, live workload, retained-write exercise, and cache exercise describe different roles in Heron. They belong in one capacity argument, but a viewer read must not silently become a stored record merely because the storage arithmetic is available.

Resource Stated workload Computed demand
API active work 1,000/s times 0.2 s 200 requests
API CPU service 1,000/s times 2 ms 2 CPU-seconds/s
API response payload 1,000/s times 2,000 bytes 2 MB/s
Query page misses 4 pages, 90% hit ratio 400 reads/s
Live recipients 20 events/s times 50,000 1,000,000 deliveries/s
Live payload Deliveries times 200 bytes 200 MB/s
Retained write payload 30 days, three copies 388.8 GB
Cache entries 100,000 times 2,100 bytes 210 MB

Each row names a path and a measurement boundary. Logs, replicas, retries, indexes, request bodies, and wire overhead need their own entries when they affect that boundary. Keep illustrative ratios visibly separate from measured values. Otherwise an exact-looking total can hide an invented input.

Review a changed assumption by recomputing the affected rows. A larger response changes network demand; a colder cache changes dependency demand; more replicas change retained copies and write traffic. This makes the argument falsifiable. Someone can point to one input and show exactly which capacity conclusion would change.

KEEP THE UNITS BESIDE THE NUMBERSAPI1,000/srequests arriving200 activeconcurrent requestsboundary: API servicelive20 events/sevents produced50,000 viewers1,000,000 deliveries/sboundary: gatewayscache100,000 keysworking-set entries210 MB100,000 × 2,100 Bboundary: cache memory
Figure 2.39Computed illustrative resource ledger keeps counts and units beside their workload boundaries.

#Section 35Defending the design at a whiteboard

An interviewer asks whether Heron can handle its peak. Start with the user operations and the assumed arrival shape. Explain where a request waits and which resources it uses. Then show that the selected application fleet survives the stated missing-server case without claiming that this alone proves the entire system fits.

Walk through the potential contradictions. The fleet has spare application capacity, but the database may cap the miss path. The API payload fits a smaller link, but live viewer delivery needs a separate distribution budget. The cache fits its entry calculation, but slow live clients and pending requests consume memory elsewhere.

Name the experiment that resolves each uncertainty. Measure CPU service per request, pool hold time, page misses under key skew, send rate with slow recipients, and useful throughput with one node absent. Then inspect recovery while new arrivals continue. The answer becomes stronger when you identify what could disprove it.

This unit stops at resource accounting and performance behavior. It has not explained how an index finds a page, how transactions order writes, or how replicas preserve a fact after failure. Those mechanisms belong in the database and distributed-systems units. You now have the quantities needed to ask whether each mechanism fits the workload.

EACH CAPACITY CLAIM NEEDS A MATCHING EXPERIMENTwork queue12341CPU hypothesismeasure service demand per request2miss-path boundtest key skew and cold pages3failure budgetremove the promised component4recovery budgetkeep new arrivals flowingname what could disprove it
Figure 2.40Illustrative architecture review connects each capacity claim with its unresolved measurement.