Cost management — study guide
The concept's fragments, read in order.
A bill you can explain
On your laptop, your app costs nothing to leave running. In production it runs on rented machines, rented disks and rented network, and every one of them is metered. Money leaves every hour whether anyone is using the app or not, and at the end of the month a bill arrives that someone has to be able to explain.
Cost management is treating that bill as one more signal from a running system, read with the same care as latency or error rate. It is not about spending as little as possible; an app that is cheap because it is too small to stay up has saved nothing. It is about knowing where the money goes, whether it is going there for a good reason, and what will happen to it when something changes.
That breaks into three habits. Read the bill: know which line items it is made of and what meter drives each one. Tie spend to load: divide what you pay by the work your app does, so a growing bill can be judged instead of feared. And price a choice before you make it: a new instance, a bigger database or a heavier response all have a monthly cost you can estimate before the change ships, not after the invoice lands.
What the bill is made of
An infrastructure bill looks long, but nearly every line belongs to one of four families, and each family has its own meter. Learn the meters and the bill stops being a wall of numbers. The exact units, rounding and prices differ by provider, region and plan, but the shapes are the same everywhere.
Compute is charged for time: the machines your containers run on are billed per hour or per second for as long as they are running, at a rate set by their size and region. Pricing calculators commonly treat a month as 730 hours (365 days times 24 hours, divided by 12), so an always-on machine at an illustrative 5 cents an hour costs 730 times 0.05, or $36.50 a month. Storage is charged for capacity held over time, usually in GB-months, with extra meters on some services for operations, snapshots and requests.
Data transfer is charged per GB moved, and direction matters. Data coming in from the internet is generally free, while data going out to the internet (egress) is charged, and traffic between zones or regions of the same provider often carries its own charge too. Managed services are the fourth family and usually combine meters: a managed database bills for the hours its instance runs plus the storage, backups and sometimes provisioned I/O behind it, and a load balancer typically bills for the hours it exists plus the traffic or capacity it handles.
For your app that maps cleanly: the instances running its containers are compute, the database is a managed service with storage attached, its backups are storage, and every response it sends to a user is egress. Once each line has a meter, each line has a question you can ask: is this many hours, GB-months or GB what the app actually needs?
Paying for what you reserved
Most of the bill is not charged for work done. A provisioned machine or managed database is billed for the capacity you reserved and the time it was running, not for how busy it was: one sitting at 3 percent CPU at four in the morning costs exactly what it costs at the evening peak. That makes provisioned capacity a fixed cost against traffic, and it steps rather than slopes, because you add capacity a whole machine at a time.
The alternative is usage-based pricing, where a serverless or per-request service charges for requests handled and compute actually consumed, and can drop to nearly nothing when there is no traffic. Its cost is variable: zero traffic, close to zero compute bill; twice the traffic, roughly twice the bill. Storage and other attached charges can still apply either way.
Neither wins everywhere, much like a gym membership against paying per visit: the membership costs the same whether you go or not, so it only wins if you actually go often. Per-request pricing wins when traffic is low or bursty, because you are not paying for idle hours. Provisioned capacity wins once traffic is steady and high enough that the per-request line would climb past the flat one. The point where the two lines cross depends on your own prices and traffic, which is why it is worth drawing for your own app rather than taking anyone's rule of thumb.
The hidden cost in a provisioned setup is idle capacity: the hours a machine was paid for and not needed. It never shows up as an error and never slows anything down, which is exactly why it goes unnoticed until someone reads the bill.
Cost per million requests
A total bill on its own cannot tell you whether anything went wrong. It rises when your app gets more users, which is good news, and it rises when something becomes wasteful, which is not. The way to tell them apart is unit cost: total spend divided by a unit of the work the app does, such as cost per million requests or cost per active user, with both numbers covering the same services and the same period, much as a bigger fuel bill can still mean a more efficient car, if it drove much further on it; the number that matters is the cost per mile, not the total.
A worked example, with illustrative numbers only. Say your app served 10 million requests last month and the infrastructure bill was $400. Its unit cost is 400 divided by 10, or $40 per million requests, which is 4 cents per thousand. This month traffic doubles to 20 million requests. If the bill comes in at $500, the unit cost is 500 divided by 20, or $25 per million: the bill went up, but every request got cheaper, because fixed costs like the database are now spread over twice the work.
Now suppose the same doubled month brings a bill of $900 instead. The unit cost is 900 divided by 20, or $45 per million, higher than the $40 you started from. Something is growing faster than your traffic: an oversized instance added in a hurry, a forgotten environment, a response that got heavier. Both bills went up; only one of them is a problem, and only the unit cost says which.
Pick a unit that matches what your app actually does, and watch its trend rather than a single month. A unit cost charted next to your latency and error rate turns the bill from a monthly surprise into a number that moves with your load, where a change in its direction is the thing to investigate.
The size you actually need
Rightsizing is matching what you pay for to what the workload actually uses. Instances get picked in a hurry, usually too big and on a guess, and nobody revisits the guess because an oversized machine never complains. The evidence for revisiting it is already in your metrics: CPU and memory utilization over a representative stretch, including the busiest hours, not one quiet afternoon. Memory is the one to check twice: on plain virtual machines it often needs an agent inside the machine to be measured, while container platforms report it per container.
If your app's instances never get near their limits, even at the evening peak, they are candidates to come down a size. Within one instance family, the hourly price usually rises roughly in step with capacity, so a step down is often a large saving on that line, though the exact ratio varies by provider and family and is worth reading off the actual price table. If the next size down has half the CPU and memory, the same peak load would roughly double its utilization, so check that number against the headroom your capacity plan calls for before you move. Then re-run the load test on the smaller size, because the per-instance capacity in your plan changes with it.
Size is not the only knob; shape matters too. Families differ in their balance of CPU to memory, and a workload that is memory-bound pays for idle cores on a CPU-heavy shape. Matching the family to the bottleneck you actually measured is often worth more than shrinking the size.
Rightsizing is a loop, not a one-off. Traffic grows, code changes and the right size drifts, so the same comparison of provisioned against used is worth repeating on a schedule, with the change itself made in your infrastructure code so it is reviewed and reversible like any other.
The resources nobody remembers
Some of every bill pays for nothing at all, like lights left burning in empty rooms: nothing breaks and nobody notices, but the meter keeps running. The usual suspects are the same everywhere: staging and test environments running through nights and weekends, disks left behind after the machine that used them was deleted, snapshots and images piling up with no retention rule, and a stray load balancer or address that outlived its purpose. None of these break anything, so no alert fires. They just bill, every hour.
The first defense is being able to say whose each line is. Cost-allocation tags (labels on some providers) are key-value pairs such as environment=staging or service=api attached to each resource, and billing tools group spend by them, so you can see what production costs separately from everything else. Tags only work if they are applied consistently when a resource is created; an untagged resource is spend nobody owns. Infrastructure as code helps twice here: the tags live in the same files as the resources, and the files are an inventory, so anything running that the code does not declare is a question worth asking.
Switching non-production environments off outside working hours is the cleanest saving there is, and the arithmetic is exact. A week has 168 hours. An environment that runs 12 hours on each of 5 weekdays runs 60 hours and is off for the other 108, which is about 64 percent of the week. If its compute line is an illustrative $84 a month running around the clock, on that schedule it costs 84 times 60, divided by 168, or $30, a saving of $54. Its disks still bill while it is stopped, so the saving applies to compute, not storage. On some providers a stopped machine keeps charging for compute too until it is deallocated, so check what "stopped" means on yours. And give the schedule exceptions for the overnight soak tests that need staging running while everyone is asleep.
Cleaning up comes with one caution. Snapshots and backups can look like waste and be the only copy you have, so confirm with whoever owns them, and with your backup plan's retention rules, before deleting anything that might be a restore point.
Price it before you apply it
Every infrastructure change has a monthly price, and the cheapest time to learn it is before the change ships. Most of the time the arithmetic is short, because the bill's meters tell you what to multiply: hours times an hourly rate for a new machine, GB-months times a storage rate for a bigger disk, GB times an egress rate for heavier responses.
Egress is a line that often surprises, so take it as the worked example, with illustrative numbers. Your app serves 10 million requests a month with responses averaging 50 KB. That is 10,000,000 times 50 KB, or 500,000,000 KB, which is 500 GB sent out each month. At an illustrative 8 cents per GB, before any free allowance, that is 500 times 0.08, or $40. Now a change adds an uncompressed 450 KB image to every response, taking the average to 500 KB. The same arithmetic gives 5,000 GB and $400 a month: ten times the egress line, from one change nobody thought of as an infrastructure decision.
For changes to the infrastructure itself, tooling can do the multiplying. Pricing calculators let you build an estimate by hand from the services, sizes and usage you expect. Cost-estimation tools go further for infrastructure as code: they read the plan your IaC tool produces, price the resources it would create, change or destroy, and post the monthly difference beside the change in review, so a reviewer sees what a change costs next to what it does.
Treat every such figure as an estimate, not a bill. Usage-based lines depend on traffic you have to guess, and discounts and commitments change the real rate. The value is not precision; it is that the cost of a decision gets looked at while the decision can still be changed.
A ceiling that warns you
A budget is a monthly amount you expect to spend, with alerts set at thresholds along the way. The major providers all let a budget alert on actual spend, say when the month reaches 80 percent of the amount, and on forecast spend, when the projected end-of-month total is heading past it. The forecast alert is the useful one: it fires partway through a runaway month instead of on the day the invoice arrives. Forecasts need some billing history, though, so a new deployment may only have threshold alerts at first.
What a budget usually does not do is stop anything. By default a budget is a warning, not a spending cap: cross it and your app keeps running and keeps billing. Some providers offer actions that can stop selected resources or pause new usage when a budget is crossed, but those are separate configuration, and even then some resources may keep running and billing. Think hard before wiring one to production, because a cap that switches your app off is an outage you scheduled yourself.
Budgets catch totals; anomaly detection catches shapes. An anomaly detector compares spending against its own recent pattern and flags a line that suddenly looks unusual, such as a storage charge that tripled overnight, even while the month as a whole is still under budget. The two complement each other, and both are notifications for a person to read and act on during working hours, not machinery that fixes the bill on its own.
Paying less for promising to stay
Providers will charge you less per hour if you promise to keep paying. Commitment discounts (reserved instances, savings plans and committed-use discounts, depending on the provider) trade flexibility for price: you commit to a level of usage or an hourly spend, typically for one or three years, and that commitment is billed at a lower rate than the same usage on demand, like a phone contract that is cheaper per month because you promise to stay for a term, and that you keep paying even if you stop using the phone.
The catch is that the commitment is paid whether you use it or not. Unused commitment generally does not roll over, and many cannot be canceled or changed mid-term. So the skill is sizing it: commit only to the floor of usage you are confident will still be there for the whole term, and leave everything that rises and falls on demand. For your app, the database instance that runs every hour of every month is the obvious candidate, and so is the always-on floor of app instances that never scales away; the extra instances that appear only for the evening peak are not.
Order matters. Rightsize first, then commit, because a discount on an oversized machine locks in the waste for the length of the term. And commit after your traffic has settled into a pattern you can read, not in the first month of production, when you are still learning what the floor is.
Spot or preemptible capacity is a different bargain: discounted spare capacity that the provider can take back when it needs it. It suits work that can be interrupted and retried, such as a batch job that can pick up where it stopped, and does not suit the always-on parts of your app that users are waiting on.
Cost is a production signal
Taking your app to production means owning its bill as well as its uptime. A few thousand users and growing is exactly the stage where cost habits are cheap to build and expensive to skip: the bill is still small enough to read line by line, and every decision made now, an instance size, a commitment, a response format, gets multiplied by the growth that follows.
The habits are small. Read the bill once a month and be able to say what drives each line. Put a unit cost, such as cost per million requests, on the same dashboard as latency and error rate, so you see whether growth is getting cheaper or dearer per request. Set a budget with a forecast alert so a runaway month announces itself early. Tag what you create, switch off what nobody is using, and price each infrastructure change before it ships, in the same review that checks the code.
None of this is about being frugal for its own sake. A service that is cheap because it is too small to stay up is not cheap. The aim is a bill you can explain, where every line is there on purpose and tracks the load it serves. The economics of AI model calls, priced per token rather than per hour, follow different meters and are their own concept; the infrastructure your app runs on is where the same discipline starts.