Quick revision
The short answer
Native image is a poor fit when startup is not the problem and the costs are paid anyway: long-running, high-throughput services where a warmed-up JIT gives better peak performance; applications built on heavy reflection, run-time bytecode generation or libraries without native support; teams that cannot afford multi-minute builds and a second test suite; large heaps that depend on the JVM's choice of collectors and tuning; and teams whose diagnostics rely on Java agents and profilers that do not work, or work differently, in a native executable.
What to remember
In this answer, we saw that native image buys startup and footprint with build time, compatibility work, some peak performance and some tooling. It is a poor fit for long-running, high-throughput services where the JIT wins, for applications built on reflection and run-time code generation, for teams that cannot afford long builds and native tests, for large heaps tuned around specific collectors, and for teams whose diagnostics depend on Java agents and profilers.
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.
Native image is a poor fit when startup is not the problem and the costs are paid anyway: long-running, high-throughput services where a warmed-up JIT gives better peak performance; applications built on heavy reflection, run-time bytecode generation or libraries without native support; teams that cannot afford multi-minute builds and a second test suite; large heaps that depend on the JVM's choice of collectors and tuning; and teams whose diagnostics rely on Java agents and profilers that do not work, or work differently, in a native executable.
Background to this question
Native image demos are impressive: a Spring Boot service starting in 80 milliseconds with a third of the memory. It is easy to conclude that every service should be native. A senior engineer is expected to know where that conclusion breaks, and to give concrete reasons rather than a vague sense that it is risky. In this answer, we will recap what native image trades, then go through five situations where the trade is bad, each with the mechanism behind it, and close with a summary table.
1A Quick Recap of the Trade
GraalVM native image compiles the application ahead of time into a standalone executable. It analyses the program at build time under a closed-world assumption, meaning only code the build can see is included, and dynamic features such as reflection must be declared. In return it removes class loading and JIT warmup, so it starts fast and uses little memory.
So native image buys startup time and footprint, and pays with build time, compatibility work, some peak performance and some tooling. It is a good deal when startup and memory dominate the cost of running a service, and a poor one when they do not.
2Reason 1: Long-Running Services Where Peak Throughput Matters
A JIT compiler, the part of the JVM that compiles hot code while the program runs, has an advantage over ahead-of-time compilation: it sees the real workload. It knows which branches are taken, which concrete types appear at each call site, and which methods are hot, and it compiles aggressively for exactly that, deoptimising and recompiling if the behaviour changes. An ahead-of-time compiler must guess.
For a pricing engine that runs for weeks at 5,000 requests per second, startup happens once a week and costs a few seconds, while peak throughput decides how many instances we pay for every hour. If the native executable reaches, say, 15 percent lower peak throughput, we need more instances, which can cost far more than the memory we saved. Profile-guided optimisation, available in Oracle GraalVM, closes much of that gap by feeding a profile from a training run into the build, but it adds another build step and training workload to maintain.
3Reason 2: Heavy Reflection and Run-Time Code Generation
Some applications are dynamic by design. A rules engine that compiles Groovy or JavaScript scripts at run time, a plugin system that loads jars from a folder, an older ORM or serialisation library that generates bytecode on the fly, or a framework without native support all fight the closed world. Generating new classes at run time is not possible in a native executable, and every reflective access needs metadata.
For a typical Spring Boot service with mainstream libraries, Spring's AOT processing and the shared metadata repository cover most of this. But if the core of the application is dynamic, the effort is not a one-off: every new library version, every new plugin and every new reflective path needs metadata and testing, forever.
4Reason 3: Build Time and Testing Cost
A JVM build of a service takes seconds to compile. A native build of a Spring Boot service commonly takes several minutes and needs several gigabytes of memory on the build machine. Multiply that by every pull request and every service, and the CI bill and the feedback loop both grow.
On top of the build, the native executable must be tested as a native executable, because a missing hint passes every JVM test and fails only in the native binary. That means a second test run, usually compiled natively too. A team that already struggles with slow pipelines, or that has no capacity to own native test failures, will find that the cost lands on every change while the startup benefit is felt rarely.
5Reason 4: Large Heaps and GC Tuning
The JVM offers several garbage collectors, such as G1, ZGC and Parallel, with many tuning options, and teams running large heaps often depend on them, for example ZGC for low pause times on a 32 GB heap. A native executable has a smaller choice. GraalVM Community Edition offers the Serial collector, and Oracle GraalVM adds a G1 collector on Linux; the set of tuning flags is smaller as well. Check your GraalVM version for the current list.
A small service with a 200 MB heap is well served by a simple collector. A cache-heavy service with tens of gigabytes of live data, tuned for years around a particular collector, may see longer pauses or need a redesign. In that case the memory saved in JVM overhead is tiny compared with the heap itself, so the main benefit of native image barely applies.
6Reason 5: Diagnostics the Team Relies On
Many operations teams depend on Java agents: an APM agent such as the OpenTelemetry Java agent attached with -javaagent, or security and profiling agents that rewrite bytecode at load time. A native executable has no bytecode to rewrite at run time, so these agents cannot attach; instrumentation must be added at build time instead, if the tool supports it. JFR, JMX, heap dumps and thread dumps are supported to different degrees, often behind build options, and some profilers behave differently. Check your version for what is supported.
If the on-call engineer's first move during an incident is to attach a profiler or take a JFR recording, losing that ability is a real operational cost, even if the service is faster to start.
| Signal | Why it hurts | Usually better |
|---|---|---|
| Runs for weeks, high throughput | JIT peak beats AOT without PGO | JVM with AOT cache |
| Scripts, plugins, bytecode generation | Closed world forbids it | JVM |
| Slow CI, no native test owner | Minutes per build, second test suite | JVM with AOT cache |
| Tens of GB of heap, tuned GC | Fewer collectors and options | JVM with chosen GC |
| APM or profiler agents essential | No run-time bytecode agents | JVM |
| Scale to zero, small and stable | Startup dominates cost | Native image is a good fit |
7Follow-up questions
If native image is a poor fit, how do we still improve startup?
With options that keep the JVM: the AOT cache from JDK 24 and 25, which stores loaded and linked classes and method profiles, CDS, removing unused starters, and lazy initialisation where it makes sense. They give smaller gains but no compatibility cost.
Does profile-guided optimisation remove the throughput gap?
It narrows it considerably for many workloads, because the build then knows the hot paths. But it needs a representative training workload and an extra build step, it is a feature of Oracle GraalVM rather than the Community Edition, and the profile can go stale as the code changes.
Can one service mix native and JVM deployments?
Yes. Spring Boot can build both from the same code, so a team can run the JVM version in long-running clusters and a native version for a scale-to-zero entry point. The cost is testing both, which is worth it only when the two deployments really serve different needs.
8Conclusion
In this answer, we saw that native image buys startup and footprint with build time, compatibility work, some peak performance and some tooling. It is a poor fit for long-running, high-throughput services where the JIT wins, for applications built on reflection and run-time code generation, for teams that cannot afford long builds and native tests, for large heaps tuned around specific collectors, and for teams whose diagnostics depend on Java agents and profilers.
Open with
I would say it is a poor fit whenever startup is not what we are paying for. The first case is long-running, high-throughput services: a JIT sees the real workload and optimises for it, so after warmup the JVM often beats ahead-of-time code, and for a service that restarts once a week, lower peak throughput costs more instances than the startup gain is worth; profile-guided optimisation in Oracle GraalVM helps but adds a training step.
Then, if they want more
Second, applications built on heavy reflection or run-time bytecode generation, like script engines, plugin folders or libraries without native support, because the closed world forbids new classes at run time and every reflective path needs metadata.
Third, teams that cannot afford native builds of several minutes with gigabytes of memory, plus a second, native test suite, since missing hints only fail in the native binary.
Fourth, large heaps that rely on a particular collector like ZGC and years of tuning; native image has fewer collectors and options, and the overhead it saves is small next to a 30 GB heap. Fifth, diagnostics: Java agents such as APM agents cannot attach at run time, and JFR or profilers may work differently.
In those cases I would keep the JVM and use the AOT cache instead.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 24
- 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 "When is GraalVM native image a poor fit for a Java service? Give concrete reasons.": https://scrivio-interview-library.netlify.app/java/startup-and-footprint/73fb3bbe58/