Quick revision
The short answer
We define a standard launch contract: the base image's entrypoint builds the java command from a few documented variables, such as memory percentage, GC choice and approved extra options, with safe defaults. Application settings move to Spring properties or environment variables instead of -D flags in scripts, every service logs its effective JVM flags and key system properties at startup so drift is visible centrally, JAVA_TOOL_OPTIONS is reserved for the platform's agents, options are validated in CI so typos fail fast, and changes roll out by canary with memory, GC and startup metrics tracked per option set.
What to remember
In this answer, we designed a launch contract for 200 services: one entrypoint in the base image that builds the java command from a few documented variables with safe defaults, application settings in Spring properties instead of -D flags, effective flags logged and collected centrally, JAVA_TOOL_OPTIONS reserved for platform agents, options validated in CI, and changes rolled out by canary with metrics per option set.
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.
We define a standard launch contract: the base image's entrypoint builds the java command from a few documented variables, such as memory percentage, GC choice and approved extra options, with safe defaults. Application settings move to Spring properties or environment variables instead of -D flags in scripts, every service logs its effective JVM flags and key system properties at startup so drift is visible centrally, JAVA_TOOL_OPTIONS is reserved for the platform's agents, options are validated in CI so typos fail fast, and changes roll out by canary with memory, GC and startup metrics tracked per option set.
Why this question is asked
When JVM options can be set in a Dockerfile, a Helm chart, a start script and JAVA_TOOL_OPTIONS, nobody knows which value actually applies. A team raises the heap in the Helm chart while a base image sets it in JAVA_TOOL_OPTIONS, a typo in a -D flag silently does nothing, and a debug agent left in a script ships to production. Interviewers ask this design question to see whether we can replace that confusion with one clear contract that is safe, observable and easy to change. In this answer, we will see why scattered configuration causes incidents, design the launch contract, separate application configuration from JVM options, make the effective configuration visible, validate it early, and roll changes out safely.
1Why Scattered Launch Configuration Causes Incidents
The JVM reads options from several places and combines them: JAVA_TOOL_OPTIONS first, then JDK_JAVA_OPTIONS, then the command line, with later values generally winning. When four teams own four of those places, the result depends on an order most people do not know. Typical incidents: an old base image sets -Xmx in JAVA_TOOL_OPTIONS, a start script adds a different -Xmx on the command line that wins, and that value is larger than the new container limit, so the kernel kills the pod under load; an -Dspring.profiles.active=prod in a script overrides the profile the Helm chart sets; a misspelled -XX flag stops some services from starting after a JDK upgrade.
The root problem is not any single setting. It is that there is no single owner, no single place to read the effective configuration, and no check before deployment.
2The Launch Contract
We make the base image's entrypoint the only thing that builds the java command. It reads a small set of documented environment variables, applies safe defaults for anything not set, and logs the final command. Teams set the variables in their deployment, and nothing else touches the command line.
- Helm values per service
JVM_MEMORY_PERCENT,JVM_GC,JVM_EXTRA_OPTS, Spring env vars - Base image entrypointbuilds and logs the java command, safe defaults
- JAVA_TOOL_OPTIONSplatform agents only, reviewed
- JVMlogs effective flags and key properties at startup
4 layers, from the top down. Step through them one at a time.
Each layer has one owner and one purpose.
Notice a few choices. exec replaces the shell with the JVM, so the JVM receives container stop signals directly and shuts down gracefully. The defaults live in one versioned script, so changing a default for 200 services is one image release. The set of variables is small and named for what people actually need, and anything outside it goes through JVM_EXTRA_OPTS, which is reviewed. The image's Dockerfile has no JAVA_OPTS of its own and the Helm chart only sets the documented variables.
3Application Configuration Is Not a JVM Option
Many -D flags in start scripts are really application settings, such as -Dspring.profiles.active=prod, -Dapp.feature.x=true or a database URL. Spring Boot reads environment variables with relaxed binding, so SPRING_PROFILES_ACTIVE=prod or APP_FEATURE_X=true in the deployment set the same properties without touching the java command. Putting them there keeps all of a service's settings in one place, the deployment configuration, where they are reviewed, diffed and shown by the platform.
So the rule is simple: JVM options in the launch contract variables, application settings as Spring properties, in configuration files or environment variables. A -D in a script is allowed only for true JVM-level system properties, such as a networking or TLS setting, and goes through JVM_EXTRA_OPTS like any other extra.
4Making the Effective Configuration Visible
To find drift, we must see what each JVM actually runs with, not what we think its scripts say. Each service logs its effective configuration at startup, and the platform collects it centrally.
Collected centrally, these lines answer questions like which services still set a fixed -Xmx, which use an unusual GC flag, or which run with an agent nobody approved. A dashboard of option sets per service makes drift visible, and an alert can fire when a service starts with a flag not on the allowed list.
5JAVA_TOOL_OPTIONS and CI Validation
JAVA_TOOL_OPTIONS is powerful because the JVM itself reads it, so it reaches every Java process, including jcmd and jstack run in the container. That makes it the right place for platform-level additions, such as the APM agent, and the wrong place for anything else. We reserve it for the platform team, set it only in the base image or the platform's admission controls, and review changes like code.
We also validate options before deployment. The CI pipeline renders each service's final command from its deployment values and runs it once in the target image with -version instead of the application, which fails immediately on an unrecognized or expired option. A simple lint compares JVM_EXTRA_OPTS against an allowed list and requires a reason comment for anything new.
6Rolling Out Changes Safely
Even a correct default can hurt a particular service, so changes to the contract roll out like code. A new base image version with a changed default goes first to a canary group of services, or to a few instances of each, and we compare memory use, GC pauses and frequency, startup time and latency against instances on the old version. Because every service logs its option set, the metrics can be grouped by option set, which tells us precisely which change caused which effect. Then the change goes out in waves, with an easy rollback by pinning the previous image.
7Follow-up questions
Which defaults would you set for container memory?
Set the container's memory request equal to its limit so the pod is not squeezed by neighbours, and size the heap as a percentage of that limit with MaxRAMPercentage, around 70 to 75 percent for typical services, because the JVM also needs memory for metaspace, thread stacks, the code cache and direct buffers. Services with heavy off-heap use, such as Netty or large thread counts, need a lower percentage, around 50 to 60. Add ExitOnOutOfMemoryError so a broken process restarts cleanly, and check that the JVM sees the right CPU count, which matters for GC and JIT threads.
What about teams that need a flag outside the contract?
They put it in JVM_EXTRA_OPTS with a short reason and a measurement in the pull request, and the allowed list grows if it is generally useful. If several teams need the same thing, it becomes a documented variable or a named profile in the contract, which keeps the contract useful rather than restrictive.
Why exec in the entrypoint?
Without exec, the shell is process 1 in the container and the JVM is its child. Container stop signals go to the shell, which may not forward them, so the JVM is killed after the grace period instead of shutting down cleanly, losing in-flight requests and skipping shutdown hooks.
8Conclusion
In this answer, we designed a launch contract for 200 services: one entrypoint in the base image that builds the java command from a few documented variables with safe defaults, application settings in Spring properties instead of -D flags, effective flags logged and collected centrally, JAVA_TOOL_OPTIONS reserved for platform agents, options validated in CI, and changes rolled out by canary with metrics per option set.
Open with
I would make the base image's entrypoint the single place that builds the java command. It reads a few documented variables, such as JVM_MEMORY_PERCENT for MaxRAMPercentage, JVM_GC, and JVM_EXTRA_OPTS for reviewed extras, applies safe defaults like G1, ExitOnOutOfMemoryError and GC logging, and uses exec so the JVM gets stop signals.
Then, if they want more
Teams only set those variables in their Helm values; Dockerfiles and scripts stop adding options. Application settings move out of -D flags into Spring properties and environment variables like SPRING_PROFILES_ACTIVE, so all service config lives in the deployment.
Next, visibility: every service logs its JVM input arguments, version and max heap at startup through a small platform starter, and jcmd VM.flags and VM.system_properties are there for live checks. We collect that centrally so we can see drift, for example who still sets a fixed -Xmx.
JAVA_TOOL_OPTIONS is reserved for the platform, mainly agents, because it reaches every JVM process including jcmd, and changes are reviewed. In CI we render each service's command and run it with -version in the target image, so a typo or an expired flag fails the pipeline, not the deploy.
Finally, changes to defaults ship as a new base image version, canaried first, comparing memory, GC, startup and latency per option set before the wider rollout.
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.
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 "Across 200 services, JVM options and system properties are set in Dockerfiles, Helm...": https://scrivio-interview-library.netlify.app/java/jvm-architecture/751102f9b0/