Quick revision
The short answer
The base image carries only the options that are right for every service and make failures safe and visible: heap as a percentage of the container limit, exit on OutOfMemoryError so the orchestrator restarts the pod, a heap dump on OOM to a mounted volume, GC logging, and a continuous low-overhead JFR recording if the organisation accepts its cost. Everything that depends on a workload, such as a different collector, a special heap percentage or measured tuning, stays in the service's own configuration. We deliver the base set through one documented variable that the entrypoint passes to java (or JAVA_TOOL_OPTIONS), keep it small, review it on every JDK upgrade, and make the effective flags visible at startup.
What to remember
In this answer, we split JVM options into a small base set for safety and diagnostics, which includes heap as a percentage of the limit, exit and heap dump on OOM to a mounted volume, GC logging and an approved continuous JFR recording, and per-service options for anything workload-specific and measured. We delivered the base set through an entrypoint variable or JAVA_TOOL_OPTIONS with later options overriding, reviewed it on each JDK upgrade, and made the effective flags visible through startup logs and metrics.
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.
The base image carries only the options that are right for every service and make failures safe and visible: heap as a percentage of the container limit, exit on OutOfMemoryError so the orchestrator restarts the pod, a heap dump on OOM to a mounted volume, GC logging, and a continuous low-overhead JFR recording if the organisation accepts its cost. Everything that depends on a workload, such as a different collector, a special heap percentage or measured tuning, stays in the service's own configuration. We deliver the base set through one documented variable that the entrypoint passes to java (or JAVA_TOOL_OPTIONS), keep it small, review it on every JDK upgrade, and make the effective flags visible at startup.
Why this question is asked
A platform team that owns the base image for hundreds of Java services has real power: one line in that image changes the behaviour of every service. Done well, it gives everyone safe defaults and the same diagnostics during incidents. Done badly, it becomes a pile of copied tuning flags that nobody dares to touch, and services cannot override what they need. Interviewers ask this to see whether we can draw the line between platform policy and service tuning, and whether we think about delivery and visibility, not just the flags. In this answer, we will look at the principle for the split, the base set and why each option is there, what stays per service, how to deliver and override options, and how to keep the set small and visible.
1The Principle: Safety and Diagnostics in the Base, Tuning per Service
A good test for any option is to ask whether it would be correct for a service we have never seen. Exiting on OutOfMemoryError is correct for every stateless service in Kubernetes. Writing a GC log is useful for every service. A particular pause-time goal or a young generation size is correct only for the workload it was measured on, so it does not belong in the base.
The base set therefore does two jobs: it makes the JVM fit the container, and it makes failures safe and diagnosable in the same way everywhere. That consistency is valuable in itself, because an on-call engineer who knows that every service writes its dump to /diagnostics and its GC log to the same place can act quickly on a service they have never seen.
2The Base Set and Why Each Option Is There
Here is a typical base set for JDK 21 or 25 services. Each option has a short reason, and the reasons are documented next to the image.
A percentage-based heap means a service that moves from a 2 GiB to a 4 GiB pod gets a bigger heap without anyone editing flags. ExitOnOutOfMemoryError matters because after an OOM a JVM can be in a half-broken state, with some threads dead and others still serving traffic; exiting lets the orchestrator replace it. The heap dump is written first, because the dump on OOM happens before the exit, and it must go to a volume that outlives the container, otherwise the evidence vanishes with the restart. The heap dump also contains customer data, so that volume needs the same protection as production data.
GC logging costs almost nothing and is the first thing anyone asks for in a performance incident. A continuous JFR recording, kept in a rolling buffer on disk, gives the last few hours of events when something goes wrong. It typically costs around 1 percent, so it is a decision the organisation should make explicitly rather than a default slipped into the image.
3What Stays per Service
Anything that depends on the workload stays with the service and must be backed by a measurement. Typical examples are a different collector, such as ZGC for a latency-critical service with a large heap; a different heap percentage, such as 60 percent for a service that uses a lot of direct memory through Netty; a pause target; or a larger metaspace for a service that loads many classes. These belong in the service's repository, reviewed by its owners, with a comment that says why and links to the measurement.
| Option | Where | Reason |
|---|---|---|
| MaxRAMPercentage default | Base | fits every pod to its limit |
ExitOnOutOfMemoryError | Base | safe failure for every service |
| Heap dump on OOM to /diagnostics | Base | same evidence everywhere |
| GC logging | Base | cheap, always needed in incidents |
| Continuous JFR | Base, if approved | about 1 percent overhead |
| ZGC instead of G1 | Service | only for measured latency needs |
| Different heap percentage | Service | depends on native memory use |
| Pause targets, region sizes | Service | workload-specific tuning |
4Delivering the Options and Letting Services Override Them
There are two common delivery mechanisms. The first is an entrypoint script that builds the java command from documented variables, for example JAVA_BASE_OPTS from the image and JAVA_OPTS from the service. The second is JAVA_TOOL_OPTIONS, which the JVM reads by itself, so it works even when a service has its own start command. Its drawback is noise: the JVM prints Picked up JAVA_TOOL_OPTIONS on stderr, and every Java process in the container, including jcmd, also picks the options up, so a diagnostic tool might try to start its own JFR recording. That is why many platforms prefer the entrypoint variable for the heavier options.
Because the JVM applies options in order and the last value wins for the same flag, placing the service variable after the base set gives a clean override mechanism without editing the image. The exec matters too: it makes java the main process of the container, so it receives the termination signal directly and shuts down gracefully.
5Keeping the Set Small and Visible
Every option in the base image is a promise that it is right for hundreds of services, so the set should be short, perhaps eight to ten options, with a written reason for each. On every JDK upgrade, the platform team reviews the list: defaults improve, flags get deprecated, and an option that was needed on JDK 11 may be harmful on JDK 25. Starting the base options on the new JDK in CI catches expired flags before the image is published.
Visibility closes the loop. The effective configuration should be easy to see without logging into a pod. A simple approach is to log the JVM arguments at startup, for example from RuntimeMXBean.getInputArguments() in a small library that every service already uses, and to export the key values, such as max heap and collector name, as metrics with the image version as a label. Then a fleet dashboard can answer questions like how many services still override the heap percentage, and an incident responder can see the real flags in seconds.
6Follow-up questions
Why not put tuned G1 settings in the base image, since most services use G1?
Because G1 tuning depends on allocation rate, live set and latency goals, which differ by service. Defaults that are tuned for one workload make others worse, and once a flag is in the base image, nobody knows which services rely on it. Defaults plus measured per-service exceptions are easier to reason about.
Is ExitOnOutOfMemoryError always right?
For stateless services managed by an orchestrator, almost always. An OOM can kill threads at random points and leave locks or caches in a bad state, so a clean restart is safer. For a process that must not lose in-memory state, the trade-off needs its own decision, but such services should not rely on surviving an OOM anyway.
How do services see what the base image sets?
The options file should be documented with the image release notes, and the startup log line or metrics show the combined result. jcmd <pid> VM.command_line inside the pod also shows everything the JVM received.
7Conclusion
In this answer, we split JVM options into a small base set for safety and diagnostics, which includes heap as a percentage of the limit, exit and heap dump on OOM to a mounted volume, GC logging and an approved continuous JFR recording, and per-service options for anything workload-specific and measured. We delivered the base set through an entrypoint variable or JAVA_TOOL_OPTIONS with later options overriding, reviewed it on each JDK upgrade, and made the effective flags visible through startup logs and metrics.
Open with
I'd use one test: would this option be correct for a service I've never seen? If yes, it can go in the base image; if it depends on the workload, it stays with the service.
Then, if they want more
So the base set is about fitting the container and failing safely and visibly. MaxRAMPercentage, say 75, so the heap follows the pod limit. ExitOnOutOfMemoryError, so a half-broken JVM exits and Kubernetes restarts it. HeapDumpOnOutOfMemoryError with the path on a mounted volume, so the evidence survives the restart, and that volume is treated as sensitive because dumps contain customer data.
GC logging with rotation. And a continuous JFR recording in a rolling buffer, if the organisation explicitly accepts roughly one percent overhead. Per service: a different collector like ZGC, a lower heap percentage for services with lots of direct memory, pause targets, always with a measurement behind them.
I'd deliver it through the entrypoint, something like exec java with the base options and then the service's JAVA_OPTS, so later values override. JAVA_TOOL_OPTIONS also works but every Java tool in the container picks it up and it prints a Picked up line.
I'd keep the set to about ten options, review it on every JDK upgrade with a CI startup check, and log or export the effective flags so anyone can see what a service really runs with.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 11, Java 21, Java 25
- 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.
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 platform team ships a base container image used by all Java services. Decide which...": https://scrivio-interview-library.netlify.app/java/jvm-tuning/d543620104/