Cloud Cost Optimization

12 min read Β· Updated 2026-09-30

Most cloud overspend is not a mysterious tax. It is oversized instances, idle resources, chatty cross-AZ traffic, and a managed service you picked because it was easy. Cost optimization is an architecture skill: the same trade-offs as reliability and latency, with a monthly bill attached.

Three Places the Money Goes

Application efficiency
Heap, threads, connection pools, and startup cost. Waste here forces you to buy bigger instances than the workload needs.
Data and storage
Disk class, replicas, snapshots, and lifecycle. Data is often the largest line and the one nobody revisits.
Service selection
Managed vs. self-run, spot vs. on-demand, Lambda vs. containers. The architecture choice is the price.

Application-Level Rightsizing

A single-threaded service on a large multi-core instance is a common shape: you pay for CPU you never schedule. The same pattern shows up as oversized heaps, default connection pools, and frameworks that allocate everything at startup.

JVM and heap
G1GC is the default. Cap pause time (MaxGCPauseMillis) so GC spikes do not look like load and trigger scale-out. Size the heap from observed usage, not from a nervous default β€” many Spring Boot services run fine on a fraction of the heap they were given. Smaller G1 regions (8–16 MB) suit 1–2 GB microservice heaps better than the default.
Startup and idle work
Lazy bean initialization defers work until first use and can cut startup memory roughly in half. GraalVM native images trade build complexity for fast cold start and a smaller footprint β€” the right trade when you pay per start, as in serverless.
Connection pools
Oversized pools time out the database, which tempts an instance upgrade, which allows an even bigger pool. Most apps need on the order of 5–15 connections. Measure concurrent queries for a week before you buy more database.
Profile in production
One bad query can be the compute budget. Continuous profiling belongs in the pipeline, not in the incident. The same idea holds outside Java: async runtimes, leak hunting, and container-aware CPU limits.

Data and Storage

Disk class and database shape

gp2
Burst credits you may not need
Still the RDS default in many consoles. You pay for a baseline whether you use the burst or not.
gp3
Cheaper, and you set IOPS
Often about 20% cheaper with independent IOPS and throughput. Existing volumes can switch with no downtime. This is the first dropdown to change.

Multi-AZ roughly doubles the database bill. That is the right insurance for the primary that serves customer traffic. It is a poor default for an analytics database queried twice a week β€” snapshots and a short restore window are cheaper. Read replicas that scale out and never scale in are the same mistake in another costume. Aurora Serverless v2 (and equivalents) scale both directions; a fixed replica fleet does not.

Lifecycle, or storage that quietly compounds

Step 01
Tier by access
S3 Intelligent-Tiering moves untouched objects to cheaper classes for a small monitoring fee. Typical savings are large relative to that fee. A hand-written lifecycle (Standard, then Infrequent Access, then Glacier, then Deep Archive) works when you know the access curve.
Step 02
Expire snapshots and logs
EBS snapshots and old application logs accumulate forever unless a policy says otherwise. A common retention shape: daily for a week, weekly for a month, monthly for a year. Logs from six months ago do not belong in Standard.
Step 03
Prefer object storage
S3 wins for backups, logs, static assets, and lakes. EBS when one instance needs low-latency block storage. EFS only when many instances truly need a shared filesystem β€” it costs several times EBS.

The network line items people miss

Cross-AZ traffic is about a cent per GB. Health checks and chatty service discovery between zones add up. Keep a service and its database in the same AZ when the availability requirement allows it, and pay the cross-AZ tax only for the tier that actually needs multi-AZ.

NAT Gateway charges per GB on top of an hourly fee. A VPC gateway endpoint to S3 or DynamoDB skips that path. Interface endpoints have their own hourly cost; they pay for themselves once data processing is heavy enough that NAT per-GB dominates (on the order of a terabyte a month).

Choosing the Service Is Choosing the Price

Spiky, short work
Serverless usually wins
Lambda (or a similar function) for irregular, short requests. You stop paying when you stop calling it. Steady high-QPS APIs flip the math: you pay for convenience you are not using.
Steady traffic
Containers usually win
A long-running container on reserved or savings-plan capacity beats per-invocation pricing once the load is smooth. Run the break-even on your own traffic shape, not a blog post's.
Commit to the baseline
Savings Plans and Reserved Instances discount the part of the bill you can predict. Leave the spiky remainder on demand or on spot.
Spot where interruption is fine
Spot is no longer only for batch, but the workload has to survive being killed. Stateless workers and mixed node pools qualify. Databases and strict-SLA state do not. Design for interruption first.
Orchestrator tax
EKS and GKE charge for the control plane before you run a pod. A handful of services is often cheaper on ECS, or even Compose on one instance, than on managed Kubernetes.
Queues
SQS is the cheap default at low volume and gets expensive at high throughput. Self-managed RabbitMQ can win on price if you will operate it. Managed Kafka is the premium option for real event streams, not for a single work queue.

Batch processing has the same shape. EMR Serverless fits infrequent Spark jobs and pays for a cold start. EMR on EKS fits a cluster you already pay for. Self-managed Spark on EC2 is the lowest cost per job when the jobs are large, frequent, and you can staff the ops.

Kubernetes, Once You Are Already On It

Scale down on purpose
The default cluster autoscaler is shy about removing nodes. Short scale-down delays and a least-waste expander stop you paying for empty capacity. Karpenter-style provisioners are the same idea with fewer node-group knobs.
Pools that match the work
CPU-optimized for compute, memory-optimized for caches, burstable for low traffic, spot for anything that can die. One general-purpose pool for everything is how you buy the wrong shape twice.
Scale on the queue, not the CPU
KEDA (and similar) scales workers from queue depth, request rate, or lag. CPU is a lagging, often misleading signal for background jobs.
Rightsize pods from data
Vertical Pod Autoscaler in recommendation mode for a week, then apply. Requests copied from a tutorial are how clusters look full while doing little.
ARM where images allow it
Graviton-class instances are often 20–40% better on price for the same work. Java, Node, Python, and Go are fine. The blocker is an old native dependency without an ARM build β€” multi-arch images surface that early.

A Cost Review You Will Actually Hold

Step 01
What went up?
Planned growth, or a surprise? Name the service. Ignore the twelve-dollar CloudWatch blip while a database jumped by hundreds.
Step 02
What went down?
A real optimization, or traffic that disappeared? A cheaper bill is not automatically healthier.
Step 03
What is new?
New resource types that were not on last month's bill. Catch them before they become the baseline.

Start with the free tools: Cost Explorer, Budgets, Compute Optimizer, Trusted Advisor, kubectl top, and an open-source allocator such as Kubecost. Paid platforms (CloudHealth, Datadog Cloud Cost, Spot, Cloudability) earn their fee when you need multi-cloud chargeback or executive reporting β€” not on day one.

Recap