Exercises: Cloud Cost Optimization
Solutions and grading notes are in the instructor companion. Exercises marked ๐งช use
code/cost_model.py. Every price in this chapter is the book's frozen rate card and yours is
different โ several exercises ask you to substitute your own, which is the point.
Warm-Up
Exercise 33.1 โ Which meter are you on?
Difficulty: โ โโ ยท Time: 15 minutes
ยง33.2: per byte scanned, per warehouse-second, per node-hour.
- For each system you use, name the meter. If you cannot, that is the exercise โ go and read the pricing page.
- For each, say what a 50% reduction in CPU time would save. Be honest; for one of the three the answer is nothing.
- For each, say what a 50% reduction in bytes read would save.
- Which of your systems dominates your bill, and does that match where your team's optimization effort goes?
Exercise 33.2 โ The Chapter 1 arithmetic
Difficulty: โ โโ ยท Time: 15 minutes
160 ร 10.0 ร $2.400 = $3,840.00 became 24 ร 1.3 ร $2.400 = $74.88.
- Compute the ratio, the annual saving, and the saving per character deleted (four characters).
--estimateprices the same fix at 126.5ร, 128.6ร, and 51.3ร. Explain why the node-hour meter shows the smallest ratio and the largest dollar saving.- ยง33.3 says the postmortem led with 51.3ร and buried $1,374,269. Rewrite the one-line summary the way ยง33.3 recommends.
Exercise 33.3 โ Read the bill
Difficulty: โ โโ ยท Time: 20 minutes ยท ๐งช
python code/cost_model.py --bill
- Storage is 2.1% and compute is 61.9%. Before looking, predict which category you would have optimized first, and say why.
- Four line items are unattributed. What do they have in common?
- Compute what deleting every byte Kestrel stores would save, and compare it to suspending one warehouse.
- Which single line item would you investigate first, and is it the largest one?
Core
Exercise 33.4 โ Estimate before you run
Difficulty: โ โ โ ยท Time: 40 minutes
ยง33.6's calibration exercise.
- For the next three queries you write against a real system: predict the cost, get the dry-run or
EXPLAINestimate, then read the actual. Record all three. - Report your error on each. Most people are wrong by more than 10ร on the first.
- Now do it for a query you have already shipped and run regularly. Annualize it.
- What would have to be true for that number to appear in front of you automatically?
Exercise 33.5 โ Attribute your own bill
Difficulty: โ โ โ ยท Time: 60 minutes
- Take a real bill. Split it by team. If you cannot, record how far you get and where you stop.
- Compute the unattributed share. Case Study 1's was 36.4%.
- For each unattributed item: is it waste, or is it shared infrastructure that genuinely has no single owner? The two need different answers.
- ยง33.5 says the fix that moved the number was charging the unattributed bucket to a team. Who would it be at your organization, and would they accept it?
- Case Study 1's unattributed spend resolved 87% by deletion, 13% by tagging. Predict your own split before you find out.
Exercise 33.6 โ Size the seven wastes
Difficulty: โ โ โ ยท Time: 60 minutes ยท ๐งช
python code/cost_model.py --waste
For each of the seven patterns, check whether you have it, and size it with arithmetic rather than instinct:
- A compute resource that does not suspend or stop when idle.
- A dev/test environment running outside working hours.
- Storage nobody has read in a year.
- Small-file request amplification.
- Cross-region or cross-AZ data transfer.
- A scheduled refresh far more frequent than anyone consumes.
- Raw data retained past its need.
For each: the monthly cost, the annual cost, and an honest estimate of weeks to fix.
Then: ยง33.7 found 83.3% of Kestrel's waste was idle, not inefficient. What is your share?
Exercise 33.7 โ Rank by payoff
Difficulty: โ โ โ ยท Time: 30 minutes ยท ๐งช
python code/cost_model.py --rank
- Take your Exercise 33.6 list and rank it twice โ by annual saving, and by annual saving per week of work.
- Do the two orderings differ? If not, either you are lucky or your effort estimates are uniform; check the second.
- Identify everything you could do in under one day. Total the annual saving. Kestrel's was $132,192.
- Identify your worst payoff-per-week item. Does it have a non-cost justification? If so, rewrite its proposal without the cost argument (ยง33.8).
Exercise 33.8 โ Unit economics
Difficulty: โ โ โ ยท Time: 45 minutes
ยง33.11: $0.1526 per order, 0.201% of GMV.
- Pick the business unit your organization counts โ orders, users, transactions, requests, patients. Compute cost per unit for your data platform.
- Compute cost as a share of the number your business reports.
- Decompose your bill into fixed and variable. Kestrel's came out ~64% variable.
- Using that decomposition, answer: if volume doubles, what happens to the bill and to unit cost?
- Find your step functions โ the lines that are flat until they jump. When is the next step?
Exercise 33.9 โ What the monitors cannot see
Difficulty: โ โ โ ยท Time: 40 minutes
Case Study 2: seven monitoring systems green for thirty nights.
- List every monitor on a pipeline you own. For each, say whether it watches time, correctness, volume, or money.
- Construct a change that would be invisible to all of them. Case Study 2's produced byte-for-byte identical output.
- Your duration alarm: is its threshold absolute or relative to the job's own history? Kestrel's 8-hour alarm missed a 3.75ร regression.
- Do you have any volume assertion on inputs, or only on outputs?
Exercise 33.10 โ The autoscaling trade
Difficulty: โ โ โ ยท Time: 30 minutes
Case Study 2's ๐ callout: autoscaling decoupled cost from latency, and latency was the only accidental cost signal.
- Verify the arithmetic: 24 nodes ร 1.30 h and 64 nodes ร 4.88 h. Why are the node-hours exactly 10ร apart?
- Compute what the job would have cost with no autoscaling and the same window change. Compare.
- For each autoscaled workload you run, name the signal that replaces latency. If there is none, that is your finding.
- ยง"Questions for Discussion" asks whether other reliability features hide signals. Take retries: what does an automatic retry hide, and how would you surface it?
Advanced
Exercise 33.11 โ Extend the model
Difficulty: โ โ โ ยท Time: 90 minutes ยท ๐งช
Add three to cost_model.py, with self-checks:
- Your own rate card, loaded from a file rather than constants. Then re-run every report and report which conclusions change.
- A reserved-capacity model โ commit level, discount, and the blended rate against a demand curve (ยง33.10).
- A spot model with an interruption rate and a re-run cost, answering "is spot worth it for this job?"
- Cost per pipeline over time, with the day-over-day anomaly check from Case Study 2.
- A storage-class model โ Standard, Infrequent Access, Glacier โ including retrieval cost, which is the term everyone omits.
- A break-even calculator for an optimization: engineering cost versus annual saving, in months.
Then: run #6 against Exercise 33.7's list at your own loaded engineering cost. How many of your optimizations never break even?
Exercise 33.12 โ Build the pull-request bot
Difficulty: โ โ โ ยท Time: 90 minutes
Case Study 2's fix.
- For your engine, find the API that estimates a query's cost without running it (dry run,
EXPLAIN, plan bytes). - Write the estimator. Given a changed file, produce before and after cost.
- Decide the threshold and the gate. Case Study 2 chose a soft gate with a label โ argue for or against.
- Run it against the last twenty merged changes in your repository. How many would have tripped it, and were any of them mistakes?
- ยง"What Happened": 5 of 11 flagged changes were modified or abandoned. What conversion rate would make you delete the bot?
Exercise 33.13 โ The commitment decision
Difficulty: โ โ โ ยท Time: 60 minutes
ยง33.10's trap: a 42% discount against a workload a migration was about to cut by 61%.
- Model it. Three-year commitment at 42% off, current spend $X, and a 61% reduction arriving in month
- What is the three-year cost with and without the commitment?
- Now model committing to the floor โ 60% of current โ and paying on demand for the rest. Compare.
- ยง33.10 claims a commitment converts a future efficiency into a sunk cost, so teams stop pursuing savings they cannot benefit from. Is that a real effect or a rationalization? Argue both.
- Write the two paragraphs you would send to a finance partner who wants to commit now. Give them something to say yes to.
Exercise 33.14 โ Deliver a cost finding
Difficulty: โ โ โ ยท Time: 45 minutes
ยง33.12: Kestrel's first attempt produced three weeks of defensiveness.
- Find a real cost finding about another team's work.
- Write the message twice โ once as the version that goes badly, once following ยง33.12's four rules. Compare them.
- Convert the number into the other team's units. What is $2,000 a month to a marketing team? To a product team? To a hospital's operations lead?
- ยง33.12's finding was wrong for one tile of eighteen because the engineer did not know what it was for. What is the equivalent thing you do not know about your finding?
- Send it. Report what happened.
Project Milestone
Exercise 33.15 โ Cost discipline for your platform
Difficulty: โ โ โ ยท Time: 3โ4 hours ยท ๐งช
Build ยง33.13's structure for your own work.
- One versioned rate card โ
rates.yml, a single source of truth. ยง33.13's ๐งฑ callout: Kestrel had two circulating answers to "what does a node-hour cost," which made every estimate arguable. - Attribute your bill, and publish the unattributed share.
- Run the seven wastes and size them.
- Rank by payoff per week, and do everything under a day.
- Compute your unit cost and its fixed/variable split.
- Add a cost estimate to code review for one repository.
- Add a daily per-pipeline cost anomaly check.
- Publish two numbers monthly: total, and unattributed share.
Deliverable: the rate card, the attributed bill, the ranked waste list with what you actually did, the unit cost, and the two monitors.
Report the unattributed share honestly, including if it is embarrassing. Case Study 1's whole finding is that the embarrassing number is the valuable one.
Exercise 33.16 โ The Part VI retrospective
Difficulty: โ โ โ ยท Time: 45 minutes
Part VI covered streaming, governance, privacy, ML, and cost. The book claims one finding recurs across all five: a control that exists and does not operate is not a control.
- Name the instance in each of the five chapters. One of them is in this chapter.
- For each, say what measurement would distinguish "exists" from "operates."
- Is there a single audit that would find all five at once? Chapter 30 Case Study 2 asks this and does not answer it. Answer it, or explain why it cannot be answered.
- Which of the five controls in your platform would fail this test today?