Quick revision
The short answer
The first minutes are slow because the JVM runs our code interpreted until the JIT compiles the hot methods, and it loads and initializes classes the first time each one is used. To reduce the impact, we send warm-up traffic before marking the instance ready, use CDS or AppCDS archives to load classes faster, and on JDK 24 and later use the Project Leyden ahead-of-time cache (JEP 483, extended in later releases, so check your version). CRaC in some distributions and GraalVM Native Image go further, each with its own trade-offs.
What to remember
In this answer, we saw that latency after a deploy comes from interpreted code before the JIT finishes and from class loading on first use. We went through the options from least to most effort: warm-up before readiness and gradual traffic shifts, CDS and AppCDS archives, the Leyden ahead-of-time cache from JDK 24, and CRaC or Native Image for cases that justify their trade-offs.
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.
The first minutes are slow because the JVM runs our code interpreted until the JIT compiles the hot methods, and it loads and initializes classes the first time each one is used. To reduce the impact, we send warm-up traffic before marking the instance ready, use CDS or AppCDS archives to load classes faster, and on JDK 24 and later use the Project Leyden ahead-of-time cache (JEP 483, extended in later releases, so check your version). CRaC in some distributions and GraalVM Native Image go further, each with its own trade-offs.
Why this question is asked
High latency right after each deploy is one of the most common complaints about Java services in production. It shows up as a spike on every dashboard after a release, timeouts in callers, and sometimes autoscaling that adds instances which are themselves slow. Interviewers ask it as a scenario to see whether we can explain the cause and pick from the remedies modern JDKs offer, rather than just raising timeouts. In this answer, we will confirm what is happening, then go through the options in order of effort: warm-up before readiness, class data sharing, the Leyden ahead-of-time cache, and finally CRaC and native images.
1What Is Happening in Those First Minutes
When a HotSpot JVM starts, it runs our bytecode in the interpreter, which is slow but starts immediately. Methods that get busy are compiled by C1, the quick compiler, which also records a profile of how the code behaves. The busiest methods are later recompiled by C2, the optimizing compiler, using that profile. On a large Spring Boot service this takes minutes, and the compiler threads use CPU that request threads also need.
At the same time, classes are loaded lazily. The first request on each code path loads and initializes its classes: JSON serializers, database driver classes, TLS and crypto setup, Hibernate metadata. So the very first requests pay for class loading, the next thousands pay for interpreted code, and latency only settles once the hot paths are compiled.
2Confirming the Cause Before Fixing It
Before choosing a fix, we check that this really is JIT warm-up and not something else that also happens after a restart, such as empty caches, a connection pool that opens connections lazily, or DNS lookups. A JDK Flight Recorder recording of the first five minutes shows compilation activity, class loading counts and where CPU goes. A quick look with -XX:+PrintCompilation or the JVM's compiler metrics shows whether compilation is still busy when latency is high. If the latency falls as compilation activity falls, warm-up is the cause.
We also check CPU limits. If the container is limited to one CPU, the JIT threads compete with requests, and warm-up can take several times longer. Giving the pod more CPU during startup is sometimes the cheapest fix of all.
3Option 1: Warm Up Before Taking Traffic
The simplest remedy needs no JVM feature. The instance warms itself up before it tells the load balancer it is ready. In Spring Boot, the readiness state is what the Kubernetes readiness probe checks, so we can keep it at REFUSING_TRAFFIC until a warm-up runner has exercised the main endpoints with realistic requests.
8 messages in order. Play them, or step through them one at a time.
Users only reach the instance after its hot paths are compiled.
The warm-up requests must be safe to repeat, so we use read-only operations or a test tenant, and they should look like real traffic so the JIT profile matches production. A gradual traffic shift in the load balancer or service mesh is the complementary approach: a new instance starts with a small share of traffic and ramps up over a few minutes. Neither makes the JVM faster; they only make sure users do not pay for the warm-up.
4Option 2: Class Data Sharing and AppCDS
Class Data Sharing, or CDS, stores class data that has already been parsed and verified in an archive file, which the JVM maps into memory at startup. The JDK ships a default archive for its own core classes, used automatically. AppCDS extends this to our application's classes and libraries: we run the application once to record which classes it loads, write an archive, and start later runs with it.
CDS mainly shortens startup and class loading; it does not compile anything, so the JIT warm-up remains. The archive must be created with the same JDK build and the same class path as production, so we create it while building the container image. Spring Boot's documentation describes this flow; the exact property and command names have changed between Boot versions, so check your version.
5Option 3: The Leyden Ahead-of-Time Cache
Project Leyden is the OpenJDK effort to improve startup and warm-up inside HotSpot itself. JDK 24 delivered JEP 483, ahead-of-time class loading and linking. It goes further than AppCDS: from a training run, it stores classes already loaded and linked, so the production JVM starts with them ready. JDK 25 made the cache easier to create in one step and added ahead-of-time method profiling, so the cache also holds the profiles collected during training, and the JIT can compile hot methods sooner instead of waiting to collect them again.
The training run should exercise realistic paths, because the cache only helps for what it saw. Like CDS, the cache is tied to the JDK build and class path. Later JDK releases are expected to store compiled code too, so check your version for what the cache contains. The big advantage of this option is that the application stays a normal HotSpot application, with full peak performance and all dynamic features.
6Option 4: CRaC and GraalVM Native Image
CRaC, Coordinated Restore at Checkpoint, takes a snapshot of a running, warmed-up JVM process and restores it later, so a new instance starts already warm in milliseconds. It is available in some distributions, such as Azul Zulu and BellSoft Liberica builds, not in every OpenJDK, and it needs Linux support for checkpointing. Spring Framework 6.1 and later can take a checkpoint automatically at startup. The trade-offs are real: open files, sockets and secrets in memory must be handled at checkpoint, and the snapshot is a sensitive artifact to store.
GraalVM Native Image compiles the whole application ahead of time into a native executable. It starts in tens of milliseconds and uses less memory, but builds take minutes, reflection and resources need reachability metadata, and peak throughput is usually lower than HotSpot's C2 unless profile-guided optimization is used. It suits short-lived or scale-to-zero services more than long-running ones.
| Option | Helps with | Main cost |
|---|---|---|
| Warm-up before readiness | users never see cold code | longer time to ready, safe warm-up requests |
| Gradual traffic shift | spreads the slow period | load balancer or mesh setup |
| CDS / AppCDS | class loading at startup | archive per JDK build and class path |
| Leyden AOT cache (JDK 24+) | loading, linking, and profiles in 25 | training run in the image build |
| CRaC | starts already warm | some distributions only, snapshot handling |
| Native Image | fast start, small memory | long builds, metadata, lower peak |
7Follow-up questions
Does a bigger heap or a different GC fix warm-up latency?
Usually not. Warm-up is about interpreted code and class loading, not memory. A GC change can help if the startup phase is also doing many collections, which a GC log will show, but the main lever is CPU for the JIT, warm-up traffic, and the archive or cache options.
Is warming up with synthetic requests risky?
It can be if requests change data or call third parties. We warm up with read-only endpoints, mocked downstream calls, or a dedicated test tenant, and we rate-limit the warm-up so it does not overload shared dependencies during a rolling deploy of many instances.
Why not turn off tiered compilation or lower the JIT thresholds?
Lowering thresholds makes the JIT compile earlier, but with less profile information, which can produce worse code and more deoptimizations later. It is a tuning knob that needs measurement, while warm-up traffic and the AOT cache attack the problem without trading away steady-state performance.
8Conclusion
In this answer, we saw that latency after a deploy comes from interpreted code before the JIT finishes and from class loading on first use. We went through the options from least to most effort: warm-up before readiness and gradual traffic shifts, CDS and AppCDS archives, the Leyden ahead-of-time cache from JDK 24, and CRaC or Native Image for cases that justify their trade-offs.
Open with
After a restart, HotSpot runs our code in the interpreter until C1 and then C2 compile the hot methods, and that takes minutes on a large service. At the same time, classes are loaded and initialized the first time they are used, so the first requests on each path are slow.
Then, if they want more
I would first confirm that with JFR or compilation logs, and check the CPU limit, because a one-CPU container makes warm-up much longer. Then I would layer the fixes.
First, warm up before taking traffic: keep the Spring Boot readiness state at refusing traffic, send a few thousand realistic read-only requests to the main endpoints, then switch to accepting traffic so the readiness probe passes, and also ramp traffic gradually in the load balancer. Second, cut class loading with an AppCDS archive built in the image build.
Third, on JDK 24 and later, use the Leyden ahead-of-time cache from JEP 483, which stores loaded and linked classes from a training run, and in JDK 25 the cache can also hold method profiles so the JIT optimizes sooner; I would check the exact flags for our version.
If we need near-instant warm starts, CRaC in distributions that support it can restore a warmed-up snapshot, and GraalVM Native Image gives fast startup, but both have costs, so I would only choose them for specific workloads.
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 "After each deploy, a service shows high latency for the first few minutes until it warms...": https://scrivio-interview-library.netlify.app/java/jvm-architecture/8cc014d2e1/