Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Your fleet runs 2,000 Java containers with inconsistent JVM flags copied between teams. How would you set and roll out standard JVM container settings?

I would define a small set of tested defaults in the shared base images or platform launcher: a heap percentage, a garbage collector chosen by container size, and failure flags such as -XX:+ExitOnOutOfMemoryError. Teams may override them only with a documented reason. The rollout goes in waves with dashboards for memory, GC pauses, restarts and latency, an inventory tracks the JDK version and effective flags of every service, and the defaults are revisited with every JDK release because the JVM's own behaviour changes.

Why this question is asked

Flags copied between teams are a quiet risk at scale. A setting that made sense for a 16 GiB service in 2019 ends up in a 512 MiB container in 2026, an old -XX:+UseConcMarkSweepGC stops the JVM from starting on a modern JDK, or one team's -Xmx works only because nobody changed their pod size. With 2,000 containers, even a small mistake is multiplied. Interviewers ask this to see how we would standardize safely without breaking services that depend on their current settings. In this answer, we will see what goes wrong today, choose defaults, deliver them through the platform, handle overrides, roll out in waves, and keep an inventory current.

1What Inconsistent Flags Cost

When flags are copied rather than chosen, three things happen. Some services run with the JVM's conservative defaults, a heap of 25 percent of the container, and waste most of the memory they pay for. Others set a heap too close to the limit and get OOMKilled under load. And many carry flags that do nothing on the current JDK, or worse, flags for collectors that no longer exist, which a JDK upgrade turns into a startup failure.

The bigger problem is that nobody can answer simple questions such as which services still use a fixed -Xmx, or how many run on JDK 17. So the plan has to standardize the settings and also make them visible.

2Choose a Small Set of Defaults

The defaults should be few and justified. For memory, -XX:MaxRAMPercentage around 70 so the heap follows the container limit and leaves room for non-heap memory. For failure handling, -XX:+ExitOnOutOfMemoryError so a JVM that has run out of heap exits and gets restarted instead of limping along, plus a heap dump to a mounted volume where the platform collects it. For garbage collection, the choice depends on size: G1 is the JVM's default and fits most services; for very small containers with one CPU the JVM falls back to Serial automatically; for large heaps with strict latency goals, generational ZGC is a good option on JDK 21 and later.

Platform JVM defaults by container size
ContainerHeapGCOther
under 1 GiB, 1 CPUMaxRAMPercentage=60Serial (JVM default here)ExitOnOutOfMemoryError
1 to 8 GiBMaxRAMPercentage=70G1 (default)ExitOnOutOfMemoryError
over 8 GiB, latency-criticalMaxRAMPercentage=75ZGC (generational)ExitOnOutOfMemoryError
any--heap dump to /dumps volume
Defaults live in the base image; services only add what they need.

3Deliver Defaults Through the Base Image or Launcher

Copied flags happen when every team writes its own entrypoint. So the platform provides them: the shared Java base image sets JAVA_TOOL_OPTIONS, or better, a small launcher script in the image computes the flags from the container's limits and starts the JVM. Services then set only an extra variable for their overrides.

Text
# Platform base image (simplified)
FROM eclipse-temurin:25-jre
ENV JAVA_PLATFORM_OPTS="-XX:MaxRAMPercentage=70 -XX:+ExitOnOutOfMemoryError \
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps"
COPY platform-launch.sh /usr/local/bin/
ENTRYPOINT ["platform-launch.sh"]
# platform-launch.sh: exec java $JAVA_PLATFORM_OPTS $JAVA_SERVICE_OPTS -jar /app/app.jar
# A service sets only: JAVA_SERVICE_OPTS="-XX:MaxDirectMemorySize=256m" # reason: Netty

Notice that the launcher puts service options after platform options, so a service's value wins when both set the same flag, and it logs the final command line at startup so anyone can see the effective settings.

4Overrides With Documented Reasons

Some services really need something different: a batch service with a 90 percent heap because it has almost no threads, or a gateway with a direct memory cap for Netty. Overrides are allowed, but each one goes in the service's deployment config with a comment that says why, ideally with a link to the measurement. During review, an override without a reason is questioned.

This keeps the platform from becoming a straitjacket while making every deviation visible. When the platform changes a default later, we can find the services that override it and check whether their reason still holds.

5Roll Out in Waves With Dashboards

Changing the JVM settings of 2,000 containers at once would make any problem impossible to diagnose. So the rollout goes in waves: first a handful of volunteer services, then 5 percent of the fleet chosen across types (web, batch, streaming), then larger waves. Before each wave, a dashboard compares before and after for container memory, heap used, GC pause time and frequency, restarts and OOMKills, and request latency at p50 and p99.

A wave proceeds when the numbers are stable or better for a week. If a service gets worse, we roll it back, find out why, and either fix the default or record a documented override. Most services should see fewer OOMKills and better memory use, and a few will show us that the defaults need tuning.

Step throughRolling out new JVM defaults
  1. Pilot with volunteer servicesmeasure for a week
  2. Wave of 5 percent across workload typesweb, batch, streaming
  3. Memory, GC, restarts, latency stable?
    YesNext wave, largerNoRoll back, fix default or add override
  4. Remaining fleet in larger wavessame checks per wave
  5. Inventory updated after each waveflags and JDK per service

5 steps in order. Play them, or step through them one at a time.

6Inventory and Revisiting Each JDK Release

An inventory records, for every service, the JDK version, the base image, and the effective flags. The launcher can report them at startup as a log line or an info endpoint, and a job collects them. With it, questions such as how many services still run JDK 17 take seconds to answer, and security upgrades are easier to track.

Finally, defaults are not permanent. The JVM's ergonomics, the choices it makes on its own, change between releases: newer JDKs improved G1's memory return, made ZGC generational, and introduced options such as compact object headers. So with each JDK release the platform team tests the defaults on a few services and updates them, and the inventory shows who has picked up the change.

7Follow-up questions

Why ExitOnOutOfMemoryError instead of letting the JVM recover?

After an OutOfMemoryError, the application is in an unknown state: some threads died, caches may be half updated, and the next allocation will probably fail again. Exiting lets Kubernetes restart a clean process, and the heap dump captured on the way out tells us why it happened.

How do you handle services that pin an old JDK?

The inventory shows them, and each gets a plan with an owner and a date. Base images for old JDKs are kept patched for a limited time, and the platform defaults for those images are tested separately, since some flags differ between versions.

Should CPU-related flags be standardized too?

Usually not by default, because the JVM reads the CPU limit itself. But for services without CPU limits, the JVM sees all the node's cores and may create too many GC and compiler threads, so the platform can set -XX:ActiveProcessorCount based on the CPU request for those.

8Conclusion

In this answer, we saw how to replace copied JVM flags with a fleet standard. We chose a few defaults, a heap percentage, a GC chosen by container size and ExitOnOutOfMemoryError with a heap dump, delivered them through the base image or a platform launcher, allowed documented overrides, rolled the change out in waves while watching memory, GC pauses, restarts and latency, tracked JDK versions and flags in an inventory, and planned to revisit the defaults with each JDK release.

What to say in the interviewAbout 80 seconds aloud

Open with

I would move the flags out of each service and into the platform. The shared base image or a small launcher script sets the defaults: MaxRAMPercentage around 70 so the heap follows the container limit, ExitOnOutOfMemoryError with a heap dump to a volume so a broken JVM restarts cleanly and leaves evidence, and the GC chosen by size, G1 for most, Serial for tiny single-CPU containers, generational ZGC for large latency-sensitive heaps.

Then, if they want more

Services can still override, but only through one variable, with a comment explaining the reason and ideally a measurement, so deviations are visible. Rollout would be in waves: a few volunteers, then about 5 percent across web, batch and streaming workloads, then larger waves.

For each wave I would compare container memory, GC pause time, restarts and OOMKills, and p99 latency before and after, and roll back any service that gets worse. In parallel, the launcher reports the JDK version and effective flags at startup, and we collect that into an inventory, so we can answer which services run which JDK and settings.

And because JVM ergonomics change between releases, the platform team retests and updates the defaults with every JDK release.

About this answer

Last updated
12 November 2026
Versions it names
Java 17, Java 21
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 fleet runs 2,000 Java containers with inconsistent JVM flags copied between teams....": https://scrivio-interview-library.netlify.app/spring-boot/containers-and-kubernetes/133f18c037/