Quick revision
The short answer
I would start with data: real CPU and memory usage per service at p95 and peak, compared with what each service requests, sorted by the size of the gap. Then I would generate recommendations, for example with the Vertical Pod Autoscaler in recommendation-only mode, have the owning teams review them, fix JVM heap settings so memory requests can shrink safely, show each team its own cost and waste, and roll the changes out in waves while watching latency, throttling and OOM kills, with a fast way back.
What to remember
In this answer, we saw that requests drive the bill, so we measured real usage at p95 and peak against requests and started with the largest gaps. We generated recommendations with VPA in recommendation-only mode and let owners review them, fixed heap sizing as a percentage of the limit so memory could shrink safely, made cost and waste visible per team, and rolled out in waves while watching latency, throttling and OOM kills with a quick rollback.
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 data: real CPU and memory usage per service at p95 and peak, compared with what each service requests, sorted by the size of the gap. Then I would generate recommendations, for example with the Vertical Pod Autoscaler in recommendation-only mode, have the owning teams review them, fix JVM heap settings so memory requests can shrink safely, show each team its own cost and waste, and roll the changes out in waves while watching latency, throttling and OOM kills, with a fast way back.
Why this question is asked
Low utilisation is one of the most common cost problems in Kubernetes, and Java services are often the largest contributors. Teams set big requests once, during a scary launch, and never revisit them, because nobody gets thanked for shrinking a request and everyone gets blamed for an outage. Interviewers ask this leadership question to see whether we can turn a cost complaint into a safe, measured programme that teams actually support. In this answer, we will see why requests drive cost, how to find the biggest gaps, how to generate and review recommendations, why the JVM settings must change at the same time, how to make waste visible per team, and how to roll it out without hurting reliability.
1Why Requests, Not Usage, Drive the Bill
The Kubernetes scheduler places pods by their requests, not by what they use. If a pod requests 2 CPU and 4 GiB, the node keeps that much reserved for it whether the pod uses it or not. Nodes are bought to fit the sum of requests, so the cluster bill follows requests. Utilisation of 20 percent means that for every five cores we pay for, four sit reserved and idle.
Java services are often the biggest offenders for two reasons. Startup needs much more CPU than steady state, because of class loading and JIT compilation, so teams size CPU for startup. And memory requests were often set large because the heap was set large with -Xmx, sometimes larger than needed, leaving no clear idea of what the service really uses.
2Finding the Largest Gaps First
The first step is measurement. From Prometheus we take, per service over at least two weeks so that weekly peaks are included, CPU usage at p95 and at peak, and memory working set at p95 and peak. We compare each with the requests and compute the gap in cores and GiB, multiplied by replicas. Sorting by that number usually shows a long tail: a small set of services holds most of the waste. Starting there gives the biggest saving for the least effort and the fewest conversations.
Notice that the comparison uses p95 and peak, not the average. Averages hide the busy hour, and a request sized from the average would cause throttling exactly when it matters.
3Generating Recommendations Owners Can Trust
Next we generate a concrete proposal per service. The Vertical Pod Autoscaler (VPA) can run with updateMode set to Off, which means it only computes recommendations from observed usage and never evicts pods. Its target and upper bound give a reasonable starting point. Tools such as Goldilocks show the same data per namespace.
The proposal goes to the owning team, not straight into production. The team knows things the metrics do not: a quarterly batch, a launch next month, a startup spike. Asking them to review keeps ownership where it belongs and turns the change into their decision. In practice we make it easy: a pull request with the new values already filled in, and a default that applies if they do not object within two weeks.
4Fixing JVM Settings at the Same Time
Memory is where right-sizing Java services goes wrong. If a service runs with -Xmx3g and we lower its memory limit to 2 GiB, the heap can grow past the limit and the kernel kills the pod. So the memory request cannot shrink unless the heap shrinks with it.
The fix is to size the heap as a percentage of the container limit instead of a fixed number, with -XX:MaxRAMPercentage=75 for example. The JVM reads the cgroup limit at startup, so when the limit goes from 4 GiB to 2 GiB the heap goes from 3 GiB to 1.5 GiB automatically, leaving room for metaspace, thread stacks, direct buffers and the code cache. We put this in the shared base image or Helm chart so every team gets it, and we remove hard-coded -Xmx values as part of the same change. CPU deserves a similar look: services that request lots of CPU only for startup can often use a startup probe and a lower steady request, or a faster-start option such as class data sharing.
5Making Waste Visible per Team
People change what they can see. We report cost and waste per team every month: what their requests cost, what they used, and the difference in money. Tools such as OpenCost or the cloud provider's cost allocation can split the bill by namespace and label. A table where a team sees that 70 percent of its spend is idle reservation does more than any mandate, and it gives managers a number to track. We frame it as information, not blame, and we celebrate the teams that close the gap.
| Team | Requested cost | Used cost | Idle share |
|---|---|---|---|
| Orders | $18,400 | $4,100 | 78% |
| Pricing | $9,200 | $5,600 | 39% |
| Search | $12,000 | $9,900 | 18% |
6Changing in Waves With a Way Back
We roll out in waves: first a few willing teams with large gaps, then the next group once the first is stable. Each change is a normal deployment, so it can be reverted in minutes. For two weeks after each change we watch the signals that would show we cut too far: p99 latency, CPU throttling ratio, OOMKilled restarts and GC time. If any of them moves beyond an agreed threshold, the team rolls back first and investigates later.
A sensible target is not 100 percent utilisation. Nodes need headroom for bursts and failovers, so a cluster at 50 to 60 percent of requested CPU used is already a large improvement on 20 percent.
- Measure usage at p95 and peak14 days or more
- Generate VPA recommendationmode Off, no restarts
- Owner reviews pull requestadds context the metrics lack
- Deploy with heap as percentageMaxRAMPercentage, no fixed Xmx
- Watch for two weeksp99, throttling, OOMKilled
- Signals within thresholds?YesKeep and report savingNoRoll back, then adjust
6 steps in order. Play them, or step through them one at a time.
7Follow-up questions
Why not let VPA apply changes automatically?
In auto mode VPA evicts pods to apply new requests, which surprises teams and can restart many replicas at once. Its recommendations also lag behind traffic changes. For a first programme, recommendation-only mode plus owner review builds trust; later, automatic updates may suit some stateless services with enough replicas.
What if a team refuses to shrink?
We ask for the reason and record it. A real reason, such as a known seasonal peak, becomes a documented exception with a review date. If there is no reason, the visible cost report and the default-after-two-weeks rule usually settle it without escalation.
How do you avoid causing CPU throttling while cutting CPU?
We size CPU requests from p95 usage, not averages, and for latency-sensitive services we avoid tight CPU limits altogether. We also watch the throttled-periods ratio after each change and treat a rise as a rollback signal.
8Conclusion
In this answer, we saw that requests drive the bill, so we measured real usage at p95 and peak against requests and started with the largest gaps. We generated recommendations with VPA in recommendation-only mode and let owners review them, fixed heap sizing as a percentage of the limit so memory could shrink safely, made cost and waste visible per team, and rolled out in waves while watching latency, throttling and OOM kills with a quick rollback.
Open with
I would treat this as a programme, not a mandate. First I would get data: per service, CPU and memory usage at p95 and at peak over at least two weeks, compared with requests and multiplied by replicas, so we see where the gap is largest.
Then, if they want more
Usually a handful of services hold most of the waste, so I start there. For each one I would generate a recommendation, for example with the Vertical Pod Autoscaler in recommendation-only mode so nothing restarts, and send it to the owning team as a pull request to review, because they know about peaks the metrics may not show.
For Java, I would fix JVM settings in the same change: replace fixed -Xmx values with MaxRAMPercentage around 75 so the heap follows the container limit, otherwise a smaller memory request just produces OOM kills. To keep it going I would publish cost and waste per team every month, so owners see the price of their margins.
Rollout would be in waves, starting with willing teams, and after each change we watch p99 latency, CPU throttling and OOMKilled restarts for two weeks, with a rollback that takes minutes. The goal is something like 50 to 60 percent utilisation, not 100, because we still need headroom.
About this answer
- Last updated
- 12 November 2026
- 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
- Kubernetes 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 cluster costs are rising and utilisation is around 20 percent, mainly due to Java...": https://scrivio-interview-library.netlify.app/spring-boot/containers-and-kubernetes/c9dad8d43a/