Quick revision
The short answer
I would start from the need, not the technology: fast scale-out, lower memory, or short-lived jobs. Class data sharing gives a moderate startup gain with almost no code change, so it is the default first step; Spring AOT with GraalVM native images gives large gains in startup and memory but restricts reflection and dynamic behaviour and makes builds heavier; checkpoint/restore gives very fast startup on the JVM but needs a JDK and platform that support it and correct handling of open resources. We pilot on a few representative services and weigh the measured gain against build and operational complexity.
What to remember
In this answer, we decided between three ways to move startup work out of the runtime. We started from the need, fast scale-out, memory or short-lived jobs, and noted that many services need none of this. CDS gives a moderate gain with little change and suits every service as a default. AOT with native images gives large gains in startup and memory but restricts reflection and dynamic configuration and makes builds heavier. Checkpoint/restore gives warm, instant starts but needs platform support and careful handling of resources. A pilot on representative services, measuring both the gain and the cost, decides 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 start from the need, not the technology: fast scale-out, lower memory, or short-lived jobs. Class data sharing gives a moderate startup gain with almost no code change, so it is the default first step; Spring AOT with GraalVM native images gives large gains in startup and memory but restricts reflection and dynamic behaviour and makes builds heavier; checkpoint/restore gives very fast startup on the JVM but needs a JDK and platform that support it and correct handling of open resources. We pilot on a few representative services and weigh the measured gain against build and operational complexity.
Background to this question
Startup time used to matter once a week, when we deployed. With containers and autoscaling it matters every time traffic rises, every time a pod is rescheduled and every time a serverless function is invoked cold. Spring now offers several ways to move startup work out of the runtime, and a twenty-year engineer is expected to choose between them for a whole company, not just try one on a laptop. In this answer, we will see what each option moves and why it helps, compare them, look at what they cost, and then go through a decision process with a pilot.
1Start From the Need
Before comparing technologies, we write down which problem we are solving, because each option is best at a different one. If the problem is fast scale-out, say a checkout service that must add ten pods in a minute when a sale starts, we care about time to first good response, including warm-up. If the problem is memory, for example hundreds of small services each holding 600 MB, we care about resident memory per instance. If the problem is short-lived work, such as batch jobs or functions that run for a few seconds, startup can be most of the cost, and peak throughput matters less.
A service that starts once a day and runs for weeks may not need any of this. Saying so is part of a good answer: the right adoption for many services is none.
2What Each Option Moves Out of the Runtime
A Spring Boot service spends its startup on three kinds of work: the JVM loading and verifying thousands of classes, Spring analysing configuration and creating beans, and the JIT compiler warming up the hot code. The three options remove different parts of that work.
Class data sharing (CDS) stores parsed and verified classes in an archive created in a training run, so the next start maps them from the archive instead of loading them again. Spring Boot 3.3 and later can extract the jar into a layout that suits CDS and create the archive with a training run that exits after the context refreshes. Newer JDKs extend the idea with an AOT cache that also stores linked classes and profiling data (JEP 483 in JDK 24, extended in JDK 25; check your version). Gains are moderate, often a fifth to a half of startup time, and the code does not change.
Spring AOT processing runs at build time: it evaluates the configuration, decides which beans exist and generates plain Java code that registers them, so the runtime skips most of the analysis. On its own on the JVM, its gain is small. Its main purpose is GraalVM native images, which compile the whole application ahead of time into a native executable that starts in well under a second and uses much less memory.
Checkpoint/restore (CRaC in the JDK, supported by Spring Framework 6.1 and later) starts the application, warms it, and saves a snapshot of the whole running process to disk. Starting a new instance restores that snapshot, already warm, in milliseconds.
| CDS / AOT cache | AOT + native image | Checkpoint/restore | |
|---|---|---|---|
| Startup gain | moderate | large | very large, already warm |
| Memory | slightly lower | much lower | similar to the JVM |
| Code changes | almost none | reflection hints, fewer dynamic features | close and reopen resources |
| Build impact | one training run | long, memory-hungry native build | checkpoint step in the pipeline |
| Runtime needs | same JDK as training | none, native executable | JDK and OS with CRaC support |
| Peak throughput | same as JVM | can be lower without profile-guided builds | same as JVM |
3What Native Images Cost
Native images assume a closed world: everything that can run must be known at build time. Spring's AOT engine handles the common cases, but reflection, dynamic proxies, resources loaded by name and serialisation used by libraries need hints, entries that tell the native compiler to keep them. Spring provides a RuntimeHints API and many libraries ship hints, but an older library that uses reflection unexpectedly fails at runtime, not at build time.
Configuration also becomes more fixed. Because bean definitions are decided at build time, @Profile and @Conditional choices that depend on the environment are evaluated during the build, so a single image cannot switch beans on a property at startup the way a normal Spring Boot jar can. Builds take several minutes and gigabytes of memory, and debugging and profiling tools differ from the JVM ones. These costs are worth paying for functions and small, stable services; for a large service with many libraries they can outweigh the gain.
4What Checkpoint/Restore Costs
Checkpoint/restore is attractive because the restored process is already warm, but it captures everything in memory. Open sockets and files cannot survive the snapshot, so beans that hold connections must close them before the checkpoint and reopen them after restore. Spring helps: its Lifecycle beans are stopped before the checkpoint and started again after restore, so a well-behaved connection pool or message listener handles it. Our own code that opens resources in @PostConstruct and never lets go is exactly what breaks.
There are platform and security questions too. CRaC needs a JDK build that supports it, from some vendors, and currently Linux; check which platforms your vendor supports. The snapshot contains whatever was in memory, including secrets and random number generator state, so it must be stored and handled like a secret, and values that must differ per instance have to be refreshed after restore.
5A Decision Process With a Pilot
For a company I would make CDS, or the JDK AOT cache, the default for every service through the shared build and container image, because it costs almost nothing and helps everyone a little. Then I would pick two or three representative services for the heavier options: one small stateless API, one large service with many libraries, and one job or function.
For each pilot we measure the same numbers: time to first successful request, time to steady latency, resident memory, peak throughput under load, build time and image size, plus the engineering hours the change took. A native image that cuts startup from 8 seconds to 0.2 seconds is a clear win for a function invoked cold thousands of times a day; the same gain on a service that starts twice a week is not worth a 10 minute build and a new class of runtime failures.
- Does startup time or memory hurt us?YesMeasure what exactly hurtsNoUse the shared CDS default only
- Enable CDS or the AOT cachedefault for all services
- Short-lived, or extreme scale-out or density?YesPilot a native imageNoStay on the JVM
- Need warm JVM performance with instant start?YesPilot checkpoint/restoreNoKeep CDS
- Compare measured gain with build and ops costadopt per service class
5 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Does Spring AOT help on the JVM without a native image?
Somewhat. Running the AOT-generated code on the JVM with spring.aot.enabled=true skips configuration analysis at startup, which saves a little time, and it pairs well with CDS. The large gains come from native images, which require the AOT step.
Why can a native image have lower peak throughput?
Because the JVM's JIT compiler optimises using what it sees at runtime, and a native image is compiled before it has seen any traffic. Profile-guided optimisation, available in some GraalVM editions, narrows the gap; for services that run for days under heavy load, the JVM often stays faster.
How do these choices affect the bean lifecycle?
AOT moves bean definition decisions to build time, so conditions are fixed early. Checkpoint/restore adds a stop and start of Lifecycle beans around the snapshot, so resources must be opened in start() and closed in stop() rather than only in @PostConstruct. CDS does not change the lifecycle at all.
7Conclusion
In this answer, we decided between three ways to move startup work out of the runtime. We started from the need, fast scale-out, memory or short-lived jobs, and noted that many services need none of this. CDS gives a moderate gain with little change and suits every service as a default. AOT with native images gives large gains in startup and memory but restricts reflection and dynamic configuration and makes builds heavier. Checkpoint/restore gives warm, instant starts but needs platform support and careful handling of resources. A pilot on representative services, measuring both the gain and the cost, decides the rest.
Open with
I would start by asking what problem we have, because the options solve different ones. Fast scale-out cares about time to a warm first response, density cares about memory, and short-lived jobs or functions care about startup above all.
Then, if they want more
Many long-running services need nothing. For the company default I would turn on class data sharing, or the newer JDK AOT cache, in the shared build: Spring Boot 3.3 and later supports the training run, it needs almost no code change, and it gives a moderate startup gain. Then I would pilot the heavier options on a few representative services.
Spring AOT with GraalVM native images gives the biggest gains in startup and memory, but it is a closed world: reflection and proxies need hints, profiles and conditions are fixed at build time, builds are long, and peak throughput can be lower.
Checkpoint/restore restores an already warm JVM in milliseconds, but it needs a JDK and OS with CRaC support, resources must be closed and reopened through Lifecycle callbacks, and the snapshot must be treated as a secret.
For each pilot I would measure time to first request, memory, throughput, build time and effort, and adopt per class of service where the gain clearly beats the cost.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 24, Java 25, Spring Boot 3.3, Spring Framework 6
- 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
- Spring Framework reference, Core technologies
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 "Spring offers several ways to move startup work out of the runtime: AOT processing...": https://scrivio-interview-library.netlify.app/spring-boot/bean-lifecycle/e984997bb3/