dissected.io
Lesson 7 of 23
Beginnerfundamentalsbillingcost-optimizationfinopsawsgcpazure10 min read

Billing and Cost Management

Your cloud bill is a direct reflection of your architecture decisions. Every time you provision a resource, pick a region, choose a storage class, or skip setting up autoscaling, you're making a cost decision. Cloud gets expensive not because the unit prices are unreasonable, but because there's no friction to provision and no friction to forget. In a datacenter, you ran out of rack space. In the cloud, you run out of budget.

Cloud Billing — Where the Real Costs Hide

Architecture

EC2
$120/mo
S3
$15/mo
Data Transfer
$280/mo
NAT Gateway
$180/mo

Traffic

0%

AWS requires upfront Reserved Instance or Savings Plan commitment

Main Cost Drivers

Most cloud bills break down into a predictable set of categories.

Compute hours: VMs, containers, and serverless functions billed by the second or invocation. This is typically the largest line item. An m5.xlarge running 24/7 costs roughly $140/month on-demand. Leave 10 of them running in a forgotten dev environment and that's $1,400/month.

Storage: billed by GB/month. Cheap per unit, but it only grows. Nobody deletes data, and without lifecycle policies, you're paying hot-tier prices for data nobody has accessed in years.

Egress (data transfer out): the hidden cost driver. Ingress is free. Transfer between services in the same AZ is free or cheap. But transferring data out to the internet or to another provider costs $0.08-0.12/GB. A service that pushes 10 TB/month to users costs $800-1,200/month in egress alone.

Requests and operations: S3 GET/PUT requests, API Gateway invocations, DNS queries, KMS API calls. Individually trivial, but at scale they add up. A service making 100 million S3 GET requests per month is paying $40 just for the requests, separate from storage.

Managed service premiums: RDS costs more than EC2 + self-managed Postgres. Managed Kafka costs more than running Kafka on VMs. You're paying for operational convenience.

Idle resources: the most wasteful category. Dev/staging environments running 24/7 when they're only used during business hours. Load balancers with no targets. Unattached EBS volumes. Elastic IPs not associated with instances ($3.65/month each since early 2024). Orphaned snapshots accumulating daily.

Pricing Levers

On-demand: pay as you go, no commitment. The most expensive per-unit rate but maximum flexibility. Use it for variable workloads and short-lived environments.

Reserved / Committed Use: commit to 1-3 years of compute for 30-60% off. AWS has Reserved Instances (specific instance type) and Savings Plans (flexible across instance families). GCP has Committed Use Discounts plus automatic Sustained Use Discounts (you get a discount just for running something more than 25% of the month). Azure has Reservations. The risk: if your workload changes, you're locked in.

Spot / Preemptible: use spare capacity for 60-90% off. The provider can reclaim the instance with short notice. Perfect for batch processing, CI/CD workers, and stateless services behind autoscaling groups. Not for databases or anything stateful.

Rightsizing

Most instances are over-provisioned. Teams pick a size during initial deployment, the workload runs fine, and nobody revisits the decision. Six months later, that m5.2xlarge averaging 12% CPU utilization could be a m5.large at one-quarter the cost.

All three providers offer rightsizing recommendations: AWS Compute Optimizer, GCP VM rightsizing recommendations, Azure Advisor. These tools analyze historical utilization and suggest smaller or different instance types. Make rightsizing a monthly or quarterly review.

Autoscaling and Scale-to-Zero

Autoscaling matches capacity to demand. Instead of provisioning for peak and paying for idle capacity during off-peak, you let the system add and remove instances based on metrics. This requires your application to be stateless and horizontally scalable.

Scale-to-zero is the ultimate cost optimization: when there's no traffic, you pay nothing. Serverless services (Lambda, Cloud Run, Azure Functions) do this by default. AWS Fargate with Application Auto Scaling and Aurora Serverless v2 can also scale to near-zero. If your workload is bursty with long idle periods, scale-to-zero architectures can reduce costs by 80%+.

Tagging and Labeling Discipline

You cannot optimize what you cannot attribute. Tags (AWS, Azure) and labels (GCP) let you annotate resources with metadata: team, environment, project, cost center. Without them, your bill is one giant number and nobody knows who's responsible for what.

Enforce tagging through policy: AWS Organizations SCPs can deny resource creation without required tags. GCP Organization Policies can enforce labels. Azure Policy can require tags at the resource group or resource level. Start with three mandatory tags: team, environment, and project.

Budgets, Alerts, and Anomaly Detection

Set budgets and alerts before you need them, not after the surprise bill arrives.

AWS: Budgets lets you set monthly spend thresholds with email/SNS alerts. Cost Anomaly Detection uses ML to flag unusual spending patterns. GCP: Budget alerts notify via email or Pub/Sub (which can trigger Cloud Functions to shut down resources). Azure: Cost Management + Billing has budgets with action groups that can trigger automation.

A reasonable starting point: set a budget alert at 50%, 80%, and 100% of expected monthly spend. Set an anomaly detection alert for any day-over-day increase exceeding 20%.

AWS Implementation

Cost Explorer is the primary analysis tool — filter and group spend by service, account, region, tag, or instance type. View trends over 12 months. AWS Budgets sets thresholds and alerts. Cost and Usage Report (CUR) is the raw, line-item billing data dumped to S3 for analysis in Athena or QuickSight. For organizations, AWS Organizations consolidated billing aggregates spend across accounts and applies volume discounts.

GCP Implementation

Billing Reports in the Cloud Console visualize spend by project, service, and SKU. BigQuery export sends detailed billing data to BigQuery for custom analysis — this is GCP's equivalent of AWS CUR and is more analyst-friendly. Recommender provides actionable suggestions for idle resources and rightsizing.

Azure Implementation

Cost Management + Billing is built into the Azure portal with cost analysis, budgets, and advisor recommendations. Azure Advisor provides rightsizing and shutdown recommendations. For enterprises, Management Groups and EA (Enterprise Agreement) portal provide hierarchical cost views.

Side-by-Side Comparison

AspectAWSGCPAzure
Cost dashboardCost ExplorerBilling ReportsCost Management
Raw data exportCUR (to S3/Athena)BigQuery exportUsage Details API / export
BudgetsAWS BudgetsBudget alerts + Pub/SubBudgets with action groups
Anomaly detectionCost Anomaly DetectionBudget alerts (threshold-based)Anomaly alerts (preview)
RightsizingCompute OptimizerRecommenderAzure Advisor
Commitment discountsReserved Instances, Savings PlansCUDs, Sustained Use DiscountsReservations
Auto-discountNoneSustained Use Discounts (automatic)None

FinOps as a Practice

FinOps (Financial Operations) is the discipline of managing cloud costs as a shared responsibility between engineering, finance, and business. The core insight: engineers make spending decisions every time they write infrastructure code, so cost awareness needs to be part of engineering culture, not a quarterly finance review.

Practical FinOps: include estimated monthly cost in pull request descriptions for infrastructure changes. Show teams their spend weekly. Make cost dashboards visible. Celebrate cost reductions the same way you celebrate feature launches.

Classic Surprise Bills

Unbounded egress: a popular open-source project hosting binaries on S3 without a CDN. Downloads spike, egress bill hits $10,000.

Forgotten GPU instance: someone spins up a p3.8xlarge ($12.24/hour) for ML training on Friday, leaves for the weekend. Monday morning: $880.

NAT Gateway charges: AWS NAT Gateway charges $0.045/GB processed. A chatty microservice architecture routing all outbound traffic through a NAT Gateway can generate thousands per month in data processing fees alone.

Runaway agent loop: a monitoring agent, log shipper, or recursive Lambda trigger goes haywire and generates millions of API calls or invocations in hours.

Free tier expiry: AWS and Azure free tiers expire after 12 months. GCP's $300 credit expires after 90 days. Services that were free start billing at full price with no warning besides the original signup terms.

Key Takeaways

  • Cloud bills are a design outcome — every architecture decision is a cost decision, and there's no friction to provision or to forget
  • The biggest cost levers are rightsizing over-provisioned instances, eliminating idle resources, and using commitment discounts for predictable workloads
  • Tagging discipline is non-negotiable; without it, you cannot attribute costs and nobody takes ownership of spend
  • Set budget alerts at 50%, 80%, and 100% of expected spend before you need them, not after the surprise bill
  • Egress, NAT Gateway data processing, and forgotten GPU instances are the classic sources of surprise bills
  • FinOps makes cost a first-class engineering concern — include estimated cost in infrastructure PRs and make spend dashboards visible to teams

This wraps up the cloud fundamentals. You now have the mental model for how cloud computing works, where your resources physically live, and how compute, storage, databases, identity, and billing fit together.

Enjoyed this breakdown?

Get new lessons in your inbox.