Cloud Fundamentals
Advanced 16 min read Cloud Fundamentals

Cloud Cost Optimization

Cloud waste is the most expensive bug you never test for. Learn right-sizing, reserved and savings plans, spot instances, lifecycle rules, cost allocation, and the FinOps practices that keep cloud bills predictable.

FinOpsright-sizingreserved instancessavings plansspot instancescost allocationtagswaste
Introduction

What is this?

Cloud cost optimization is the practice of paying only for the capacity you actually use. It covers right-sizing resources to real demand, committing to reserved capacity for steady loads, bidding on spot or evictable capacity for fault-tolerant work, tiering storage, and attributing spend to teams through tags. FinOps is the discipline — a culture of engineers, finance and product sharing cost visibility and accountability.

Motivation

Why do you need it?

  • Unused and oversized resources routinely account for 30–40% of cloud spend.
  • Cost is a system property: the same workload can be 60% cheaper or twice the price depending on purchasing choices.
  • Waste grows silently — an instance or bucket you forget keeps billing forever.
  • Cost allocation turns finance arguments into engineering decisions backed by data.
  • FinOps practices make cost a first-class metric like latency and error rate.
Think about it

Mental model

Imagine

Public transport vs owning a car

Think of

On-demand vs committed cloud pricing

Buying a bus ticket (on-demand) is flexible but expensive per trip. A monthly pass (reserved capacity) is much cheaper if you ride daily, but wasteful if you barely ride. A shared carpool (spot instances) is cheapest, but someone else owns the schedule. Choosing depends on your commute, not on which is 'best' in the abstract.

Mechanics

How it works

  • Metering records every resource-hour, GB stored and request, and billing aggregates it into a monthly invoice broken down by service and tags.
  • Right-sizing matches instance size to actual utilization: downsize idle VMs, scale to zero in dev, and use autoscaling for variable load.
  • Committed use discounts — Reserved Instances and Savings Plans — exchange a 1- or 3-year commitment for 20–60% off steady-state compute.
  • Spot instances offer large discounts (60–90%) on spare capacity, but the provider can reclaim them with short notice, so they fit stateless, retryable work.
  • Lifecycle rules and tiering move cold data to cheaper storage, and cost allocation tags let finance bill each team for exactly what it consumed.

The FinOps cost-optimization loop.

Meter usage
Allocate
Analyze
Optimize
Repeat
Informed decisions
Reference

Key commands

free -m

Check memory utilization to decide whether an instance is oversized.

df -h

Check disk utilization before resizing or deleting volumes.

date

Confirm time-of-day patterns — idle overnight hours are right-sizing candidates.

cat costs.csv | sort -t, -k2 -rn | head -5

Rank the top spenders in a comma-separated cost report.

grep -i "EC2" costs.csv

Filter a cost report down to one service family.

Hands-on

Examples

Find the biggest cost drivers in a spend report

Find the biggest cost drivers in a spend report
$ cat costs.csv
Service,MonthlyCost,Tags
AmazonEC2,4821.90,team=payments
AmazonS3,1234.56,team=media
AmazonEC2,320.10,team=analytics
AmazonRDS,2210.00,team=payments
$ sort -t, -k2 -rn costs.csv | head -4
Service,MonthlyCost,Tags
AmazonEC2,4821.90,team=payments
AmazonRDS,2210.00,team=payments
AmazonS3,1234.56,team=media
AmazonEC2,320.10,team=analytics

A tagged cost report is the starting point of every FinOps conversation. Sorting by monthly cost shows the payments team owns the two largest items (EC2 + RDS) — exactly the team to talk to about right-sizing and reserved capacity. Without tags, that attribution is impossible and the conversation becomes guesswork.

Real world

In production

  • Right-size after a month of real utilization data, not on the original guess.
  • Cover steady-state workloads with Savings Plans or Reserved Instances and keep only bursts on-demand.
  • Run batch, stateless and test workloads on spot or evictable capacity at 60–90% off.
  • Put logs and backups on lifecycle rules so they age into archive tiers automatically.
Guidelines

Best practices

  • Tag everything at creation, and enforce it with a policy or CI check.
  • Set budgets and alert on anomalies before the invoice surprises you.
  • Prefer reserved capacity for stable, always-on workloads; on-demand for elastic and unknown demand.
  • Run a monthly waste review: stop idle instances, delete orphaned volumes and stale snapshots.
  • Treat cost as a metric in your dashboards, next to latency and error rate.
Watch out

Common mistakes

  • Buying reserved capacity for workloads that are small or likely to change — the commitment becomes waste.
  • Leaving dev and test environments running 24/7 when they are used for 8 hours a day.
  • Ignoring egress and request costs, which can exceed compute for data-heavy services.
  • Optimizing spend without a tag strategy, so nobody can see what anything actually costs.
Root cause analysis

Common issues

Error
Bill doubled but nothing obvious changed
Root cause

A resource was left running — often a test cluster, orphaned volume or abandoned data transfer job.

Fix

Sort the month-over-month report, drill to the top new line item, and terminate the resource.

Error
Reserved capacity shows unused hours
Root cause

The workload shrank or changed instance family after the commitment was purchased.

Fix

Exchange or modify the reservation, or right-size the remaining on-demand usage to match.

Error
Spot instances terminated mid-job
Root cause

The provider reclaimed capacity because demand or price exceeded the bid.

Fix

Design for interruption: checkpoint progress, retry from the last checkpoint, and fall back to on-demand.

When things break

Debugging tips

  • Sort your cost report before blaming any single service — one line-item usually explains the spike.
  • Cross-check an anomaly against deployment events: a new autoscaling max or larger instance type is a common culprit.
  • Look at per-service breakdowns, then per-tag, then per-resource to drill into waste.
  • Use the provider's cost anomaly detection instead of reviewing the bill manually every month.
Interviews

Interview checkpoint

Practice

Hands-on lab

Analyze a Cost Report and Right-Size
30 min · advanced
In progress
Objectives
  • Build a realistic tagged cost report
  • Rank the top spenders by service and team
  • Identify right-sizing candidates from utilization data
  • Practice the drill-down a FinOps review would do

Analyze a Cost Report and Right-Size

30 min · advanced

0/6 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/3
1

Which purchasing model saves the most money but can be reclaimed by the provider?

2

What does a Savings Plan commit you to?

3

Cost allocation tags let you attribute cloud spend to teams and projects.

Quick reference

Cheat sheet

The lever set
Right-sizeMatch instance size to real utilization
Savings Plans / RIs20–60% off steady-state compute
Spot60–90% off interruptible workloads
Lifecycle tiersAge logs and backups into archive
Scale to zeroDev/test off outside hours
Inspect from the shell
free -mMemory utilization for right-sizing
df -hDisk utilization and orphaned volumes
sort -t, -k2 -rn costs.csvRank top spenders by column 2
grep -i "EC2" costs.csvFilter a cost report by service
Go deeper

Official documentation