Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Teams copy JVM flags from blog posts and old services, so your fleet has hundreds of different flag combinations. How would you standardise JVM configuration?

We replace the hundreds of copied flag combinations with a small, owned default: container-aware memory settings such as MaxRAMPercentage, an explicit garbage collector, GC logging and JFR settings, and a few safety flags, shipped in the standard base images or launcher scripts. Any extra flag needs a documented reason and a measurement, obsolete flags are removed during JDK upgrades because some are ignored and others stop the JVM from starting, and the whole configuration is reviewed at every LTS migration.

Why this question is asked

JVM flags accumulate like sediment. A team copies a list from a blog post written for Java 8, another copies from an old service, and soon nobody knows why a service runs with twenty options or whether any of them still help. Some flags actively hurt, such as a fixed heap size that no longer fits the container, and others will break the next JDK upgrade. Interviewers ask this design question to see whether we can turn a messy fleet into a simple, maintained standard without breaking services. In this answer, we will see why flag sprawl is dangerous, design the default set, decide how to ship it, set the rule for exceptions, and plan cleanup during upgrades.

1Why Copied Flags Are a Problem

A JVM flag is an option on the java command line, such as -Xmx2g or -XX:+UseG1GC. Each one changes how the JVM behaves, and many were added for a specific JDK version, heap size or hardware. Copied into a different context, they can do harm.

Typical examples: -Xmx4g in a container with a 3 GB memory limit, which gets the process killed by the kernel; flags for the CMS collector, which was removed in JDK 14; -XX:MaxPermSize, which has meant nothing since Java 8; GC tuning flags tuned for a 64 GB batch server applied to a 1 GB service. Even harmless flags have a cost, because nobody dares to remove them, and every incident starts with comparing long command lines. With hundreds of combinations, we also cannot tell which settings actually work, because nothing is comparable.

2First Find Out What Is Running

Before designing a standard, we take an inventory. Every running JVM can tell us its effective settings, so we collect them from each service, group the combinations and count them.

Text
# on a running service
jcmd 1 VM.command_line # the java command and arguments as given
jcmd 1 VM.flags # flags that differ from the defaults, after ergonomics
# -XX:MaxHeapSize=1610612736 -XX:+UseG1GC -XX:+UseCompressedOops ...
# what a flag set would resolve to, without starting the app
java -XX:MaxRAMPercentage=75 -XX:+PrintFlagsFinal -version | grep -E 'MaxHeapSize|UseG1GC'

The inventory usually shows a few patterns: many services set a fixed -Xmx, a large group carries the same block copied from one old template, and a long tail has unique flags. That tells us where most of the value is: one good default will replace the majority of combinations immediately.

3Define a Small Default Set

The default should be short enough that every engineer can read and understand it. It covers memory, the collector, observability and failure behaviour, and nothing else.

Java
# Standard JVM options, version 2026.1 (owned by the platform team)
-XX:MaxRAMPercentage=75.0 # heap as a share of the container limit; default is only 25%
-XX:+UseG1GC # explicit, so small containers do not silently get Serial
-XX:+ExitOnOutOfMemoryError # let the orchestrator restart a broken process
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps
-Xlog:gc*:file=/logs/gc.log:time,uptime,level,tags:filecount=5,filesize=20m
-XX:StartFlightRecording=disk=true,maxsize=250m,maxage=6h,dumponexit=true,filename=/logs/app.jfr
Step throughWhere each part of the JVM configuration comes from
  1. Service-specific exceptionsrare, each with a reason, a measurement and an owner
  2. Named profiledefault, latency (ZGC) or batch (Parallel)
  3. Platform default setmemory percentage, GC, logging, JFR, OOM behaviour
  4. Base image launcherbuilds the java command; versioned with the image

4 layers, from the top down. Step through them one at a time.

Teams choose a profile; they do not assemble flags.

Notice the reasons. MaxRAMPercentage makes the heap follow the container limit, so resizing a pod does not require editing flags; the default of 25 percent wastes most of a small container's memory. Setting the collector explicitly avoids the JVM choosing Serial on machines it considers small. ExitOnOutOfMemoryError turns a half-dead process into a clean restart. GC logging and a continuous JFR recording mean that, when an incident happens, the data is already there. We might offer two or three named profiles, such as a latency profile with ZGC and a batch profile with Parallel GC, instead of letting each team compose its own.

4Ship It in Base Images or Launchers

A standard that lives in a wiki is copied once and then drifts. A standard that lives in the base container image, or in the launcher script that the image's entrypoint runs, is applied automatically to every service that uses the image. The platform team owns the image, versions it, and changes the default in one place.

The launcher builds the java command from the defaults plus a few documented variables, such as JVM_PROFILE for the profile and JVM_EXTRA_OPTS for approved exceptions, and it logs the final command at startup. Services then upgrade their defaults the same way they upgrade the image, with a version bump that goes through normal testing and canary rollout.

5A Rule for Extra Flags

Some services will genuinely need more, for example a larger metaspace or a specific GC pause goal. We allow that, but each extra flag needs a short written reason, a measurement showing it helps, such as GC logs or load test results before and after, and an owner. The reason lives next to the flag, in the service's deployment config, so the next person can judge whether it still applies.

In practice, the review is light: a template in the pull request asks what the flag does, what was measured, and when it should be re-checked. A CI check can compare each service's extra flags against an allowed list and flag anything new for review, which keeps the long tail from growing back.

6Clean Up at Every JDK Upgrade

Flags change between JDK releases. Some are deprecated, which prints a warning; some become obsolete, which means they are accepted but ignored with a warning; and eventually they expire, after which the JVM refuses to start with Unrecognized VM option. For example, -XX:+UseConcMarkSweepGC stopped having any effect when CMS was removed in JDK 14, and old -XX:+PrintGCDetails style logging flags were replaced by unified logging with -Xlog. The exact behaviour for each flag depends on the release, so check your version.

So every LTS migration includes a review of the default set and of every exception. We run each service's full command line against the new JDK in CI with java <options> -version, which fails fast on unknown options, and we read the warnings it prints. Flags whose reason no longer holds are deleted. This review is also the moment to adopt new good defaults, such as a newer collector mode or an AOT cache.

7Follow-up questions

Why MaxRAMPercentage instead of a fixed -Xmx?

Because a percentage follows the container. With -Xmx, changing the pod's memory limit requires changing the flag too, and the two drift apart, causing either wasted memory or kills by the kernel. A percentage of 70 to 75 leaves room for metaspace, thread stacks, direct buffers and the JIT's code cache; services with large off-heap use need a lower value.

What if a team refuses to drop its tuned flags?

We ask for the measurement. If their flags measurably help their workload, they become a documented exception, or even a new named profile if several teams benefit. If nobody can show a benefit, we run a canary with the default and compare; data usually settles the discussion.

How do we avoid breaking 300 services when the default changes?

By versioning the base image and rolling the change out like any other release: a canary group first, metrics compared on GC, memory and latency, then waves. Services pin the image version, so the change reaches each service through a normal pull request and test run, not silently.

8Conclusion

In this answer, we saw why copied JVM flags are risky, and designed a standard: take an inventory, define a small default set for memory, GC, logging, JFR and failure behaviour, ship it in versioned base images or launchers, allow extra flags only with a reason and a measurement, and remove obsolete flags at every JDK upgrade and LTS review.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start with an inventory: jcmd VM.flags and VM.command_line on every service, grouped so we see the patterns. Then I would define a small default set owned by the platform team.

Then, if they want more

It would cover memory with -XX:MaxRAMPercentage around 75, so the heap follows the container limit instead of a hard-coded -Xmx; an explicit collector, normally G1, because the JVM can silently pick Serial on small containers; ExitOnOutOfMemoryError and a heap dump path; GC logging with -Xlog; and a continuous JFR recording so incident data already exists.

I would offer two or three named profiles, like latency with ZGC and batch with Parallel, rather than letting teams compose flags. That default goes into the standard base image's launcher script, so every service gets it automatically and it is versioned like any other dependency.

Any extra flag needs a written reason, a measurement such as before-and-after GC logs, and an owner, and a CI check flags new options for review.

Finally, at every JDK upgrade, and especially each LTS migration, we review the set: run each command line against the new JDK in CI, because some flags are ignored with a warning and expired ones stop the JVM from starting, and delete anything whose reason no longer holds.

About this answer

Last updated
12 November 2026
Versions it names
Java 14, Java 8
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 "Teams copy JVM flags from blog posts and old services, so your fleet has hundreds of...": https://scrivio-interview-library.netlify.app/java/jvm-architecture/ca816a675f/