Cloud Cost Optimization: FinOps, Rightsizing, Spot, Autoscaling, Data Transfer, and Observability Costs
Fast recall
Quick revision
Core answer
-XX:MaxRAMPercentage), GraalVM native image for FaaS to cut memory and cold-start, HikariCP right-sized to DB limits. Anti-patterns: kubectl apply with no resource requests/limits; on-demand everywhere; Lambda for sustained high-RPS workloads; 90-day CloudWatch log retention on DEBUG logs; over-provisioned Postgres with idle replicas. The discipline: measurable targets per service (cost/request, cost/tenant, cost/feature), weekly waste reviews, and FinOps ownership embedded in engineering — not a separate team handing out scolding reports.Treating cost as finance's problem; focusing only on compute; ignoring data transfer and logs; no tagging
FinOps framework, tag strategy, Spot/Savings Plans concretely, observability cost, Java-specific tuning, per-team budgets
Interview-ready guide
Interview answer
Cost is an engineering metric. Systematic reduction follows FinOps — inform, optimize, operate.
Inform: visibility first
- Tagging strategy: team, service, environment, cost-center — enforce via policy
- Cost dashboards per team, per service, per request, per tenant, per feature
- Anomaly alerts, budget alerts at 50/80/100%
- CUR → Athena → dashboards; Kubecost or OpenCost for K8s attribution
Optimize: the biggest levers
Compute
- Rightsizing: 20–40% often overprovisioned; use p95 actual from 14 days
- Container ergonomics for Java: -XX:MaxRAMPercentage=75 so JVM respects cgroup
- Autoscale: K8s HPA, KEDA for event-driven, Karpenter for nodes, scale-to-zero where possible
- Spot/Preemptible: up to 70% off for fault-tolerant workloads
- Savings Plans / Reserved: 30–60% off steady baseline, cover ~70% of floor
- Non-prod off-hours shutdown: 60%+ savings
- Java specifics: ZGC/Shenandoah for large heap, GraalVM native image for FaaS
- HikariCP sized near DB max
- AppCDS for faster container startup
Storage
- S3 Intelligent-Tiering by default
- Lifecycle rules: Standard → IA → Glacier → Deep Archive
- Delete unattached EBS, old snapshots, incomplete multipart uploads
- gp3 over gp2
- CDN for hot content
- Compression (zstd, gzip), Parquet for analytics
Data transfer
- Same-AZ free; inter-AZ $0.01–0.02/GB; NAT Gateway $0.045/GB
- VPC Endpoints for AWS services — avoid NAT
- Co-locate chatty services in same AZ
- Cross-region expensive — architect region-locality
- Internet egress: CDN, compression, HTTP/2 + HTTP/3
Databases
- Rightsize RDS/Aurora to actual CPU and connections
- Aurora I/O-Optimized for I/O-heavy
- Aurora Serverless v2 for variable
- Reserved DB instances for steady
- Stop non-prod nights/weekends
- Archive cold data to S3; don't keep 5 years in Postgres
Observability (often top-3 cost)
- Log levels: INFO in prod, DEBUG where needed
- Retention: 7–14 days hot, archive to S3
- Sampling: 1–10% traces + 100% errors; logs sampled at high volume
- Metric cardinality: avoid userId/requestId labels
- Audit custom metrics quarterly
Operate: governance
- Budgets per team with alerts
- Weekly waste review: idle, oversized, anomalies, assign owners, close loop
- Policy as code: OPA/Gatekeeper/Kyverno block oversize, missing tags
- AWS Service Control Policies to block expensive regions/instances
- FinOps role: platform team handles rates and tooling; product teams own usage
Concrete savings targets
- Rightsizing: 20–40% of compute
- Spot + Savings Plans: 30–70% on committed
- S3 lifecycle + Intelligent-Tiering: 30–50% storage
- Log/metric tuning: 40–70% of observability
- NAT/VPC endpoints: 20–50% of AWS-service traffic
- Non-prod off-hours: 50–70% on non-prod
Anti-patterns
- kubectl apply without resource requests/limits
- On-demand everywhere
- DEBUG logs + 90-day retention
- High-cardinality metrics
- Unattached EBS, old snapshots, orphaned ELBs
- NAT egress for AWS services
- Inter-AZ chatter without reason
- No tagging
- Lambda for steady high-RPS
- Java default -Xmx in container
- Forgotten 90-day preview envs
- Over-provisioned RDS read replicas
Trade-offs
- Spot saves 70% but interrupts — pair with on-demand baseline
- Scale-to-zero saves $$ but adds cold-start
- Fewer replicas — cost vs SLO
- Centralized vs team ownership — hybrid; platform rates, teams usage
- Savings plan commitment: 70% of baseline, re-evaluate quarterly
- Engineering time is a cost — prioritize high-leverage first
Senior behaviors
- Own cost as SLI; report; reduce
- Tag everything from day one with policy enforcement
- Model cost per request, per tenant, per feature
- Weekly waste review as team ritual
- Automate: right-sizer scripts, alerts, scheduled shutdown
- Architecture decisions include cost trade-off
- Prioritize big levers; don't chase pennies
- Never break SLOs to save $; monitor both
- Teach team: share dashboards, celebrate savings, normalize conversation
Interview emphasis
- Lead with FinOps framework
- Name specific levers with magnitude estimates
- Don't forget observability and data transfer
- Java-specific: container ergonomics, SnapStart/native, HikariCP
- Tagging and governance, not just one-off cuts
- SLO protection — cost cuts that break availability are not wins
Bottom line
- Systematic 30–40% reduction is routinely achievable without SLO impact
- Compute rightsizing + Spot/Savings Plans + observability tuning + data transfer fixes + storage lifecycle = the main $$
- FinOps embedded in engineering makes this sustainable — not a one-shot cut
Cloud Cost Optimization: FinOps, Rightsizing, Spot, Autoscaling, Data Transfer, and Observability Costs
Direct Answer
Cost is an engineering metric, not a finance problem. Systematic reduction follows FinOps: visibility (tagging, per-service cost attribution, cost dashboards), optimization (rightsize, autoscale, spot/preemptible, reserved instances + savings plans, storage tiering, data-transfer redesign), and governance (cost alerts, budgets per team, waste reviews). The biggest levers are usually: compute rightsizing (often 2–4× overprovisioned), autoscaling (set min/max with real HPA or KEDA signals), Spot/Savings Plans (up to 70% off compute for fault-tolerant workloads), storage lifecycle (S3 Intelligent-Tiering, Glacier for cold), data transfer (inter-AZ, NAT egress, logging), and observability (logs ingestion is often the top-3 cost line; tune retention and sampling). Java-specific: container ergonomics (-XX:MaxRAMPercentage), GraalVM native image for FaaS to cut memory and cold-start, HikariCP right-sized to DB limits. Anti-patterns: kubectl apply with no resource requests/limits; on-demand everywhere; Lambda for sustained high-RPS workloads; 90-day CloudWatch log retention on DEBUG logs; over-provisioned Postgres with idle replicas. The discipline: measurable targets per service (cost/request, cost/tenant, cost/feature), weekly waste reviews, and FinOps ownership embedded in engineering — not a separate team handing out scolding reports.
Common Mistakes & Pitfalls
Treating cost as finance's problem; focusing only on compute; ignoring data transfer and logs; no tagging
Check your understanding
Answer these without looking back at the article.
- How would you decide between Reserved Instances and Savings Plans for your team?
- Walk me through how you'd cut your CloudWatch Logs bill in half this month.
- How do you enforce tagging at the organization level without annoying engineers?
- When is scale-to-zero actively harmful, and how do you decide?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.