Sub topic 12
How cloud services are billed
This chapter assumes you know the three service models (IaaS, PaaS, SaaS) and the essential characteristics of the cloud, especially measured service. It also assumes you can read a short Python script. All prices below are illustrative round numbers. Real prices vary by provider, region, and date, so check the provider's price list before you plan a budget.
Billing follows measurement
The cloud meters what you use, so you can be billed for it. Every billing model comes from the same idea: the provider picks a unit it can measure and charges a price per unit.
Which unit the provider picks depends on the service model. Roughly, the lower the layer you rent, the closer the unit is to raw hardware. The higher the layer, the closer it is to people or business activity.
Common pricing models
Providers combine a small set of pricing models. Most real bills mix several.
| Model | You pay for | Commitment | Best for |
|---|---|---|---|
| On-demand (pay-as-you-go) | Exact usage, by the second, hour, or request | None | Unpredictable or short-lived workloads |
| Reserved or committed use | A lower rate in return for a 1 to 3 year commitment | Spend or capacity | Steady, always-on workloads |
| Spot or preemptible | Spare capacity at a deep discount | None, but the provider can reclaim it | Interruptible batch jobs |
| Subscription | A flat fee per seat or tier per month or year | Usually monthly or annual | SaaS products |
| Free tier | Nothing, up to a limit | None | Learning and small tests |
On-demand
On-demand is the default and the clearest form of pay-as-you-go. You start a resource, the meter runs, and you stop paying when you delete it. There is no up-front cost and no commitment, but the per-unit price is the highest.
Reserved and committed use
You promise to use a certain amount over one to three years, and the provider discounts the rate. The discount is real only if you actually use what you promised. Unused commitment is still billed. This is the standard trade: you give up flexibility, which is the elasticity you came to the cloud for, in exchange for a lower price.
Spot capacity
Providers sell idle capacity cheaply, with the condition that they can take it back on short notice. Your software has to tolerate interruption, for example by checkpointing work. Spot suits batch processing, rendering, and test runs. It does not suit a database that must stay up.
Subscriptions
Most SaaS uses a subscription. You pay per user (a seat) or per tier, which bundles features and limits. The cost scales with headcount rather than with compute use, so adding an inactive employee still costs money.
What gets metered
On IaaS, a single virtual machine produces several separate line items. People who expect one line, "the server", are usually surprised by the others.
- Compute: billed per second or per hour while the instance runs. A stopped instance generally stops accruing compute charges.
- Storage: billed per GB-month for the disk attached to the instance. This continues while the instance is stopped, because the data is still kept.
- Data transfer: inbound traffic is usually free. Outbound traffic to the internet, and often traffic between regions, is billed per GB. This charge is called egress.
- Extras: public IP addresses, load balancers, snapshots, and monitoring can each have their own meter.
PaaS bills in a similar way underneath, but often hides the pieces behind a plan. Elastic Beanstalk, for example, has no extra charge of its own. You pay for the EC2 instances, load balancer, and storage it creates for you. Other platforms sell a flat plan tier instead. Either way, you are paying for the resources the platform runs on your behalf.
Request-based billing
Serverless services (covered in a later chapter) bill per request and per unit of execution time. Idle time costs nothing. A function that runs a few thousand times a month can cost almost nothing, but a very busy one can cost more than a small always-on server.
A worked cost comparison
The script below compares four ways to run one small server for a month. The numbers are illustrative: an hourly rate of $0.0104, a 30% commitment discount, and a $0.08 per GB-month disk rate. It uses 730 hours as an average month.
HOURLY_RATE = 0.0104 # illustrative on-demand price per hour
COMMIT_DISCOUNT = 0.30 # illustrative discount for a 1-year commitment
HOURS_IN_MONTH = 730 # average hours in a month
STORAGE_GB = 30
STORAGE_RATE = 0.08 # illustrative price per GB-month
def compute_cost(hours, discount=0.0):
return HOURLY_RATE * (1 - discount) * hours
storage_cost = STORAGE_GB * STORAGE_RATE # billed even when the server is stopped
scenarios = {
"On-demand, always on": compute_cost(HOURS_IN_MONTH),
"On-demand, 10h x 22 workdays": compute_cost(10 * 22),
"Committed, always on": compute_cost(HOURS_IN_MONTH, COMMIT_DISCOUNT),
"Stopped all month": 0.0,
}
for name, compute in scenarios.items():
total = compute + storage_cost
print(f"{name:32s} compute ${compute:6.2f} total ${total:6.2f}")Running it prints:
On-demand, always on compute $ 7.59 total $ 9.99
On-demand, 10h x 22 workdays compute $ 2.29 total $ 4.69
Committed, always on compute $ 5.31 total $ 7.71
Stopped all month compute $ 0.00 total $ 2.40Three lessons follow from the output:
- Running only during working hours cut the compute cost by about 70%, because on-demand billing follows usage.
- The commitment helped the always-on case, but it would be a poor choice for a server you only run 220 hours a month. You would pay for hours you never use.
- Even a stopped server costs $2.40, because the disk still exists.
Cost behaviors to expect
Billing behaves differently from buying hardware, and several effects catch learners off guard.
- Costs are variable, not fixed. A traffic spike or a runaway job raises the bill automatically. Elasticity works in both directions.
- Granularity differs. One service bills per second, another per hour, and another rounds up to a minimum charge. Short-lived jobs are sensitive to this.
- Data leaving is expensive, data entering is cheap. This asymmetry is a major part of vendor lock-in, which a later chapter covers.
- Rates vary by region. The same instance type can cost noticeably more in one region than in another.
- Shared responsibility has a price too. On IaaS the provider does not patch your operating system, so you spend staff time on it. On SaaS the subscription fee already includes that work. Compare total cost of ownership, not just the invoice.
Billing and the service models
The same workload can cost very different amounts depending on the model you pick, and the cheapest invoice is not always the cheapest option.
| Model | Typical bill shape | Cost grows with | Hidden cost to watch |
|---|---|---|---|
| IaaS | Many small line items | Machine size, running time, data out | Your own operations labor |
| PaaS | A plan tier or the underlying resources | Plan size or resources provisioned | Scaling to a higher tier in jumps |
| SaaS | One subscription | Number of users or feature tier | Paying for unused seats |
IaaS gives you the finest control over cost, and also the most ways to waste money. SaaS gives you a predictable bill but little room to optimize. PaaS sits between the two.
Summary of practical rules
- Use on-demand until you understand your usage pattern.
- Commit only for the baseline load you are sure will keep running.
- Use spot capacity only for work that can be interrupted and resumed.
- Delete what you stop using, and set a budget alert from day one.
- Read the egress and storage prices as carefully as the compute price.
Exercise
A team runs a test database on an IaaS virtual machine with a 100 GB disk. They stop the VM every night and weekend, and they believe this means the VM costs nothing when stopped. Name two charges that still apply while it is stopped, and say what you would do if the database is no longer needed.
Show answer
The 100 GB disk is still billed per GB-month because the data is retained. Any attached extras also keep billing, for example a reserved public IP address or snapshots of the disk. If the database is no longer needed, delete the VM, the disk, the snapshots, and the IP address, after backing up any data you want to keep. Stopping only pauses the compute meter.
Exercise
A SaaS tool costs $12 per user per month for 40 users, of whom 8 have not logged in for six months. Meanwhile, a batch job that can safely be restarted runs for 200 hours a month on IaaS. Which pricing change would you consider for each?
Show answer
For the SaaS tool, remove or reassign the 8 inactive seats, which saves 8 x $12 = $96 per month, because subscriptions bill per seat whether or not it is used. For the batch job, consider spot or preemptible capacity, since the job tolerates interruption and spot pricing is much cheaper than on-demand. A long commitment is a poor fit here, because the job runs only 200 hours a month, not around the clock.