Quick revision
The short answer
The organisation should treat every JVM flag as code: it has an owner and a written reason, and a flag nobody can explain is removed after testing. Because JDK defaults have improved steadily, with container support, better G1 and ZGC and better metaspace handling, most services need few flags, and regular JDK upgrades are the highest-return performance practice for a fleet. Tuning effort belongs mainly in code, allocation and architecture, where gains are larger and survive upgrades. We keep a small approved set of flags in the base image, require measurements for any addition, and change the culture by teaching the method of tuning rather than lists of flags.
What to remember
In this answer, we saw that flags accumulate because adding is easy and removing feels risky. The organisation should treat flags as code with an owner and a reason, recognise that modern JDK defaults and regular upgrades make most old flags unnecessary, put tuning effort into code, allocation and architecture, remove unexplained flags in small canaried batches, keep a small approved base set that requires measurements for additions, and teach the method of tuning rather than lists of flags.
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 organisation should treat every JVM flag as code: it has an owner and a written reason, and a flag nobody can explain is removed after testing. Because JDK defaults have improved steadily, with container support, better G1 and ZGC and better metaspace handling, most services need few flags, and regular JDK upgrades are the highest-return performance practice for a fleet. Tuning effort belongs mainly in code, allocation and architecture, where gains are larger and survive upgrades. We keep a small approved set of flags in the base image, require measurements for any addition, and change the culture by teaching the method of tuning rather than lists of flags.
Background to this question
A service with 40 JVM flags accumulated over a decade is a common sight, and it is a cultural problem more than a technical one. Each flag was added by someone with a reason, but the reasons are lost, the people have moved on, and now the list blocks JDK upgrades and makes every performance investigation harder. A senior engineer is expected to fix not just this service but the habits that produced it. In this answer, we will look at why flags accumulate, set the stance of flags as code, see why modern defaults and upgrades change the economics, decide where tuning effort should go, describe how to clean up the 40 flags safely, and how to change the culture so the list does not grow back.
1How 40 Flags Happen
Flags accumulate through a predictable pattern. An incident happens, someone finds an article with a flag that sounds related, adds it, and the incident does not recur, perhaps because of the flag, perhaps because of something else. Nobody measures, so the flag stays. A new team member copies a list from a previous job. A consultant adds tuning for a specific load test. Each addition is small and reasonable; nobody owns the total. Removing a flag feels risky, because nobody knows what it protects, while adding one feels safe.
The result is a configuration that nobody understands, built for collectors and JDK versions that no longer exist. That asymmetry, easy to add and scary to remove, is what the organisation has to change.
2The Stance: Flags Are Code
A JVM flag changes how a production system behaves, exactly like a line of code, so it deserves the same treatment. Each flag has an owner, a written reason, a link to the measurement that justified it, and a review when the context changes, such as a JDK upgrade or a large change in load. A flag without a reason is treated like dead code: it is a candidate for removal, and removal is done carefully, with tests, not with fear.
Notice that with this format a newcomer can answer, in seconds, why each flag exists and when to question it. That is the difference between a configuration and a superstition.
3Why Modern Defaults and Upgrades Change the Economics
Many of the 40 flags were compensating for weaknesses that the JDK has since fixed. Container support means the JVM reads pod limits instead of host values. G1 became the default in JDK 9 and has improved in almost every release since, with better pause prediction, faster full GCs and lower memory overhead. ZGC became production ready in JDK 15 and generational in JDK 21. Metaspace was reworked to return memory more readily, and the JIT got better with each release. A flag that tuned around a 2015 problem often fights the 2026 solution.
This also means that upgrading the JDK regularly is the single most effective performance practice for a fleet. Each LTS release brings performance work that no team could replicate, and it applies to every service at once. A fleet stuck on an old JDK because its flags break on the new one loses those gains; removing unexplained flags is what unlocks them.
4Where Tuning Effort Should Go
JVM flags are a small lever compared with the code. Reducing allocation in a hot path, fixing an N+1 query pattern, bounding a cache, adding a timeout or batching downstream calls typically gives improvements of tens of percent or more, while a carefully tuned flag often gives a few percent on one JDK version. Code improvements also survive upgrades and help every collector. So the organisation's tuning culture should point people at profiles and allocation data first, and treat flags as the last step, for problems that remain after the code is reasonable.
| Lever | Typical gain | Survives JDK upgrades? |
|---|---|---|
| Regular JDK upgrades | steady gains every release | it is the upgrade |
| Allocation and data structure fixes | large in hot paths | yes |
| Architecture: caching, batching, timeouts | often the largest | yes |
| Heap size fitted to measurement | moderate, avoids incidents | mostly |
| Fine-grained GC flags | small, workload-specific | often not |
5Cleaning Up the 40 Flags Safely
For the service itself, we run a structured cleanup. First, list every flag with what it does on the current JDK; obsolete flags that only produce Ignoring option warnings can go immediately, because they already do nothing. Second, group the remaining flags: those that fit the environment (heap percentage, GC logging, heap dump on OOM), those that tune the collector, and those whose purpose is unknown. Third, remove the tuning and unknown groups in small batches on a canary, comparing latency, throughput, GC CPU and memory with the current configuration under the same traffic for at least a daily cycle.
Most services end up with five to ten flags. Any flag that measurably helps stays, now with a written reason. Any that does not is gone, and the experiment log records why, so the question does not come back.
- Inventory all 40 flagswhat does each do on this JDK?
- Obsolete or ignored?YesRemove nowNoGroup: environment, tuning, unknown
- Remove a small batch on a canary
- Latency, GC CPU or memory worse?YesRestore, document the reasonNoKeep removed
- Repeat until each flag has a reason
5 steps in order. Play them, or step through them one at a time.
6Changing the Culture
The lasting change is in habits. The platform team maintains a small approved flag set in the base image, perhaps eight options for heap percentage, OOM handling, GC logging and JFR, each with a reason. Adding anything beyond it requires a measurement in the pull request, and reviewers ask for it. The JDK upgrade process includes a review of every service's extra flags. And most importantly, engineers learn the method: define the goal, measure, find where time goes, change one thing, record the result. People who know the method stop copying flags, because they know a flag is a hypothesis to be tested.
Leaders reinforce this by praising removals as well as additions. A pull request that deletes 30 flags and shows equal or better numbers is a good piece of engineering, and saying so publicly changes what people think good tuning looks like.
7Follow-up questions
What if removing a flag causes an incident?
That is why removals go to a canary first with automatic comparison, and in small batches. If one causes a regression, we restore it and, for the first time, write down what it protects. That knowledge has value too.
How do we stop teams from adding flags in a hurry during incidents?
Allow emergency changes, but require a follow-up: within a week the flag gets a measurement or is removed. A short template in the incident review asks whether any JVM options were changed and whether they are still needed.
Is there ever a case for many flags?
Some specialised systems, such as low-latency trading or very large heaps, do need careful tuning. Even then, each flag should be measured and documented, and the set should be reviewed on upgrades. Many flags with reasons is acceptable; many flags without reasons is not.
8Conclusion
In this answer, we saw that flags accumulate because adding is easy and removing feels risky. The organisation should treat flags as code with an owner and a reason, recognise that modern JDK defaults and regular upgrades make most old flags unnecessary, put tuning effort into code, allocation and architecture, remove unexplained flags in small canaried batches, keep a small approved base set that requires measurements for additions, and teach the method of tuning rather than lists of flags.
Open with
My stance is that a JVM flag is code. It changes production behaviour, so it needs an owner, a written reason and a link to the measurement, and it gets reviewed on every JDK upgrade.
Then, if they want more
A flag nobody can explain is like dead code: we remove it, carefully, with a test. For this service I'd inventory all 40, drop the obsolete ones immediately, since they already do nothing, then remove the tuning and unknown ones in small batches on a canary, comparing latency, GC CPU and memory over a daily cycle.
Most services end with five to ten flags. The wider point is that the JDK has improved a lot: container support, G1 getting better every release, generational ZGC, metaspace, the JIT. Many old flags fight those improvements, and they block upgrades, which are the highest-return performance practice we have because every service gets the gains for free.
Real tuning effort should go into code and architecture, like allocation in hot paths, query patterns, caches and timeouts, because those gains are bigger and survive upgrades.
To change the culture, the platform keeps a small approved base set, additions need a measurement in the pull request, and we teach the method: define the goal, measure, change one thing, record it. And I'd publicly praise a pull request that deletes 30 flags with equal numbers, so removal is seen as good engineering.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 15, Java 21, Java 9
- 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 "A long-lived service carries 40 JVM flags added over a decade, many copied from old...": https://scrivio-interview-library.netlify.app/java/jvm-tuning/f877a68dec/