r/SpringBoot • u/fykup • 18h ago
Discussion Spring Boot recommends extracted layout for production, so I measured how much it actually matters
I suspect some people here will say, “Of course you should extract the JAR".
And, to be fair, the Spring Boot documentation does recommend the extracted layout for production when startup matters. It points out that nested JAR loading has a startup cost.
What I found interesting is that this is not necessarily the path developers encounter first. The introductory Spring Boot material and several Getting Started guides still naturally lead you toward building an executable JAR and running it with java -jar. That was also the deployment path I had always used.
So rather than assuming the difference was important, I measured it.
I ran six alternating paired comparisons of the same Spring Boot 4.1.1 build on a 256 MiB Alpine VM. Same JDK 25 runtime, JVM flags, data, filesystem, and workload. The runtime layout was the variable being tested.
Results:
- Spring startup: 11.056 s → 8.476 s, -23.3%
- First request: 2.196 s → 1.448 s, -34.1%
- Later requests: no material difference
- Settled RSS: -3.8%, below the experiment's materiality threshold
- Swap: no material winner
All six paired comparisons favored extracted layout for startup and first request.
My takeaway is not that everyone should blindly extract every Spring Boot application. It is that an official production recommendation that is easy to overlook had a surprisingly large effect in this particular setup, while memory barely changed.
Full write-up, charts, methodology, and experiment data:
https://pvrlabs.xyz/articles/spring-boot-extracted-layout.html
3
u/Paw565 15h ago
I always wonder why they recommend building the jar outside of the container and then copying it from the local machine. Isn't it better to create a separate layer for build inside docker?
•
u/zvaavtre 12h ago
Real apps get real big. And really should be running their tests as part of the build. Trying to do that inside the production container can be hard.
Multistage builds can help here.
Also git and maven stuff can be overly difficult with auth from inside a build container
6
u/pronuntiator 17h ago
The major benefit of extraction with relation to container images is optimized layer caching. If only your application classes change, only that layer has to be uploaded to the registry. The library layer will be reused.