Quick revision
The short answer
I would label every workload with its service, team and environment and allocate node cost by requested CPU and memory, because requests are what reserve capacity on a shared cluster. Then I would report cost per service and per unit of business work, show each service the gap between what it requests and what it uses, and publish recommendations with the expected saving and the risk, leaving the change to the owning team. Cost then becomes a regular part of service reviews next to reliability, with non-production environments in scope too.
What to remember
In this answer, we designed a cost visibility programme for 40 teams on shared Kubernetes clusters. Every workload is labelled with service, team and environment, node cost is allocated by requested CPU and memory, and reports show cost per unit of business work and the gap between requested and used resources that is common for JVMs. Recommendations carry expected savings and risk, teams own the change, and cost is reviewed regularly next to reliability, including non-production environments.
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 label every workload with its service, team and environment and allocate node cost by requested CPU and memory, because requests are what reserve capacity on a shared cluster. Then I would report cost per service and per unit of business work, show each service the gap between what it requests and what it uses, and publish recommendations with the expected saving and the risk, leaving the change to the owning team. Cost then becomes a regular part of service reviews next to reliability, with non-production environments in scope too.
Why this question is asked
On shared Kubernetes clusters, the cloud bill arrives as one large number for the nodes. Nobody can say what a given service costs, so nobody feels responsible for it, and waste grows quietly. Interviewers ask this design question to see whether we can build visibility that is fair, understandable and actually changes behaviour, rather than a dashboard nobody opens. In this answer, we will see why shared clusters hide cost, design the allocation, choose the right unit metrics, expose the gap between requested and used resources that is typical for JVMs, turn data into recommendations, and build the habit of reviewing cost.
1Why Shared Clusters Hide Cost
On a shared cluster, the cloud provider bills for nodes, the virtual machines, not for services. Forty teams' pods are packed onto the same nodes by the Kubernetes scheduler, so the bill has no idea which team caused which cost. Without allocation, the cost belongs to the platform team, which cannot reduce it because it does not own the workloads, while the teams that could reduce it never see it.
The scheduler's rule is the key to fair allocation. When a pod requests 2 CPU cores and 4 GB of memory, the scheduler reserves that capacity on a node, whether the pod uses it or not. No other pod can be placed in that space. So a service's cost is driven by what it requests, not just by what it uses.
2Labels and Allocation by Requests
The first step is labelling. Every workload carries labels for service, team and environment, enforced by an admission policy so that unlabelled workloads cannot be deployed. A cost tool, such as OpenCost or a commercial equivalent, then reads the node prices and splits each node's cost among the pods on it, in proportion to their CPU and memory requests (or their usage, if it is higher). Shared costs such as the control plane, monitoring and idle node capacity are spread by a documented rule, for example in proportion to each team's requests.
- Cloud billNode prices per hour
- Allocation toolSplits node cost by pod requests or usage
- Labelsservice, team, environment on every workload
- Unit metricsCost per 1,000 requests or per order
- Team report and service reviewGap, recommendations, trend
5 layers, from the top down. Step through them one at a time.
Each layer turns the previous one into something a team can act on.
Notice the staging line: non-production environments often cost a large share of the bill and are easy to forget, so they stay in scope from the start.
3Cost per Unit of Business Work
Total cost alone is misleading. If the orders service costs 40 percent more than last quarter, that is good news if orders grew 60 percent, and bad news if they grew 5 percent. So the report shows cost per unit of business work: per 1,000 requests, per order, per active user or per message processed, whichever drives the service's load. Growth then shows up as rising total cost with flat unit cost, and waste shows up as rising unit cost.
Unit costs also make teams comparable in a fair way and give product leaders a number they understand, such as 0.4 cents of infrastructure per order.
4Showing the Gap Between Requested and Used
For JVM services, the most valuable number is often the gap between requests and actual use. Java services are commonly given a large heap and a matching memory request when they are created, plus CPU requests sized for the startup burst, and those values are never revisited. A service might request 4 GB and use 1.6 GB at peak, or request 2 cores and use 0.3. That gap is reserved capacity nobody else can use.
The JVM makes this tricky in one specific way: memory used by the container includes the heap the JVM has claimed, which may be far more than its live data. So the report should show both container memory and heap after GC, which together tell the team how much they can safely cut.
5Recommendations With Savings and Risk
Data alone rarely changes behaviour; a specific recommendation does. For each service, the programme publishes recommended requests based on measured usage plus headroom, with the expected monthly saving and the risk: lower memory raises the chance of OOMKilled pods or more GC, and lower CPU can raise latency, especially at startup. The Vertical Pod Autoscaler in recommendation mode, or the cost tool itself, can compute the numbers.
The owning team decides and makes the change in its own manifests, because they know their traffic patterns, their upcoming launches and their latency targets. The platform's role is to make the recommendation easy to apply and safe to undo.
- Measure usage over 30 daysp95 memory, heap after GC, CPU
- Recommend requests with headroomShow monthly saving and risk
- Team accepts?YesApply in manifests, graduallyNoRecord the reason, review next quarter
- Watch OOMKilled, GC, latency for a week
- Stable?YesKeep and report the savingNoRoll back to previous requests
5 steps in order. Play them, or step through them one at a time.
Teams own the decision; reliability metrics guard the change.
6Making Cost a Regular Habit
Visibility fades unless it is part of a routine. I would add cost to the regular service reviews where teams already discuss reliability: the unit cost trend, the request gap and open recommendations, next to SLOs and incidents. Putting cost next to reliability keeps the trade-off honest. Leaders see team-level reports monthly, and the biggest savings are celebrated publicly, which does more than any mandate.
7Follow-up questions
How do you avoid teams cutting memory until services become unstable?
By pairing every cost number with reliability numbers and setting guardrails. Recommendations always include headroom above measured peak, for example 30 percent above heap after GC, never the bare minimum. After a change, OOMKilled events, GC time and p99 latency are watched for a week, with an easy rollback. Teams are measured on unit cost together with their SLOs, not on absolute cuts, so nobody is rewarded for a saving that causes an incident. And the review looks at services that cut aggressively as closely as at those that waste.
Should cost be allocated by usage or by requests?
Mostly by requests, because that is what reserves capacity and what the team controls. A common refinement is to use whichever is larger, requests or usage, so a pod with no limits that bursts far above its request is also charged for that. Using usage alone would make over-requesting look free, which is exactly the waste we want to show.
What about costs outside the cluster, like databases?
They belong in the same report, tagged by service and team in the cloud provider's billing. For many services, the managed database or storage costs more than the pods, and showing it alongside compute keeps the focus on the largest numbers.
8Conclusion
In this answer, we designed a cost visibility programme for 40 teams on shared Kubernetes clusters. Every workload is labelled with service, team and environment, node cost is allocated by requested CPU and memory, and reports show cost per unit of business work and the gap between requested and used resources that is common for JVMs. Recommendations carry expected savings and risk, teams own the change, and cost is reviewed regularly next to reliability, including non-production environments.
Open with
I would start by making cost attributable. Every workload must carry service, team and environment labels, enforced at admission, and a tool like OpenCost splits each node's cost among pods by their CPU and memory requests, because on a shared cluster requests reserve capacity whether they are used or not.
Then, if they want more
Shared overhead and idle capacity are spread by a documented rule. Then I would report cost per service and per unit of business work, like per thousand requests or per order, so teams can tell growth from waste.
The most useful view for Java services is the gap between requested and used resources: heaps and memory requests set once at creation, CPU sized for startup, often two or three times what the service uses at peak. I would show container memory and heap after GC side by side, so teams know what is safe to cut.
Each service gets recommendations with the expected saving and the risk, OOMKilled pods, more GC, higher latency, and the team decides and applies them, with a week of monitoring and an easy rollback. To stop teams cutting too far, recommendations always keep headroom, and teams are measured on unit cost together with their SLOs.
Finally, cost becomes part of the regular service review next to reliability, and non-production environments stay in scope, because they are often a surprisingly large share of the bill.
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, Spring Boot reference
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 organisation runs Java workloads for 40 teams on shared Kubernetes clusters, and...": https://scrivio-interview-library.netlify.app/spring-boot/production-operations/be9024a5ca/