Quick revision
The short answer
I would sort the 20 services by how much they gain from fast startup and low memory against how much they would lose or risk. Good candidates are short-lived or scale-to-zero services, CLI tools, functions and small services that scale often; poor candidates are long-running, high-throughput services where JIT peak performance matters, or services built on libraries without native support. For each candidate I would check library compatibility and use of dynamic features, estimate the extra build time and CI cost, and then pilot two or three services, comparing memory, latency and operational effort before deciding on the rest.
What to remember
In this answer, we assessed 20 services for native images by the value of fast startup and low memory against peak performance and compatibility. Short-lived, scale-to-zero, CLI, function and frequently scaling small services are good candidates; steady high-throughput services and those with unsupported dynamic libraries are poor ones. We checked libraries and dynamic features with a native build spike, priced the extra build and CI cost, and piloted a few services before deciding for the rest.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would sort the 20 services by how much they gain from fast startup and low memory against how much they would lose or risk. Good candidates are short-lived or scale-to-zero services, CLI tools, functions and small services that scale often; poor candidates are long-running, high-throughput services where JIT peak performance matters, or services built on libraries without native support. For each candidate I would check library compatibility and use of dynamic features, estimate the extra build time and CI cost, and then pilot two or three services, comparing memory, latency and operational effort before deciding on the rest.
Why this question is asked
A request to move everything to native images usually starts with a real goal, saving memory and money, and a tool that is good at it. But native images are not free and do not suit every workload, and converting 20 services blindly can cost months and leave some services slower than before. Interviewers ask this scenario to see whether we can assess candidates with evidence and protect the goal rather than the tool. In this answer, we will recap what native images give and take away, define good and poor candidates, check compatibility and build cost, and run a pilot that turns the assessment into a decision.
1A Quick Recap of the Trade
A GraalVM native image is compiled ahead of time from the code that static analysis finds reachable. It starts in tens of milliseconds and uses much less memory than the same service on the JVM, often a third to a half, because there is no JIT compiler, no class loading and no unused class metadata.
What it takes away is just as important. Peak throughput is often lower than a fully warmed JIT, because the ahead-of-time compiler cannot use run-time profiles (Oracle GraalVM's profile-guided optimisation narrows the gap). GraalVM Community offers fewer garbage collectors. Builds take minutes and gigabytes of memory. And reflection, proxies and resources need metadata. So the question for each service is whether the memory and startup gain is worth those costs for that particular workload.
2Good and Poor Candidates
A service is a good candidate when startup time or memory per instance dominate its cost. Short-lived and scale-to-zero services pay for startup on every cold start. Command-line tools and batch utilities run for seconds, so JVM startup is most of their run time. Functions on serverless platforms are billed by memory and duration. Small services that scale out often, or run many small replicas, save memory on every replica and add capacity faster.
A service is a poor candidate when it runs hot for a long time, because there the JIT's profile-driven optimisation pays off and memory is a smaller share of its cost: a pricing engine at 5,000 requests per second, a Kafka streams application, a search service with a large heap. Services that rely on dynamic features, such as runtime bytecode generation, plugins loaded at run time, or libraries with no native support, are also poor candidates until those libraries catch up.
| Service | Profile | Libraries | Verdict |
|---|---|---|---|
| report-cli | runs 20 s nightly | Spring Boot, JDBC | strong candidate |
| notification-api | scales 2 to 30, spiky | Boot web, Kafka client | candidate, pilot |
| pricing-engine | steady 5k req/s, 8 GB heap | Boot, custom caches | stay on JVM |
| legacy-rules | loads rules classes at run time | Drools, reflection | not compatible yet |
3Checking Compatibility and Dynamic Features
For each candidate we list its dependencies and check them: Spring Boot's own starters are supported, many popular libraries have entries in the GraalVM Reachability Metadata Repository, and some publish their own metadata. Then we look at the service's own code for dynamic features: Class.forName with names from configuration, dynamic proxies outside Spring, resources loaded by computed path, Java serialization, and beans chosen at run time by profile or property, which Spring AOT fixes at build time.
The quickest real check is to try it. A spike of a day or two per service, running the native build and the native tests, surfaces most problems: missing metadata appears as build warnings or test failures, and incompatible libraries fail early. We record the effort needed to fix each, because that effort is part of the cost.
4Estimating Build and CI Cost
A native build of each service can take five to ten minutes and need 8 GB or more of memory, against under a minute for a jar. For 20 services built on every merge, that is real CI capacity and slower feedback. We estimate it concretely: number of builds per day times native build minutes times runner cost, plus the effort of keeping hints current as dependencies change. Most teams keep the JVM build for pull requests and build native only on the main branch, which halves the impact but delays the discovery of native problems. All of this goes into the comparison next to the memory saving.
5Running the Pilot and Deciding
We pick two or three services from the good-candidate list, ideally of different shapes, and run them as native images in a real environment for a few weeks, alongside or instead of the JVM version. We compare memory per replica, startup time, p50 and p99 latency under real traffic, throughput per CPU, build time, and the number of native-specific issues and hours spent on them. If the numbers support it, we move the rest of the good candidates and write down the conditions, so new services can make the same call. If they do not, we have learned it cheaply, and the cheaper options, such as right-sizing the JVM heap, class data sharing or the JDK AOT cache, may meet the memory goal instead.
- Classify by workload shapeshort-lived, spiky, steady, heavy
- Gains from startup or memory?YesCheck libraries and dynamic featuresNoStay on JVM, right-size instead
- Native build and tests pass with modest effort?YesAdd to pilot listNoRevisit when libraries support it
- Pilot 2 or 3 servicesmemory, latency, build time, effort
- Roll out to proven classwrite the criteria down
5 steps in order. Play them, or step through them one at a time.
6Follow-up questions
If the goal is saving memory, are there cheaper options than native images?
Yes. Many Java services simply have oversized heaps or memory requests, so right-sizing with MaxRAMPercentage often saves a lot. Lowering thread counts, using a smaller base image and enabling class data sharing also help. Native images give the largest reduction, but we should compare against those cheaper steps.
How do we know peak throughput is worse for a service?
We measure it. A load test at the real traffic shape, with the JVM version warmed up, compared against the native build at the same CPU and memory, shows throughput per core and p99. Some services lose little; others lose a lot.
What about developer experience?
Developers still run and debug on the JVM day to day, because native builds are slow. The risk is that native problems are found late, which is why native tests in CI are part of the deal for any service we convert.
7Conclusion
In this answer, we assessed 20 services for native images by the value of fast startup and low memory against peak performance and compatibility. Short-lived, scale-to-zero, CLI, function and frequently scaling small services are good candidates; steady high-throughput services and those with unsupported dynamic libraries are poor ones. We checked libraries and dynamic features with a native build spike, priced the extra build and CI cost, and piloted a few services before deciding for the rest.
Open with
I would not convert all 20; I would assess each against the goal, which is saving memory. Native images give much lower memory and millisecond startup, but cost long builds, metadata work and often lower peak throughput than the JIT.
Then, if they want more
So the good candidates are services where startup and memory dominate: short-lived jobs and CLI tools, functions, scale-to-zero services and small services that scale out often or run many small replicas.
Poor candidates are long-running, high-throughput services where the JIT's peak performance matters, and services relying on libraries or features that don't work well natively, like runtime class loading or bytecode generation.
For each candidate I would list the dependencies, check the GraalVM reachability metadata repository and library docs, and look for dynamic features in our own code, then do a short spike running nativeCompile and nativeTest to see real problems and effort.
I would also estimate the build cost: five to ten minutes and 8 GB per native build, times builds per day, plus keeping hints current. Then I would pilot two or three services of different shapes for a few weeks and compare memory, startup, p99 latency, throughput per core and operational effort.
If it pays off, we roll it out to that class of service; if not, right-sizing heaps or CDS may meet the memory goal more cheaply.
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.
- Official documentation
- Kubernetes documentation, Spring Boot reference
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 "You are asked to move 20 Spring Boot services to native images to save memory. How would...": https://scrivio-interview-library.netlify.app/spring-boot/native-and-aot/668f21dd18/