Skip to content
Back to Blog
Linux & Server11 min read

Cloud Infrastructure Cost Optimization: 9 Ways to Cut Waste

Instance rightsizing, spot-instance strategies, and storage-tier automation can reduce monthly cloud bills by 30-60% without sacrificing uptime.

Written by Abdul AbrorTechnical Hosting Support Engineer
Cloud Infrastructure Cost Optimization: 9 Ways to Cut Waste
On this page

Your cloud bill climbed again last month, and you're running the same workloads. That's the pattern I see in support tickets — teams spinning up resources during a launch sprint, then forgetting they exist. A staging environment that costs $800/month but gets used twice a quarter. An RDS instance sized for Black Friday traffic running at 12% CPU in July.

The fixes aren't complicated. Most cloud waste comes from three places: instances sized for peak load running 24/7, storage sitting in expensive tiers when it's rarely accessed, and reserved capacity purchased before anyone measured actual usage patterns.

Start with instance rightsizing

Your compute instances are probably too big. Not all of them, but enough that rightsizing saves 20-40% on EC2 or Compute Engine bills without changing a single line of code.

Pull a 30-day CPU and memory report for every instance. Your cloud provider's console has this built in — AWS CloudWatch, Azure Monitor, GCP's operations suite. Look for instances that never break 30% CPU or 50% memory. Those are your candidates.

Don't resize blindly. Check the instance type family first. An older generation m4.xlarge might cost the same as a current-gen m6i.large with better performance. The newer chip runs your workload at 60% CPU instead of 25%, and you've cut the monthly cost in half.

For production web servers, I usually see the best results moving from general-purpose to compute-optimized families when the workload is CPU-bound, or memory-optimized when you're running databases or caching layers. A c6i.large costs less than an m5.xlarge and often performs better for API servers that aren't memory-heavy.

Test on a single instance first. Resize during your maintenance window, monitor for 48 hours, then roll it out to the fleet. Keep your old instance stopped (not terminated) for a week in case you need to revert.

Automate instance scheduling

Development and staging environments don't need to run nights and weekends. Stopping them Friday at 6 PM and starting Monday at 7 AM cuts 128 hours off a 168-hour week — that's 76% savings right there.

Write a simple Lambda function (or Cloud Function, or Azure Automation runbook) triggered by EventBridge on a cron schedule. Tag your non-production instances with AutoStop: true, and the function shuts them down at the configured time. Start them back up when your team arrives.

# Example: stop all instances tagged AutoStop=true
aws ec2 describe-instances \
  --filters "Name=tag:AutoStop,Values=true" \
  --query "Reservations[].Instances[].InstanceId" \
  --output text | xargs aws ec2 stop-instances --instance-ids

For databases, take snapshots before the first stop if your test data matters. RDS and Cloud SQL both support automated snapshots, so schedule those for Friday afternoon before the shutdown window.

Some teams worry about cold-start delays Monday morning. Fine — start instances 30 minutes before anyone logs in. The cost difference between 76% savings and 73% savings is negligible, and your developers won't wait for boot.

Use spot instances where failure is acceptable

Spot instances (or preemptible VMs, depending on your provider) cost 60-80% less than on-demand pricing. The tradeoff: your cloud provider can reclaim them with 30 seconds to two minutes of notice.

That makes them perfect for batch jobs, CI/CD runners, and stateless web workers behind a load balancer. I've run WordPress cron jobs on spot instances for years — if one dies mid-job, the next cron cycle picks it up.

Set up a mixed instance fleet: 50% on-demand for baseline capacity, 50% spot for burst traffic. When spot instances disappear, your on-demand nodes handle the load until spot capacity returns. Most load balancers drain connections gracefully when you configure health checks properly.

# Auto Scaling group with mixed instances (simplified)
MixedInstancesPolicy:
  InstancesDistribution:
    OnDemandBaseCapacity: 2
    OnDemandPercentageAboveBaseCapacity: 50
    SpotAllocationStrategy: capacity-optimized
  LaunchTemplate:
    Overrides:
      - InstanceType: m6i.large
      - InstanceType: m5.large
      - InstanceType: m5a.large

For CI runners, spot works even better because build jobs are inherently retryable. GitHub Actions, GitLab CI, and Jenkins all support spot-backed runners. A failed build restarts automatically on the next available node.

Avoid spot for databases, stateful services, or anything that can't tolerate sudden termination. The cost savings aren't worth the complexity of managing state across interruptions.

Move cold storage to cheaper tiers

Object storage has multiple pricing tiers, and most files sit in the expensive tier long after anyone stopped accessing them. S3 Standard costs 10x more than Glacier Instant Retrieval for data you touch once a quarter.

Set up lifecycle policies that transition objects automatically. Move anything untouched for 90 days to Infrequent Access, then to Glacier after six months. For logs and backups you keep for compliance but never read, use Deep Archive.

{
  "Rules": [
    {
      "Id": "MoveOldLogs",
      "Status": "Enabled",
      "Transitions": [
        {
          "Days": 90,
          "StorageClass": "STANDARD_IA"
        },
        {
          "Days": 180,
          "StorageClass": "GLACIER_IR"
        }
      ]
    }
  ]
}

Check your CloudFront or CDN logs first — those pile up fast. A site serving 50 GB/day of traffic generates 1.5 TB of logs per month if you're storing every request. Archive them after 30 days unless you're actively analyzing older data.

Database snapshots are another common culprit. You probably don't need daily snapshots kept for 90 days. Weekly snapshots work fine after the first month, and monthly after quarter one.

Delete unattached volumes and orphaned snapshots

Every terminated instance leaves behind its EBS volumes unless you specifically set DeleteOnTermination: true. Over six months, those add up — I've seen accounts with 40 TB of unattached storage costing $4,000/month for data nobody remembered existed.

Run this monthly:

# Find unattached EBS volumes
aws ec2 describe-volumes \
  --filters Name=status,Values=available \
  --query "Volumes[].{ID:VolumeId,Size:Size,Created:CreateTime}" \
  --output table

Before you delete anything, check the creation date and size. A 500 GB volume created last week might be your DBA's new database build. A 20 GB volume from 2024? Almost certainly forgotten.

Snapshots are worse because they're invisible in your instance list. Check for snapshots older than your retention policy, especially AMI snapshots from instances you've long since replaced. Each AMI includes snapshots of all attached volumes, and those stick around even after you deregister the AMI.

Buy reserved instances for stable workloads

If you've rightsized your production fleet and it's been stable for three months, buy reserved capacity. One-year reservations typically save 30-40% over on-demand; three-year commitments can hit 60%.

Start with your database tier. RDS instances rarely change size once you've found the right fit, so a one-year reservation is low-risk. Same for ElastiCache nodes and other managed services that run 24/7.

For compute, buy reservations that cover your baseline — the minimum capacity you need even during slow periods. Handle traffic spikes with on-demand or spot instances. That way you're not stuck paying for reserved capacity you don't use.

Most cloud providers let you modify reservations if your needs change. You can split a large reservation into smaller ones, or exchange instance families within the same region. Read your provider's docs on reservation flexibility before buying.

Rightsize your database instances separately

Databases need different optimization than application servers. CPU and memory matter, but IOPS and storage throughput often matter more.

Check your database's disk I/O metrics over a two-week period. If your provisioned IOPS sit at 15% utilization, you're paying for performance you're not using. Drop from 10,000 IOPS to 3,000 and pocket the difference.

For read-heavy workloads, add read replicas instead of vertically scaling your primary. A read replica on a smaller instance type costs less than upsizing the primary, and it scales horizontally when traffic grows.

Storage autoscaling helps when growth is unpredictable, but it's not free. AWS charges for the maximum allocated space, not what you're using today. If your 500 GB database autoscaled to 800 GB during a data import, you're paying for 800 GB until you manually shrink it.

Set up cost anomaly alerts

You won't catch runaway spend if you only look at the bill after it arrives. Enable cost anomaly detection in your cloud console and set a daily threshold — if spending jumps 20% day-over-day, you want to know before Friday's invoice.

Tag everything. Seriously. Tag by environment (prod, staging, dev), by team, by cost center, by project. When an alert fires, you'll know exactly which service caused the spike and who to ask about it.

# Tag instances consistently
aws ec2 create-tags \
  --resources i-1234567890abcdef0 \
  --tags Key=Environment,Value=production \
         Key=Team,Value=platform \
         Key=CostCenter,Value=engineering

Cost allocation reports let you break down spending by tag. That's how you discover that the analytics team's Spark cluster costs more than your entire production web tier, or that staging is somehow 40% of your compute spend.

Compress and deduplicate backups

Backups accumulate silently. Daily database backups, EBS snapshots, application state archives — they all cost money to store, and incremental snapshots aren't as efficient as you'd think when the data changes frequently.

Enable compression on database dumps before uploading them to object storage. A 50 GB PostgreSQL dump often compresses to 8-12 GB, which matters when you're storing 30 days of dailies.

# Compress before uploading
pg_dump mydb | gzip -9 > backup-$(date +%F).sql.gz
aws s3 cp backup-$(date +%F).sql.gz s3://my-backup-bucket/

For EBS snapshots, switch to AMI creation only when you need a full system image. Block-level snapshots are cheaper for data volumes that change often, because they only store the changed blocks.

Consider a third-party backup tool if your native cloud snapshots are costing more than they should. Some tools deduplicate across snapshots and compress more aggressively than the default provider implementations.

What's the fastest win?

Schedule shutdowns for dev and staging environments. You'll see savings in the next bill cycle, and it takes an hour to set up.

Do spot instances really save that much?

Yes, but only if you architect for interruptions. A batch job that retries on failure? Perfect. A database with five-minute checkpoint intervals? Don't risk it.

How often should I review instance sizes?

Quarterly for production, monthly for everything else. Usage patterns shift as features launch and traffic grows.

Will lifecycle policies break my application?

Not if you test your data access patterns first. Move a small bucket to IA, monitor for retrieval errors, then roll out the policy fleet-wide.

Start with the three biggest line items

Open your cloud bill and sort by cost. The top three services are where you'll find the most waste.

For most hosting workloads, that's compute instances, database services, and storage. Rightsize the instances, schedule the non-production ones, and tier the storage. Do those three things this month and your next bill drops 25-40%.

The tactics here aren't theoretical — they're what I walk through when a client asks why their infrastructure costs doubled in six months. Check your metrics, resize what's oversized, automate what's manual, and delete what's orphaned. Then set up alerts so it doesn't happen again.