Scrivio Interview library
DesignIntermediate7 min read · updated 12 November 2026

Compare GraalVM native image, CRaC (Coordinated Restore at Checkpoint) and JDK AOT caching (Project Leyden) for reducing startup of Spring Boot services.

GraalVM native image gives the fastest startup and lowest memory, but under a closed-world model with long builds and metadata for dynamic features. CRaC checkpoints an already warmed JVM and restores it in milliseconds, but needs a CRaC-enabled JDK and careful handling of open files, sockets and secrets; Spring supports it. The JDK AOT cache from Project Leyden (JDK 24 and later, starting with JEP 483) stores loaded and linked classes, and in later JEPs method profiles, from a training run, while keeping full JVM behaviour; class data sharing is its simpler predecessor. We choose by startup target, operational constraints and team skills.

Why this question is asked

Startup time has become a first-class concern for Java services: it decides how fast we can autoscale, how long deployments take and whether scale-to-zero is realistic. There are now several ways to attack it, and they work in very different ways. Interviewers ask this design question to see whether we know the mechanism behind each option, because the mechanism explains both the gain and the price. In this answer, we will recap what makes a JVM start slowly, look at class data sharing, the JDK AOT cache, CRaC and native images in turn, put them side by side, and see how to choose.

1A Quick Recap of Where Startup Time Goes

When a Spring Boot service starts on the JVM, time goes into three things. Class loading: finding, parsing, verifying and linking thousands of classes. Framework startup: Spring scanning, evaluating conditions and creating beans. And warmup: running interpreted code until the JIT compiler has compiled the hot paths, which can take a minute or more under load. Each option below removes a different share of this work, which is why their results differ so much.

Step throughWhat each option removes
  1. Class loading and linkingCDS: parsed classes; AOT cache: loaded and linked classes
  2. Spring context startupSpring AOT on the JVM; CRaC and native skip it entirely
  3. JIT warmupAOT cache profiles help start; CRaC restores warm code
  4. Everything abovenative image: done at build time, no JIT at all

4 layers, from the top down. Step through them one at a time.

2Class Data Sharing: The Simple First Step

Class data sharing (CDS) stores the parsed form of classes in an archive file that the JVM maps into memory at startup instead of reading and parsing class files again. The JDK ships a default archive for its own classes, and AppCDS extends it to application classes, created with a training run. Spring Boot 3.3 and later documents a simple way to do it, including starting the context and exiting with spring.context.exit=onRefresh. It typically cuts startup by a fifth to a third, needs no code changes, and keeps everything else about the JVM the same.

Shell
$ java -XX:ArchiveClassesAtExit=app.jsa -Dspring.context.exit=onRefresh -jar app/orders.jar # training
$ java -XX:SharedArchiveFile=app.jsa -jar app/orders.jar
Started OrdersApplication in 2.6 seconds # from 3.8 seconds (example)

3The JDK AOT Cache: CDS Taken Further

Project Leyden is the OpenJDK effort to improve startup and warmup while keeping the JVM's full dynamic behaviour. Its first delivered step, JEP 483 in JDK 24, extends CDS into an AOT cache: during a training run, the JVM records which classes are loaded and links them, and the cache stores them already loaded and linked. JDK 25 made it easier to create (JEP 514, a single -XX:AOTCacheOutput option) and added method profiles from the training run (JEP 515), so the JIT can compile hot methods sooner. The application still runs on a normal JVM with the normal JIT, all collectors and all tools; the only rules are that the JDK version and classpath must match the training run.

Java
# JDK 25: training run writes the cache in one step
$ java -XX:AOTCacheOutput=app.aot -Dspring.context.exit=onRefresh -jar app/orders.jar
# production
$ java -XX:AOTCache=app.aot -jar app/orders.jar
Started OrdersApplication in 1.7 seconds # example; gains grow with each JDK release

Notice that nothing about the application changes. That is the main attraction: the gain is smaller than native or CRaC, but the risk is close to zero.

4CRaC: Restore an Already Warm JVM

Coordinated Restore at Checkpoint (CRaC) takes a different route. We start the application, optionally warm it up with traffic, and then take a checkpoint: an image of the whole process, including the heap, loaded classes and JIT-compiled code, written to disk. Starting a new instance means restoring that image, which takes tens of milliseconds, and the restored JVM is already warm.

The coordination part is the catch. Open files, network sockets and connection pools cannot survive in a snapshot, so resources must be closed before the checkpoint and reopened after restore, through the org.crac API's beforeCheckpoint and afterRestore callbacks. Spring Framework 6.1 and later handles this for its Lifecycle beans, stopping them before the checkpoint and starting them after restore, and can take an automatic checkpoint at startup with -Dspring.context.checkpoint=onRefresh. Other constraints: it needs a CRaC-enabled JDK build (offered by some vendors such as Azul and BellSoft), it currently works on Linux, the checkpoint mechanism may need extra container privileges, and anything in memory at checkpoint time, including secrets and random seeds, ends up in the image file, which must be protected and must not be shared across environments.

Shell
$ java -XX:CRaCCheckpointTo=/opt/crac -Dspring.context.checkpoint=onRefresh -jar orders.jar
# context refreshed, Lifecycle beans stopped, checkpoint written to /opt/crac, process exits
$ java -XX:CRaCRestoreFrom=/opt/crac
Restored OrdersApplication in 0.061 seconds

5Native Image: The Furthest Step

A GraalVM native image moves all of it to build time: static analysis of reachable code, ahead-of-time compilation, and Spring's AOT processing. It starts in milliseconds and has the smallest memory footprint, since there is no JIT, no class metadata for unused classes and no profiling. The price is a closed world: reflection, proxies and resources need metadata, Spring's conditional beans are fixed at build time, builds take minutes and many GB, tooling differs, and peak throughput can be lower than a warmed JIT.

Comparing the options
OptionStartup gainKeeps full JVM?Main constraints
CDS / AppCDSmoderateyestraining run, same JDK and classpath
JDK AOT cache (24+)moderate to largeyestraining run, newer JDK, same classpath
CRaCvery large, warmyes, restoredCRaC JDK, Linux, resources, secrets in image
Native imagevery large, low memoryno, closed worldmetadata, long builds, lower peak, tooling

6Choosing Between Them

We start from the target. If we need startup cut from 6 seconds to 3, CDS or the AOT cache, done once in the build template, is enough and almost free. If we need sub-second startup with full warm performance, for example for aggressive autoscaling, CRaC fits, provided our operations can handle CRaC JDKs, checkpoint images per release and the resource and secret rules. If we need sub-second startup and the smallest memory, for functions or scale-to-zero, a native image fits, provided our libraries support it and the team accepts the build and tooling costs.

Team skills and operations matter as much as the numbers. The AOT cache needs nothing new. CRaC adds a new artefact, the checkpoint image, to the release process. Native images change how teams debug and observe. A reasonable platform default is CDS or the AOT cache for everyone, with CRaC or native offered for the service types that really need more.

7Follow-up questions

Can these options be combined?

Some can. Spring AOT on the JVM combines with CDS or the AOT cache, since one removes framework work and the other class loading. CRaC already includes everything in its snapshot, and a native image does not use CDS or the AOT cache at all.

Why does the AOT cache need a training run?

Because it records what the application actually loads and, in later JDKs, which methods are hot. The training run should look like real startup, for example starting the Spring context; a poor training run gives a smaller gain but never wrong behaviour.

What is the security concern with CRaC?

The checkpoint image contains the process memory, so any secret loaded before the checkpoint is stored in it, and every restored instance shares the same random state unless it is reseeded. Secrets should be loaded after restore and the images treated as sensitive artefacts.

8Conclusion

In this answer, we compared four ways to cut Spring Boot startup by what each removes. CDS stores parsed classes and is the simple first step; the JDK AOT cache from Project Leyden stores loaded and linked classes and profiles from a training run while keeping full JVM semantics; CRaC restores a warmed JVM from a checkpoint but needs a CRaC JDK and careful resource and secret handling; native images start fastest with the lowest memory under a closed world with long builds. We choose by startup target, operational constraints and team skills.

What to say in the interviewAbout 90 seconds aloud

Open with

They attack startup in different ways. A GraalVM native image moves everything to build time: static analysis, ahead-of-time compilation and Spring AOT. It gives the fastest startup and the lowest memory, but it's a closed world, so reflection and proxies need metadata, conditional beans are fixed at build time, builds are long and peak throughput can be lower.

Then, if they want more

CRaC keeps the normal JVM: you start the app, maybe warm it up, take a checkpoint of the whole process, and restore it in tens of milliseconds, already warm.

But you need a CRaC-enabled JDK, it's Linux only, resources like sockets and pools must be closed and reopened around the checkpoint, which Spring 6.1 and later handles for Lifecycle beans, and secrets in memory end up in the image.

The JDK AOT cache from Project Leyden, from JDK 24 with JEP 483 and improved in 25, uses a training run to store classes already loaded and linked, and now method profiles, while keeping full JVM semantics and tooling. It builds on class data sharing, which is the simplest earlier step and caches parsed classes.

I'd choose by target: CDS or the AOT cache as a cheap default for everyone, CRaC where we need fast and warm startup and can operate checkpoints, and native for functions or scale-to-zero where memory and startup dominate and our libraries support it.

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.
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 "Compare GraalVM native image, CRaC (Coordinated Restore at Checkpoint) and JDK AOT...": https://scrivio-interview-library.netlify.app/spring-boot/native-and-aot/4ac30d64d5/