Native image provides a way to build and run Spring Boot applications with different characteristics than a regular JVM deployment:
-
The output is a native executable that contains your application with a subset of the JDK and the dependencies required to run it.
-
In practice the executable would likely be shipped in an highly optimized container image (FROM scratch
Docker image is supported) with reduced surface attack which is good fit with Kubernetes.
-
Startup time is almost instant and peak performance is available immediately, allowing support for scale-to-zero (serverless) applications including for regular Spring Boot web applications.
-
Memory consumption is reduced, which is a good fit for systems split into multiple microservices.
As you would expect, native images are not a free lunch and those interesting capabilities come with a few drawbacks:
-
GraalVM native is a young platform which is far less mature than the JVM.
-
This new flavor of Java is not yet well supported and tested by JVM libraries.
-
It requires initialization, resources, reflection and proxy explicit configuration.
-
Build time is very long and build memory consumption is high.
-
Lower throughput and higher latency (more details ).
Obviously native image is a moving target and some of those characteristics are likely to evolve in the future. The Spring team currently collaborates actively with the GraalVM team in order to ensure Spring and more globally the JVM ecosystem integrated via Spring Boot works well when compiled as native images. This effort includes fixes and new features in GraalVM native, changes to Spring itself, but also additional work to improve testability and maintainability with this GraalVM native platform.
It is also worth noticing that the scope of native images is now wider than GraalVM since Mark Reinhold has recently announced Project Leyden, an effort to standardize native images at Java platform level.