What you'll learn: By the end of this lesson you will be able to attribute spend to the services and teams that cause it, order the cost levers from cheapest to riskiest, work out whether a commitment, an interruptible instance or a cheaper storage tier actually pays off for a given usage pattern, and express cost as a unit price you can track.
A household that wants a smaller electricity bill does not start by negotiating a better tariff. It first finds which appliances run, notices the heater left on in an empty room, and only then compares tariffs. Doing it in the other order buys a cheap rate for power nobody needed.
Cloud cost works the same way. The order matters: see where the money goes, stop paying for what nobody uses, size what remains, and only then change how you buy it. The capacity and cost lesson listed the biggest cost drivers. This lesson goes deeper on the decisions: who owns a cost, which lever comes first, and how to test a saving with arithmetic before you commit to it. Capacity planning has its own lesson, because the fleet size is the input to every number below.
Verified on 2026-12-01 against the AWS Well-Architected cost optimization pillar, the FinOps Foundation framework, the Amazon EC2, Savings Plans, Spot and S3 storage class documentation and the AWS cost allocation tag guide. Providers change their prices and terms often. Every price below is an illustrative round number, not a price list, and the script was run with Node.js v26.13.1.
The core idea
Cost optimization is not cost cutting. It is delivering the same business outcome, within your reliability and performance targets, at a lower price. The AWS Well-Architected pillar words the goal as "the best ratio between cost and business value", and describes a cost-optimized workload as one that delivers outcomes "at the lowest appropriate price point".
Two consequences shape the lesson. First, cost is a design input like latency, so it needs an owner and a number. Second, the cheapest saving is the one that removes work or waste. A discount applied to waste is still waste.
Three illustrations run through the lesson, each labelled:
- Minimal example: a commitment that pays only if the instance is busy often enough.
- Realistic example: ShopStream's daily traffic curve across a compute fleet, with batch work and old storage.
- Failure example: a commitment sized to the peak.
See the money: attribution and unit cost
You cannot optimize what you cannot attribute. The pillar says it plainly: "You cannot optimize what you cannot see". Its area on expenditure and usage awareness covers monitoring cost and usage against the teams that create it, managing resources across their lifecycle, and planning for data transfer.
In practice this means tags (labels such as service, team or environment on every resource) and a billing report grouped by them. The AWS cost allocation guide describes the mechanism: tags are keys and values on resources, they must be activated before they appear in Cost Explorer or a cost allocation report, and the report includes untagged costs too, so that totals reconcile. It also says tags can take up to 24 hours to appear. Untagged spend is the first thing to hunt, because nobody owns it.
The FinOps Foundation describes the discipline as "an operational framework and cultural practice which maximizes the business value of technology", with a journey of Inform, Optimize and Operate and a principle that "everyone takes ownership for their technology usage". The practical reading for a back-end team: the people who write the service see its cost.
Figure 1. Making spend attributable. How to read this: resources carry tags, the billing report groups spend by them and the owner sees a unit cost. Whatever lands in "untagged" is a task for the platform team, not a number to ignore.
A unit cost divides spend by a business quantity: cost per 1,000 orders, per active user or per request. It answers a question the total cannot: whether a bill that doubled came with twice the orders (healthy) or the same orders (a problem).
The levers, in order
idle resources, old data"] --> B["2. Right-size and scale to demand"] B --> C["3. Match each part to a pricing model
on-demand, commitment, interruptible"] C --> D["4. Change the architecture
caching, data locality, tiers"]
Figure 2. Order of attack. How to read this: each step shrinks the amount the next step has to discount. Buying a commitment before right-sizing locks in the wrong size.
The pillar's own structure agrees: its cost-efficient-resources area covers choosing the resource size and number that fit the work and the pricing model that matches how each component runs, and its continuous-optimization area adds reviewing on a cadence and automating.
Lever 1 and 2: waste and right-sizing
Idle environments, forgotten snapshots, unattached volumes and oversized instances are the common finds. Right-sizing links to capacity planning: the fleet should follow the daily curve (autoscaling or scheduled scaling) rather than stay at its peak size all day, within the headroom the reliability target needs.
Lever 3: pricing models
The EC2 documentation lists the purchasing options. On-Demand: pay by the second for the instances you launch. Savings Plans: a commitment to a consistent amount of usage, in USD per hour, for a 1 or 3 year term. Reserved Instances: a commitment to an instance configuration for a term. Spot Instances: unused capacity at a lower price. The page's guidance is that Spot suits you "if you can be flexible about when your applications run and if they can be interrupted". The Savings Plans page adds that the price stays the same through the term and that payment may be all, partial or no upfront.
The minimal example: break-even of a commitment
Minimal example (illustrative). On-demand costs 0.10 per instance-hour. A commitment costs 0.065 per committed hour, and you pay it every hour whether or not the instance is busy. The commitment wins on a given instance only if it is busy for more than 0.065 / 0.10 = 65% of the hours. Below that you pay for hours you did not use at a rate that was never going to beat on-demand.
The same test works for any commitment: break-even use is the committed rate divided by the on-demand rate. A deeper discount lowers the bar; a rate close to on-demand raises it.
Figure 3. Interruptible compute needs idempotent, retryable work. How to read this: the saving is only real if a reclaimed instance costs a retry rather than a failed job. See idempotent consumers for the design.
The Spot documentation says an instance can be interrupted "when Amazon EC2 needs the capacity back", for capacity, price or constraint reasons, that availability varies, and that "it is always possible that your Spot Instance might be interrupted". Check your provider's current notice period and prepare-for-interruption page before you rely on it. The queue and acknowledgement design is covered in message queues.
Lever 3 for data: storage tiers
Amazon S3 offers storage classes for different access patterns. At the time of writing its documentation says S3 Standard-IA suits long-lived, infrequently accessed data, charges a per-GB retrieval fee, and has a 30-day minimum storage duration and a 128 KB minimum billable object size; Glacier classes have 90 or 180 day minimums, and Intelligent-Tiering moves objects between tiers automatically, with a monitoring fee but no retrieval fee. A cheaper tier is cheaper to hold and dearer to read, so the test is how much of the data is read.
Lever 4: architecture and data transfer
Some of the largest savings change the design: a cache in front of a hot read (caching basics), a CDN in front of static files (CDN and edge networking), keeping chatty services in one zone, and compressing what crosses a boundary. The pillar has a separate practice for data transfer because it is easy to miss until it shows up on the bill. Check your provider's pricing page for whether traffic between zones or regions is charged. In the illustrative example below, a service pair that exchanges 2,000 GB a day across zones at 0.01 per GB costs 600 a month for traffic alone.
The realistic example: ShopStream compute, batch and storage
Realistic example (illustrative). ShopStream's browsing service needs 14 instances to carry its peak at the planned utilisation (the capacity lesson's result for month 12), three zones, one may be lost, so the fleet at peak is 21. Demand follows a daily curve, from 20 percent of peak at night to 100 percent at midday and early evening. A nightly batch job needs 6 instances for 8 hours. 40,000 GB of exports older than 90 days sit in standard storage. Prices: on-demand 0.10 per instance-hour, committed 0.065, interruptible 0.03; storage 0.02 per GB-month standard, 0.012 infrequent access, and a retrieval fee of 0.02 per GB.
// cost.mjs - all prices are illustrative round numbers, not any provider's price list.
const od = 0.10, commit = 0.065, spot = 0.03; // per instance-hour
const days = 30, zones = 3, needPeak = 14; // needPeak: instances that carry the peak
const curve = [0.25,0.2,0.2,0.2,0.25,0.3,0.4,0.55,0.7,0.8,0.85,0.9,1,0.95,0.9,0.85,0.85,0.9,1,0.95,0.8,0.6,0.4,0.3];
const fleet = curve.map((f) => Math.max(zones, Math.ceil(Math.ceil(needPeak * f) / (zones - 1)) * zones));
const usd = (x) => "quot; + x.toFixed(2);
const fixed = Math.max(...fleet) * 24 * days * od;
const follow = fleet.reduce((a, n) => a + n, 0) * days * od;
console.log("hourly fleet:", fleet.join(" "));
console.log(`A fixed at peak ${usd(fixed)}, B follows demand ${usd(follow)}`);
for (const c of [0, 3, 6, 9, 12, 15, 18, 21]) {
const used = fleet.reduce((a, n) => a + Math.max(0, n - c), 0) * days * od;
console.log(`commit ${c}: ${usd(c * 24 * days * commit)} committed + ${usd(used)} on-demand = ${usd(c * 24 * days * commit + used)}`);
}
console.log(`break-even: a committed unit must be busy ${(commit / od * 100)}% of hours`);
for (const c of [9, 12]) console.log(`unit ${c} is busy ${fleet.filter((n) => n >= c).length} of 24 hours`);
const batch = 6 * 8 * days; // nightly job: 6 instances, 8 hours
console.log(`batch: on-demand ${usd(batch * od)}, interruptible with 15% rework ${usd(batch * spot * 1.15)}`);
const gb = 40000, std = 0.02, ia = 0.012, fee = 0.02; // per GB-month, per GB retrieved
console.log(`storage: standard ${usd(gb * std)}; infrequent access wins below ${((std - ia) / fee * 100)}% of data read per month`);
for (const r of [0.1, 0.8]) console.log(` read ${r * 100}%: ${usd(gb * ia + r * gb * fee)} vs ${usd(gb * std)}`);
Output of running the script with Node.js v26.13.1:
hourly fleet: 6 6 6 6 6 9 9 12 15 18 18 21 21 21 21 18 18 21 21 21 18 15 9 9
A fixed at peak $1512.00, B follows demand $1035.00
commit 0: $0.00 committed + $1035.00 on-demand = $1035.00
commit 3: $140.40 committed + $819.00 on-demand = $959.40
commit 6: $280.80 committed + $603.00 on-demand = $883.80
commit 9: $421.20 committed + $432.00 on-demand = $853.20
commit 12: $561.60 committed + $297.00 on-demand = $858.60
commit 15: $702.00 committed + $171.00 on-demand = $873.00
commit 18: $842.40 committed + $63.00 on-demand = $905.40
commit 21: $982.80 committed + $0.00 on-demand = $982.80
break-even: a committed unit must be busy 65% of hours
unit 9 is busy 19 of 24 hours
unit 12 is busy 15 of 24 hours
batch: on-demand $144.00, interruptible with 15% rework $49.68
storage: standard $800.00; infrequent access wins below 40% of data read per month
read 10%: $560.00 vs $800.00
read 80%: $1120.00 vs $800.00
Read the output in order. Following the daily curve (B) is 31.5 percent below a fixed fleet at peak (A), before any commitment. A commitment of 9 instances brings the month to 853.20, the lowest of the levels tried, because the ninth committed unit is busy 19 of 24 hours, which is above the 65 percent break-even (19 of 24 is 79 percent). The twelfth is busy 15 of 24 hours, 62.5 percent, below break-even, and its row costs more, 858.60. The interruptible batch costs 49.68 against 144.00 on-demand even after 15 percent rework (illustrative). And storage moves to the cheaper tier only while less than 40 percent of the data is read in a month.
Dividing the compute bill (853.20 plus 49.68) by 15,000,000 orders a month (500,000 a day, the shared figure, over 30 days) gives about 0.06 per 1,000 orders. That is the unit cost to track: it should stay flat, or fall, as orders grow.
The failure example: a commitment sized to the peak
Failure example (illustrative). A team buys the commitment for the 21 instance peak. The 21 row of the output costs 982.80, which is 129.60 a month more than the 9 instance commitment, because the last committed units are busy only 7 of the 24 hours in the hourly row. If the team later right-sizes the fleet, the commitment stays and the unused hours are still paid for.
Figure 4. A lifecycle rule moves data down by age. How to read this: the ages are illustrative ShopStream policy, not provider defaults. A job that reads the older tier often can cost more than leaving the data where it was, which is why the read rate is measured first.
Trade-offs
| Choice | Gain | Cost | Wrong when |
|---|---|---|---|
| Follow the demand curve | Pay for what the day needs | Scaling delay, headroom still required | Spikes outrun scaling |
| Commit a baseline | Lower rate on steady use | Pay for unused hours | Usage is shrinking or uncertain |
| Interruptible capacity | Large discount | Interruptions and retries | Work cannot be retried safely |
| Cheaper storage tier | Lower holding cost | Retrieval fee, minimum duration | Data is read often |
| Reduce redundancy | Fewer resources | Larger blast radius | The SLO needs the redundancy |
| Cache or CDN | Fewer origin requests | Invalidation, stale reads | Content changes on every request |
In practice: a bill that grew faster than orders
This is an educational scenario on ShopStream with illustrative numbers.
This is a realistic scenario, not a case history.
The situation
Over one quarter ShopStream's cloud bill rose 40 percent while orders rose 10 percent (illustrative). Finance asks for a plan and engineering fears that cutting cost will hurt reliability.
Starting architecture
A fixed fleet of 21 on-demand instances sized for the peak and one zone lost, a nightly batch on on-demand instances, and 40,000 GB of order exports in the standard tier. About a fifth of the bill (illustrative) carries no service tag.
Options considered
| Option | Gain | Cost | Wrong when |
|---|---|---|---|
| A. Buy a commitment for the 21 instance peak | Quick, one purchase | Pays for hours the fleet does not use | Any later right-sizing |
| B. Tag, follow the curve, commit a baseline, interruptible batch, tier old data | Layered savings, each testable | Several changes to verify | The team cannot own them |
| C. Negotiate a general discount | Little engineering | Discounts waste | Usage can still fall |
The decision
Option B, in the order of Figure 2. Tag first so every saving can be attributed, then scale to demand, then commit nine instances (the best level in the output), then move the batch to interruptible capacity and tier the exports once the read rate is measured.
Rollout and verification
One change per week. After each, compare the unit cost per 1,000 orders and the latency SLO with the week before. Add commitments in steps, not in one purchase, so a wrong forecast strands a small amount. Re-run the break-even test each quarter, because a commitment is a bet that usage stays.
The 2 a.m. failure
At 06:00 the page reads "Nightly export incomplete". The provider reclaimed most of the interruptible workers at 02:00 and the replacements were slow to appear. The batch had no checkpoints, so each reclaimed task restarted from zero.
First checks: count reclaimed workers and task retries, and see whether the job finished on its second attempt. Mitigation: fall back to on-demand workers for the rest of the night. Follow-up: checkpoint tasks, diversify instance types and zones for the pool, and set a deadline after which the job switches to on-demand automatically.
Architect's notes
- Make cost a design input: write the unit cost beside latency and availability in the design review.
- Tag first. Savings you cannot attribute cannot be defended or repeated.
- Test every saving with arithmetic like the break-even calculation, using your own prices.
- Commit the floor, not the peak: commit only what is busy most of the time, and buy it in steps.
- Keep the reliability target fixed while optimizing; if a saving needs a lower target, that is a business decision.
- Review on a schedule. The pillar describes the work as continual: demand shifts and prices change.
Common mistakes
- Buying a commitment before right-sizing and locking in the wrong size.
- Committing to the peak instead of the baseline.
- Treating interruptible capacity as normal capacity with no retry design.
- Moving data to a cold tier that is still read often.
- Ignoring data transfer until it appears on the bill.
- Optimizing a number nobody owns.
Key takeaways
- Cost optimization delivers the same outcome within the same targets at a lower price.
- Attribute first: tags, a billing report and a unit cost per business quantity.
- Order the levers: remove waste, right-size, match pricing models, then change the architecture.
- A commitment wins on an instance only above break-even use: committed rate divided by on-demand rate.
- Interruptible capacity saves money only for work that can be retried.
- A cheaper storage tier wins only while little of the data is read.
Practice exercises
Exercise 1 (30 min). Change the committed rate to 0.08 and rerun the script. Which commitment level is best now and what is the new break-even?
Exercise 2 (45 min). Change the demand curve to a flat 0.8 all day. What commitment level is best, and what does that say about steady workloads?
Exercise 3 (1 hour). Change the batch rework from 15 percent to 25 percent and then to 200 percent. At what rework rate does the interruptible price equal the on-demand price?
Related reading
- Capacity planning: the fleet-size input to the cost model.
- Capacity planning and cost: the overview of cost drivers and levers.
- Caching basics and CDN and edge networking: architecture levers.
- Message queues: retry design for interruptible workers.
- Observability with Micrometer, Prometheus and OpenTelemetry: the metrics that feed a unit cost.
Official documentation
- AWS, Well-Architected Framework: Cost optimization pillar.
- FinOps Foundation, FinOps Framework.
- AWS, Amazon EC2 billing and purchasing options.
- AWS, Spot Instance interruptions.
- AWS, Amazon S3 storage classes.
- AWS, Organizing and tracking costs using cost allocation tags.