Quick revision
The short answer
I would start with visibility, tagging every resource by service and team and showing cost per service and per request so teams own their numbers, and then pull the big levers in order of effort: right-size JVMs and containers from real metrics and scale on load, move suitable workloads to Graviton with multi-architecture images, cover the steady base with Savings Plans and run tolerant batch work on Spot, and use runtime choices such as newer JDKs, CDS and AOT caches or native images where they pay off. Governance over several years means budgets and alerts per team, regular cost reviews, and engineering time set aside for efficiency rather than one-off cleanups.
What to remember
In this answer, we built a cost plan for Java compute that starts with visibility, tags, cost per service and cost per request owned by teams, and then pulls right-sizing and load-based scaling, Graviton with multi-architecture images, Savings Plans for the steady base and Spot for tolerant batch work, and runtime choices such as newer JDKs, startup caches and native images. Governance over years comes from budgets, regular reviews, cost estimates in design reviews and protected engineering time for efficiency.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would start with visibility, tagging every resource by service and team and showing cost per service and per request so teams own their numbers, and then pull the big levers in order of effort: right-size JVMs and containers from real metrics and scale on load, move suitable workloads to Graviton with multi-architecture images, cover the steady base with Savings Plans and run tolerant batch work on Spot, and use runtime choices such as newer JDKs, CDS and AOT caches or native images where they pay off. Governance over several years means budgets and alerts per team, regular cost reviews, and engineering time set aside for efficiency rather than one-off cleanups.
Why this question is asked
A bill that grows 40 percent a year doubles in about two years, and when the CFO asks for a plan, they want two things: a credible reduction now, and confidence that it will not happen again. Java workloads are a good place to look, because JVMs are often over-provisioned out of caution and because the platform keeps improving. Interviewers ask this at the senior leadership level to see whether we can combine technical levers with financial ones and build a lasting operating model. In this answer, we will build the visibility first, then go through right-sizing, Graviton, commitments and runtime choices with rough numbers, and finish with how to govern cost year after year.
1Visibility First: Cost per Service and per Request
We cannot manage what nobody owns. The first step is a tagging standard, with service, team and environment on every resource, enforced through infrastructure-as-code modules and tag policies, and activated as cost allocation tags. For shared clusters, AWS can split ECS and EKS costs by task or pod, so shared nodes are attributed to the services that use them. With that, a monthly report shows cost per service and per team.
The most useful number is cost per unit of business, such as cost per thousand requests or per order. Total cost grows with traffic, which may be good news; cost per request growing is the real warning. Each team sees its own numbers on a dashboard next to its latency and error rate, so cost becomes one of the things they own, not a surprise from finance.
- Tag every resourceservice, team, environment
- Split shared cluster costby task or pod usage
- Monthly cost per servicefrom Cost and Usage Report
- Divide by request countfrom service metrics
- Cost per request rising?YesTeam investigates in its reviewNoTrack the trend
5 steps in order. Play them, or step through them one at a time.
2Right-Sizing JVMs and Containers
Right-sizing is usually the largest and safest lever. Many Java services request far more than they use: a task with 4 vCPU and 8 GB that peaks at 20 percent CPU and a 1.5 GB heap. Teams over-provision because a JVM that runs out of memory fails loudly, and nobody gets credit for shrinking. We use real metrics, CPU and memory at the 95th percentile over several weeks, GC behaviour and heap after collection, to propose new sizes, set the heap with MaxRAMPercentage so it follows the container size, and test under load before changing production.
Then we scale on load instead of running a fixed count sized for the peak. A service that needs 12 tasks at noon and 3 at night saves more than half its compute with target tracking on CPU or requests per target. Together, right-sizing and autoscaling often cut compute for a service by 30 to 50 percent.
| Setting | Before | After |
|---|---|---|
| Task size | 4 vCPU, 8 GB | 2 vCPU, 4 GB |
| Count | 12 fixed | 3 to 12, scaled on load |
| Average tasks running | 12 | about 6 |
| p95 CPU per task | 20 percent | about 55 percent |
| Compute cost | 100 percent | about 25 percent |
3Graviton, Commitments and Spot
Graviton, AWS's ARM-based processors, often gives better price-performance for Java: instances cost less per hour than comparable x86 ones, and many JVM workloads run as fast or faster. AWS quotes up to about 40 percent better price-performance; we measure our own. Pure Java code runs unchanged because the JVM is portable. The work is building multi-architecture images, which buildpacks and docker buildx support, and checking dependencies with native code, such as compression, crypto or database drivers with JNI parts, for ARM builds. We migrate a few services, compare latency and cost, and then make ARM the default for new services.
Commitments reduce the price of what we will run anyway. Savings Plans give a lower rate in exchange for committing to a dollar amount of compute per hour for one or three years, and Compute Savings Plans also apply to Fargate and Lambda. We commit to the steady base, perhaps 60 to 70 percent of the current minimum usage, not the peak, and only after right-sizing, so we do not lock in waste. Spot capacity, spare EC2 capacity at a large discount that can be reclaimed with two minutes' notice, suits batch jobs and stateless workers that tolerate interruption.
4Runtime Choices
The JVM itself keeps getting cheaper to run. Newer JDKs bring better garbage collectors and lower memory overhead, so moving from Java 11 or 17 to 21 or 25 can reduce CPU and heap needs with no code change. Startup improvements, class data sharing and, since JDK 24, the AOT cache from Project Leyden, shorten startup, which matters for autoscaling: a service that starts in 10 seconds instead of 60 can run fewer spare tasks. For services that are idle most of the time, native images with GraalVM or a move to Lambda can scale to zero. Each of these has an engineering cost, so we use them where the numbers per service justify it, not everywhere.
5Governing Cost Over Several Years
One cleanup gives a one-off drop, and the bill grows again. Lasting control needs an operating model. Each team has a budget with alerts in AWS Budgets and sees its cost per request monthly. A quarterly review with engineering and finance looks at the top services, anomalies and commitment coverage. Architecture reviews for new services include a cost estimate. And we set aside engineering time for efficiency, for example a few percent of each team's capacity, because savings work always loses to features when it has no time of its own.
For the CFO, the plan has a shape: the first quarter brings visibility and quick wins, such as deleting idle resources and right-sizing the largest services; the next two quarters bring Graviton migrations and commitments for the new, smaller base; and from then on, cost per request is a tracked metric with a target, such as flat or falling while traffic grows.
| Period | Main actions | Expected effect |
|---|---|---|
| Quarter 1 | tagging, cost per service, idle cleanup, top 20 right-sized | first visible drop |
| Quarters 2 and 3 | Graviton migrations, autoscaling, Savings Plans on new base | largest savings |
| Year 2 onward | budgets, quarterly reviews, efficiency time, runtime upgrades | cost per request flat or falling |
6Follow-up questions
How would you measure cost per request for a service?
We take the service's monthly cost from the Cost and Usage Report filtered by its tags, including its share of shared clusters from split cost allocation and its own databases and queues, and divide by the number of requests it served, from its http.server.requests metric or load balancer request counts. For services whose unit is not a request, such as a batch job, we use records processed. The number is approximate, but the trend is what matters, and putting it next to latency on the team dashboard makes it part of normal engineering decisions.
Which lever would you pull first and why?
Visibility and right-sizing. They have no commitment risk, they often save the most, and they must come before Savings Plans, otherwise we commit to paying for capacity we later remove. Graviton follows, because it needs some engineering per service.
How do you keep cost cutting from hurting reliability?
Every change goes through a load test and a staged rollout with the usual latency and error alarms, scaling targets keep headroom, and the service's own team makes the change, so they decide what margin they need. We track incidents alongside savings.
7Conclusion
In this answer, we built a cost plan for Java compute that starts with visibility, tags, cost per service and cost per request owned by teams, and then pulls right-sizing and load-based scaling, Graviton with multi-architecture images, Savings Plans for the steady base and Spot for tolerant batch work, and runtime choices such as newer JDKs, startup caches and native images. Governance over years comes from budgets, regular reviews, cost estimates in design reviews and protected engineering time for efficiency.
Open with
I would give the CFO a plan in three parts. First visibility: tag every resource by service, team and environment, split shared cluster costs by task or pod, and show each team its cost per service and per request next to its latency.
Then, if they want more
Growth in total cost can be healthy; growth in cost per request is the problem, and teams need to own that number. Second, the technical levers, in order. Right-sizing comes first, because many JVMs request far more CPU and memory than they use.
I would size containers from weeks of real metrics, size the heap with MaxRAMPercentage, and scale on load instead of running a fixed count for the peak, which often saves 30 to 50 percent per service.
Then Graviton: ARM instances usually give better price-performance for Java, the JVM code runs unchanged, and the work is multi-architecture images and testing native libraries, so we measure a few services and make it the default. After right-sizing, I would buy Savings Plans for the steady base, not the peak, and run interruption-tolerant batch work on Spot.
Runtime choices come last: newer JDKs with better GCs, class data sharing or the AOT cache for faster startup, and native images or Lambda for services that are idle most of the time.
Third, governance so the bill does not grow back: budgets and alerts per team, a quarterly cost review with finance, cost estimates in architecture reviews, and a fixed share of engineering time for efficiency work.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 11, Java 24
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- AWS documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your AWS bill for Java workloads has grown 40 percent a year. The CFO asks for a plan....": https://scrivio-interview-library.netlify.app/spring-boot/aws/715a03e016/