Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

List the main costs and limitations of building a Spring Boot application as a GraalVM native image compared with running on the JVM.

A native image trades build-time cost and run-time flexibility for fast startup and low memory. Builds take minutes and several GB of memory; peak throughput can be lower than a warmed JIT (Oracle GraalVM's profile-guided optimisation narrows the gap); GraalVM Community offers only the Serial and Epsilon collectors, with G1 available in Oracle GraalVM on Linux; debugging, profiling and Java agents work differently; and dynamic features need metadata while Spring's conditional beans are fixed at build time.

Why this question is asked

Native images are easy to sell with a single number: a service that started in three seconds now starts in eighty milliseconds. Interviewers ask for the costs because a senior engineer needs to know what is given up to get there, and whether those costs matter for a particular service. In this answer, we will go through each cost in turn: build time and resources, peak performance, garbage collection choices, the tooling we lose or must replace, and the closed-world limits on dynamic features and Spring configuration. At the end, a table puts them side by side with the JVM.

1A Quick Recap of What a Native Image Is

GraalVM's native-image tool analyses the application from its entry point, keeps only the reachable code (the closed-world assumption), compiles it ahead of time to machine code and links it with a small runtime called Substrate VM into a single executable. Every cost below follows from this: work that the JVM does lazily at run time, with full knowledge of what the program actually does, is done once at build time with only what static analysis can see.

2Cost 1: Long, Heavy Builds

A jar builds in seconds. A native image of a typical Spring Boot service takes two to ten minutes, because the analysis covers the whole application and all its libraries and the compiler optimises every reachable method. It also uses a lot of memory, commonly 4 to 10 GB, and several CPU cores. On a developer laptop this breaks the quick edit-run loop, which is why developers keep working on the JVM; in CI it means larger runners and slower pipelines. The executable is also specific to one operating system and CPU architecture, so building for Linux on ARM and on x86 means two builds.

Shell
$ time ./gradlew bootJar
BUILD SUCCESSFUL in 9s
$ time ./gradlew nativeCompile
Finished generating 'orders' in 3m 12s.
Peak RSS: 6.84GB of 15.4GB (44.4% of system memory) # reported by native-image
BUILD SUCCESSFUL in 3m 31s

3Cost 2: Lower Peak Throughput Without Profiles

The JVM's JIT compiler watches the program run: which branches are taken, which concrete types appear at a call site, which methods are hot. It uses these profiles to inline aggressively and to optimise for the real case, and it can recompile when behaviour changes. An ahead-of-time compiler has no run-time profile, so it must make safer, more general choices. For a long-running service under steady load, the warmed JIT version often reaches higher throughput and lower latency per request than the native one.

Oracle GraalVM offers profile-guided optimisation (PGO): we build an instrumented image, run it under a representative workload to collect a profile, and build again using it. This closes much of the gap. GraalVM Community does not include PGO.

4Cost 3: Fewer Garbage Collector Choices

On the JVM we can choose G1, ZGC, Parallel or Serial to match the workload. A native image built with GraalVM Community offers the Serial GC, the default, and Epsilon, which never collects and is only for very short-lived programs. Serial collects with one thread and stops the application while it does, which is fine for small heaps and short runs but can produce longer pauses for services with large heaps and heavy allocation. Oracle GraalVM adds G1 for native images on Linux, selected at build time with --gc=G1. Collector options therefore depend on which distribution and platform we use.

5Cost 4: Tooling Works Differently

Much of the Java tooling we rely on assumes a JVM with bytecode. A native image has no bytecode, so Java agents such as APM agents that instrument classes at load time cannot be attached in the usual way; observability moves to libraries such as Micrometer and OpenTelemetry's SDK, or to agents that support native builds. Debugging uses native debuggers such as gdb with debug information generated by the -g option, rather than the usual JDWP attach from an IDE. JFR, heap dumps and some jcmd support exist but must be enabled at build time with --enable-monitoring, and the set of supported features differs from the JVM and between versions, so check your version. Thread dumps, allocation profiles and the familiar JVM metrics may look different or be missing.

Shell
$ native-image -jar orders.jar -o orders -g --enable-monitoring=heapdump,jfr
$ ./orders -XX:+FlightRecorder -XX:StartFlightRecording=filename=rec.jfr # JFR, when enabled at build
$ gdb ./orders # debugging with -g symbols

6Cost 5: Dynamic Features and Fixed Configuration

Under the closed-world assumption, nothing can be loaded or discovered at run time that the build did not see. Reflection, dynamic proxies, resources and Java serialization work only with reachability metadata, which Spring's AOT step, the GraalVM Reachability Metadata Repository and our own hints must provide. Code that generates bytecode at run time, or loads plugin jars, cannot work.

For Spring Boot there is one more consequence. The AOT step evaluates the application context at build time, so @Profile, @ConditionalOnProperty and similar conditions decide once, during the build, which beans exist. Property values are still read at run time, but a service that switches beans per environment through runtime configuration will not do so as a native image.

Native image compared with the JVM
AspectJVM (JIT)Native image
Startup and memoryseconds, higher memorymilliseconds, much lower memory
Buildseconds, smallminutes, 4 to 10 GB, per platform
Peak throughputhigh after warmupoften lower; PGO in Oracle GraalVM
Garbage collectorsG1, ZGC, Parallel, SerialSerial, Epsilon; G1 in Oracle GraalVM on Linux
Agents, debugging, profilingfull Java toolingdifferent tools, enabled at build
Dynamic features, conditional beanswork at run timeneed metadata; beans fixed at build

7Follow-up questions

When are these costs worth paying?

When startup and memory dominate: functions, scale-to-zero services, CLI tools, short batch jobs and small services that scale out often. For long-running, high-throughput services, the JVM usually wins, possibly with class data sharing or the JDK AOT cache for faster startup.

Can we keep using our APM vendor?

Only if the vendor supports native images, usually through a library or OpenTelemetry rather than a Java agent. This should be checked before converting a service, because losing observability is a serious operational cost.

Does the binary run on any Linux machine?

It runs on the operating system and architecture it was built for, and by default links dynamically against the C library, so the base image must provide a compatible one. Building inside the same base image used in production, as Buildpacks do, avoids surprises.

8Conclusion

In this answer, we went through the main costs of a native Spring Boot application: long builds that need several GB of memory and one build per platform, lower peak throughput without run-time profiles unless Oracle GraalVM's PGO is used, fewer GC choices in GraalVM Community, debugging, profiling and agents that work differently, and the closed-world limits that make dynamic features need metadata and freeze Spring's conditional beans at build time.

What to say in the interviewAbout 80 seconds aloud

Open with

Native images give fast startup and low memory, but they cost in five places. Builds are much longer, minutes instead of seconds, and need several gigabytes of memory, and each build is for one OS and architecture.

Then, if they want more

Peak throughput can be lower than a warmed-up JVM, because the ahead-of-time compiler has no runtime profiles to guide inlining and optimisation; Oracle GraalVM has profile-guided optimisation to close part of that gap, Community doesn't.

Garbage collection choices are limited: in GraalVM Community you get the Serial GC, which is the default, and Epsilon, while G1 is available in Oracle GraalVM on Linux.

Tooling is different: Java agents for APM don't attach the usual way, debugging is with gdb and debug symbols rather than JDWP, and JFR or heap dumps must be enabled at build time with --enable-monitoring, with features varying by version.

And because of the closed world, reflection, proxies, resources and serialization need metadata, runtime class loading doesn't work, and in Spring the AOT step fixes the bean set at build time, so @Profile and @ConditionalOnProperty can't change beans at runtime.

So I'd use native for functions, CLI tools and services that scale often, and keep the JVM for steady, high-throughput services.

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 "List the main costs and limitations of building a Spring Boot application as a GraalVM...": https://scrivio-interview-library.netlify.app/spring-boot/native-and-aot/a515a948a9/