Cloud Native 8 min read

Spring Native: Achieving Sub‑100 ms Startup for Spring Boot Applications

This article introduces Spring Native, explains how native images built with GraalVM can reduce Spring Boot startup time to under 100 ms, walks through environment setup, project initialization, Docker image creation, performance testing, and provides troubleshooting tips for common issues.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
Spring Native: Achieving Sub‑100 ms Startup for Spring Boot Applications

What is Spring Native?

Spring Native is a Spring‑provided technology that leverages GraalVM’s native image compiler to build Spring applications into native executables, enabling cloud‑native deployment with instant startup, higher peak performance, and lower memory consumption compared to the traditional JVM.

Why is it powerful?

Native images compile Java code ahead‑of‑time into a standalone binary that includes application classes, dependencies, runtime libraries, and a subset of the JDK. The resulting executable runs without a JVM, starts in less than 100 ms, delivers peak performance immediately, and reduces memory usage, making it ideal for microservices, serverless functions, and containerized workloads.

Key benefits of GraalVM native images (as quoted from the GraalVM website): The output is a native executable containing the application, a JDK subset, and required dependencies. It can be packaged as an ultra‑optimized Docker image (FROM scratch), reducing attack surface and fitting Kubernetes well. Startup time is virtually instantaneous, enabling zero‑cold‑scale serverless scenarios. Memory consumption is significantly lower, which is advantageous for microservice architectures.

Getting Started

The author demonstrates a hands‑on comparison between a regular Spring Boot project and a Spring Native project.

Environment

Computer: MacBook Pro 13‑inch (2017)

OS: macOS Big Sur 11.2

IDE: IntelliJ IDEA 2021.2.2 (Ultimate)

OpenJDK: 11.0.12

Maven: 3.6.3

Docker Desktop: 4.0.1

Project Initialization

Use https://start.spring.io/ to generate a project with Maven, Spring Boot 2.5.8, and JDK 11. Add the following dependencies:

spring native

spring web

Download the generated ZIP and import it into the IDE.

Running the Project

Two ways to start a Spring Native application are provided in the generated README:

Build a Docker image with the Maven plugin and run the container.

Build a native executable locally and run it directly.

Below is the Docker‑based approach used in the demo.

Step 1: Build the Docker image

$ ./mvnw spring-boot:build-image

This step may take a while and can fail if resources are insufficient.

Step 2: Run the image

$ docker run --rm spring-native-demo:0.0.1-SNAPSHOT

The application starts instantly.

Performance Comparison

Scenario 1 – Spring Native : The author observed a best‑case startup time of 143 ms on the test machine, close to the claimed 79 ms.

Scenario 2 – Regular Spring Boot : The same application started in 2.091 seconds.

Thus, Spring Native achieved roughly a 15× speed‑up on the author’s hardware.

Conclusion

Spring Native dramatically reduces startup latency and memory usage, making it well‑suited for cloud‑native, containerized, and serverless environments, albeit at the cost of longer build times and fewer runtime optimizations.

FAQ & Troubleshooting

Problem 1: Maven dependency download failures due to poor network.

<mirror>
  <id>aliyunmaven</id>
  <mirrorOf>*</mirrorOf>
  <name>central</name>
  <url>https://maven.aliyun.com/repository/central</url>
</mirror>

Problem 2: Docker image build fails with out‑of‑memory errors. Increase Docker’s memory allocation.

performanceDockerSpring BootGraalVMnative-imageSpring Native
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.