Key takeaways
- ✓Cost per request is the bill divided by the requests: in the lab's model, a million redirects of a URL shortener cost 11.9 cents with capacity provisioned for a 3× peak all day, and 9.5 cents with capacity that follows the traffic.
- ✓The largest line was not compute: storing the new links for five years cost 4.8 cents (40%), sending 400-byte responses to the internet cost 3.6 cents (30%), and all the compute together cost 3.6 cents (30%).
- ✓Halving the app processes' CPU saves about 1.2 of the 11.9 cents, a tenth of the bill, because the app is only 20% of it; with capacity that follows the traffic, the same halving saves about 4% of 9.5 cents. That saving is arithmetic on the cost model, not a measured result.
- ✓The one-hour page rule fires when more than 6.72% of checkouts are bad over the last hour and the last five minutes, which is 2% of a 28-day error budget spent in one hour (a burn of 13.44, times the 0.5% the budget allows).
- ✓promtool, Prometheus's own rule tester, fired that page after 40 minutes at a burn of 20, 16 minutes at 50 and 4 minutes at 200, matching the formula's 40.3, 16.1 and 4.0 minutes; the calculator fired two minutes later each time.
- ✓Live, with every window divided by 60 so that the run takes 15 minutes, each page started and stopped within 2.6 seconds of the calculator's prediction, and the ticket was already firing at the start because long windows remember an earlier failure.
A million redirects on the URL shortener from earlier in the series cost about 12 cents in this model, and under a third of that was computing. Halving the app's processor time would save about a tenth. This chapter does two things. It prices a request by its parts, to see where the money goes, and it writes the alert rules for the SLO from code and tests them, the way you would test any other code.
The examples come from Lab 21 (SLOs and Observability) of the system design labs: script 06_cost.py for the bill, and script 05_rules.py for the alerts. Both ran on the same laptop setup as the earlier chapters, an Apple M4 Max with Docker Desktop and 16 virtual CPUs. Prometheus, the checkout services and the load tests all ran in Docker on that one laptop. Each result is one recorded run.
Cost per request
Cost per request is the bill divided by the requests. The lab computes it per million requests, which keeps the numbers readable. Each part of the bill has a rule for turning a measurement into dollars:
- Compute. Measured CPU-seconds per request, divided by the share of the machine you actually use (the lab assumes 60% utilization), times the price of a vCPU-hour. The lab prices containers on AWS Fargate's ARM rate, plus 2 GB of memory per vCPU.
- Egress. The bytes each response sends out to the internet, times the price per gigabyte. The design estimates 400 bytes a redirect. For a million redirects, that is 0.4 GB, and at $0.09 a gigabyte it costs $0.036, or 3.6 cents.
- Storage. The bytes each new link writes, times the number of copies, times the price per gigabyte-month, times the months kept. The design writes 500 bytes per link, one link per 100 redirects, two copies, for 60 months at $0.08 per gigabyte-month. That is 4.8 cents per million redirects.
Every price is an AWS list price for us-east-1, fetched on 4 November 2026. None of the prices is a negotiated or account-specific price.
Why the biggest line is not the CPU
Here is the bill for a million redirects, with capacity provisioned for a busy hour that is three times the average (the design's peak-to-average ratio), priced as in the lab:
| Part of the bill | CPU per redirect | Cents per million, provisioned for the peak | Share | Cents per million, capacity follows traffic | Share |
|---|---|---|---|---|---|
| Link storage, 5 years, 2 copies | 4.8 | 40% | 4.8 | 50% | |
| Egress, 400 bytes a redirect | 3.6 | 30% | 3.6 | 38% | |
| App processes | 0.440 ms | 2.4 | 20% | 0.8 | 8% |
| HAProxy | 0.081 ms | 0.4 | 4% | 0.1 | 2% |
| Redis | 0.068 ms | 0.4 | 3% | 0.1 | 1% |
| Postgres, primary and replica | 0.063 ms | 0.3 | 3% | 0.1 | 1% |
| Total | 0.651 ms | 11.9 | 9.5 |
Storage and egress are bytes, so their cost follows what the design writes and sends, not how busy the processors are. Storage is the largest line because links are kept for five years on two copies. Egress is the second because every redirect sends a response out. All the compute together is 3.6 cents, the same as egress. The app processes are the biggest compute part, at 2.4 cents.
Nothing in this table is a managed service. The lab prices Redis, Postgres and HAProxy as containers. A real deployment would use ElastiCache, RDS and a load balancer, each with its own price, which would make the compute share larger.
- Link storage, 5 years, 2 copies4.8¢40%
- Egress, 400 bytes a redirect3.6¢30%
- App processes0.440 ms CPU2.4¢20%
- HAProxy0.081 ms CPU0.4¢4%
- Redis0.068 ms CPU0.4¢3%
- Postgres primary0.008 ms CPU0.0¢0%
- Postgres replica0.055 ms CPU0.3¢3%
Recorded: every bar, both capacity modes, and the recorded totals, from the lab's 06_cost.py run (60% utilization, 400 bytes of egress per redirect, 500 bytes per new link kept twice for five years). Arithmetic: the halved app line and the saving. Prices are AWS list prices from 4 November 2026. Nothing here was re-measured.
Halving the CPU saves a tenth
Halving the app's processor time is a small change to the bill. The app's compute line is 2.4 cents at peak provisioning, so halving it saves 1.2 cents of the 11.9, about a tenth. With capacity that follows the traffic, the app's line is 0.8 cents of 9.5, so the same halving saves about 4%.
The lesson is the shape of the bill, not the number. Making the code faster is worth doing, but a smaller response, or links kept for less time, would save more than halving the CPU here. The lab's model is linear in CPU, so this halving is arithmetic on its output, not a measured result.
Idle machines for the peak
The compute line is mostly idle machines. Provisioned for the busiest hour and kept all day, the compute costs 3.6 cents per million. If capacity followed the traffic, it would cost about 1.2 cents. The ratio between them is the peak-to-average ratio of 3, which the model assumes. You pay for three times what the average needs.
Autoscaling is what closes that gap, when it keeps up with the traffic. The lab's monthly figures make the same point at scale: at the design's average of about 1,169 requests a second, the bill is $361 a month provisioned for the peak and $289 following the traffic. Those monthly figures include each new link's full five years of storage, so they are not one month's invoice.
What tracing costs
The checkout pipeline in the lab has seven services. Its processor time per checkout is 3.29 ms with tracing off, 3.95 ms with 10% of checkouts traced, and 4.19 ms with every checkout traced. Priced as in the rest of the chapter, with capacity following traffic, that is 6.0, 7.2 and 7.7 cents per million checkouts (7.65 in the results). Tracing every checkout raised the processor bill by 27%, before the collector and before storing the traces.
SLO alert rules, generated from code
The SLO is 99.5% of checkouts good, over 28 days. A checkout is good if it is answered with a success within 300 ms. The error budget is what the SLO allows to be bad: 0.5%. The burn rate is how fast the budget is being spent. A burn of 1 spends it in exactly 28 days, and a burn of 200 is a full outage.
The lab keeps the SLO in one place, in slo.py. From it, tools/gen_rules.py writes the Prometheus rules that Prometheus evaluates, and the calculator in the same module replays the same requests with the exact arithmetic. Both come from one definition, so they cannot drift apart.
There are three alert rules, each defined by the share of the budget it should catch:
- The one-hour page fires when 2% of the 28-day budget is spent in one hour. That is a burn of 2% × 672 hours ÷ 1 hour = 13.44, and 13.44 × 0.5% = 6.72% of checkouts bad. It also needs the last five minutes to be above the same line, so the alert clears soon after the problem stops.
- The six-hour page fires when 5% of the budget is spent in six hours. That is a burn of 5.6, or 2.8% of checkouts bad.
- The three-day ticket fires when 10% of the budget is spent in three days, a burn of about 0.93, or 0.467% of checkouts bad. It opens a ticket, not a page, because nothing needs a person tonight.
The generated Prometheus file holds the recording rules, which keep the error ratio over each window fresh, and the three alerts. Each alert is a plain expression. The one-hour page is rate1h > 0.0672 and rate5m > 0.0672 in the lab's file, with the same threshold written as a share of checkouts. A typo in a window or a threshold would show up only on the night it should have paged, so the lab tests the rules before that happens. The rate1h and rate5m in that expression are the error ratio over the last hour and the last five minutes.
Test one: promtool, on fake counters
promtool is Prometheus's own rule tester. The lab feeds it synthetic counters at one-minute samples: three days of normal traffic, then a constant burn, checking each minute for when the one-hour page fires.
| Burn | promtool: page fired after | Calculator: page fired after | Formula |
|---|---|---|---|
| 5 | never | never | never (5 is under the six-hour page's 5.6) |
| 20 | 40 min | 42 min | 40.3 min |
| 50 | 16 min | 18 min | 16.1 min |
| 200 | 4 min | 6 min | 4.0 min |
promtool matched the formula to the minute. The calculator fired two minutes later at every burn. The lab's README calls it a fixed offset in how the two count a minute's samples, because Prometheus's rate() extrapolates to the edges of its window. Burn 5 never paged, which is right: that burn belongs on the ticket.
Test two: live, against the calculator
The live test runs the real Prometheus, scraping the real gateway every second, with the same rules scaled down. Every window is divided by 60, so one hour becomes one minute and the run takes 15 minutes. The load is 200 checkouts a second. Payments fails 5% of charges from 420 to 720 seconds, and then 50% from 780 to 825 seconds. The calculator replays the client's own record of the same requests.
| Alert | Prometheus: firing, seconds into the run | Calculator, same requests | Fault |
|---|---|---|---|
| Six-hour page | 625.6 to 735.4 | 624 to 733 | 5% from 420 s (a burn of 10) |
| Six-hour page, again | 784.6 to 855.3 | 782 to 854 | 50% from 780 s |
| One-hour page | 791.6 to 831.2 | 789 to 830 | 50% from 780 s to 825 s |
| Ticket | firing at the start, off at 197 s, on again at 457 s | on from 464 s |
Every page started and stopped within 2.6 seconds of the calculator. The six-hour page took 206 seconds to fire after the 5% failure began, where the formula says 202. The one-hour page fired 12 seconds after the 50% failure began, where the formula says 8 plus the time for Prometheus to scrape and evaluate, and it cleared 6 seconds after the failures stopped, because of its short window.
The ticket is the surprise. It was already firing when the run began, because its 72-minute window at this scale still held the failed checkouts from an earlier test. Prometheus remembered them and the calculator's record of this run did not. Long windows remember: for days after an incident, a small new burn can reopen a ticket much sooner than you would expect.
The workflow and the results
Rules. 05_rules.py generates the rules, runs the promtool tests, and runs the live Prometheus for about 16 minutes. Its results are in data/results/05_rules.json. Each live alert's start and end times are recorded in seconds, next to the calculator's times for the same requests.
Cost. 06_cost.py takes about a second. It reads the CPU per redirect from Capstone A's load run at 3,000 redirects a second (Capstone A is the URL shortener design in the capstone labs), adds the design's egress and storage figures, and prices everything with the list prices in data/prices.json. Its results are in data/results/06_cost.json. The price file can be refreshed with tools/fetch_prices.py, which needs read-only AWS credentials.
Caveats
- List prices from one day. The prices are AWS us-east-1 on-demand list prices from 4 November 2026. They are not negotiated, not account prices, and not current as of this chapter.
- Measured versus assumed. The CPU per request and the live alert times were measured, once each. The 60% utilization, the 3× peak, the 400-byte responses, and the 500-byte links kept twice for five years are assumptions or the design's estimates, not measurements.
- Containers, not managed services. Redis, Postgres and HAProxy are priced as containers on Fargate. Managed services have their own prices and minimums, and they would change the shares.
- Only what the model prices. Requests charges, cross-zone traffic and other line items are not in the model. The compute shares could also change with a real load balancer.
- The 2-minute offset has one explanation in the lab. The README attributes it to how the calculator and Prometheus count a minute's samples. It is the same at every burn, and the rules match the formula either way.
- The ticket is outside the 3-second claim. The 3-second bound applies to the pages. The ticket's recorded restart at 457 seconds came 7.5 seconds before the calculator's 464.
- One recorded run. Each table is one run on one laptop, and the live numbers come from a single 15-minute run.
The checklist
- Write the SLO once, and generate the alerts from it. The calculator, the Prometheus rules and the dashboard should all come from the same definition.
- Test alert rules like code. promtool on synthetic counters, run before the rules ship, catches a wrong window or threshold before the night it matters.
- Expect long windows to remember. A ticket can outlive the incident that opened it, and that is correct behavior.
- Price a request by its parts. Storage, egress and compute are different lines with different levers: retention, response size and autoscaling, and faster code.
- Check the peak multiplier. If capacity is sized for a peak that is three times the average and kept all day, that multiplier is the first thing to look at, before the code.
Quiz
1.In the lab's model, what was the largest part of the bill for a million redirects?
2.The app's CPU is halved in the model. Roughly what share of the bill does that save when capacity is provisioned for the peak?
3.Why was the ticket alert already firing when the live run began, although nothing was failing?
Check your understanding
Try each question before opening its answer.
Why is storage the biggest line in the lab's bill, when the app's processes are the biggest compute line?
Storage is 4.8 cents per million redirects because each new link is kept for five years on two copies, and the design writes one link per 100 redirects. The app processes cost 2.4 cents at peak provisioning, and they are the largest compute line. Storage and egress depend on bytes, not on how busy the processors are, so making the code faster leaves them unchanged.
When capacity follows the traffic, halving the app's CPU saves about 4% of the bill, not a tenth. Why the difference?
The tenth comes from provisioning for the busiest hour all day, which makes the app's compute line 2.4 cents of 11.9. With capacity following the traffic, the 3× headroom is not multiplied in, so the app's line is 0.8 cents of 9.5. Halving it saves 0.4 cents, about 4%.
The six-hour page fired 206 seconds after the 5% failure began, but the formula says 202. Is that a problem?
Not really. The formula is the time for the six-hour window's bad share to reach the 2.8% line. The extra four seconds are the scrape and evaluation delay of a live Prometheus, which reads and checks once a second. The lab's 3-second bound is measured against the calculator on the same requests, and this page met it.
Why does a one-minute sample in promtool matter for an alert that fires after 40 minutes?
The test checks each minute after the burn starts, and the first minute that fails is when the page would have fired. A one-minute resolution means the answer is accurate to the minute, which is enough to catch a wrong window (a 3-minute window and a 1-hour window would page at very different times). A typo in a window usually moves the page by much more than a minute, so promtool catches it.
Next up: Clock skew and logical clocks, part 54: what time is it on two machines at once, and how do you order events when the clocks disagree?