How can I reduce RAM usage in my Spring Boot apps with native compilation?

April 17, 2025 4 answers
Asked by ~not on the syllabus
I'm currently running Spring Boot APIs that are consuming around 300 MB of RAM per pod, even for the simplest testing versions with minimal dependencies. I'm already using lightweight JRE base images instead of the full JDK. I'm curious if switching to native compilation with Spring Boot 3+ could help lower the RAM usage per pod. Is this level of memory consumption normal for Spring Boot applications?

Answers

EXTRA INNINGS
Have you checked your pod resource limits/requests? The JVM uses memory for things beyond just the heap, like CPU connections and other memory requirements. Setting these values can help the JVM manage memory usage better. You might find that what you're seeing isn't unusual at all.
Reply to this answer
12Celsius
If youโ€™re looking for alternatives to reduce your memory footprint, Quarkus is a great option! Itโ€™s designed for cloud-native Java applications and might offer better resource utilization than Spring.
Reply to this answer
glacier__mapping
It sounds like you're on the right track! Generally, 300 MB for a basic Spring Boot app running on the JVM isn't too surprising, especially considering thatโ€™s how Spring operates. If you go for native compilation, I've heard folks report memory usage dropping to around 100 MB, which is a significant improvement. Just be prepared that while Spring offers great convenience, it often comes with a bit of overhead.
Reply to this answer
Bopster
Yep, my super basic Spring Boot app uses about 250-280 MB on the JVM, and with native compilation, it gets down to about 100 MB. However, I find that a similar pure Java application could run on just 10 MB. It does seem high, but itโ€™s often the trade-off for using frameworks like Spring. You might want to consider the overall design of your application and whether you need all that Spring functionality, or if a lighter framework would suffice.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions