Quick revision
The short answer
We attack the two minutes from every side. Each pod gates readiness on a warmup phase with representative requests, the load balancer ramps traffic to new pods with slow start, images ship CDS or AOT cache archives so class loading and, with stored profiles, JIT warmup take less time, and pods may burst CPU during startup because compilation needs it. On the scaling side, we scale earlier from predicted load and keep a minimum replica count so peaks are not handled reactively, and we track time to steady state as a service metric after every change.
What to remember
In this answer, we designed a layered fix for cold starts. Each pod warms up before reporting ready, the load balancer ramps traffic with slow start, images carry CDS or AOT cache archives from a training run, and pods may burst CPU during startup for the JIT. Predictive scaling and a minimum replica count keep cold starts away from the peak, and time to steady state is tracked per service so regressions are caught after changes.
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.
We attack the two minutes from every side. Each pod gates readiness on a warmup phase with representative requests, the load balancer ramps traffic to new pods with slow start, images ship CDS or AOT cache archives so class loading and, with stored profiles, JIT warmup take less time, and pods may burst CPU during startup because compilation needs it. On the scaling side, we scale earlier from predicted load and keep a minimum replica count so peaks are not handled reactively, and we track time to steady state as a service metric after every change.
Why this question is asked
Autoscaling is supposed to protect latency at peak, but with JVM services it can do the opposite: the very pods added to help are slow for their first minutes and drag the p99 up exactly when traffic is highest. Interviewers ask this design question to see whether we can combine JVM knowledge with platform design and operational metrics into a fleet-wide solution rather than a per-service hack. In this answer, we will break down where the two minutes come from, then design the solution in layers: inside the pod, at the load balancer, in the image, in resource settings, in the scaling policy, and in measurement.
1Where the Two Minutes Come From
A new JVM pod starts with nothing. It loads thousands of classes on first use, runs its code in the interpreter until the JIT compiles the hot paths through C1 and then C2, opens database connections and fills its caches. If the readiness probe only checks that the HTTP port answers, the pod receives its full share of traffic while still in that state, and its requests are several times slower than on warm pods. With a 1/N share of traffic going to a slow pod, the fleet p99 rises, and during peaks the autoscaler adds several pods at once, so the effect is larger.
Two more effects make it worse. Compilation needs CPU, and a pod sized for steady state may be throttled during warmup, stretching it. And the peak itself means the pod receives the most traffic at the moment it can handle it least.
- Scaling policypredictive scaling, minimum replicas
- Load balancerslow start ramps traffic to new pods
- Pod readinesswarmup phase before ready
- ResourcesCPU burst during startup
- ImageCDS or AOT cache archive shipped with the build
- Measurementtime to steady state per service
6 layers, from the top down. Step through them one at a time.
2Inside the Pod: Warmup Before Ready
The first layer is a warmup phase. After the application context starts, the service stays not ready and sends itself representative requests over its real HTTP endpoints, without side effects, until latency stops improving or a time limit is reached. Only then does readiness switch to accepting traffic. The platform can provide this as a shared library or a sidecar that replays a recorded, sanitised sample of each service's traffic, so every team does not build its own. Warmup traffic must resemble real traffic, because the JIT optimises for the profile it sees.
3At the Load Balancer: Slow Start
Even after warmup, a pod's caches and profiles are not identical to those of a pod that has served real traffic for hours. Slow start, a feature of many load balancers and service meshes, sends a new endpoint a small share of traffic at first and increases it over a configured window, for example 60 to 120 seconds. AWS target groups, Envoy-based meshes and others offer it under names like slow start mode or slow start window; check what your platform supports. Combined with warmup, it means a new pod reaches its full share only when it is already close to steady state.
6 messages in order. Play them, or step through them one at a time.
The pod only sees full traffic after warmup and a gradual ramp.
4In the Image: CDS and the AOT Cache
The build pipeline can do part of the warmup once, ahead of time. Class Data Sharing and Project Leyden's AOT cache store the results of a training run: since JDK 24 the cache holds classes already loaded and linked, and since JDK 25 it can hold method profiles, so the JIT starts compiling hot code sooner. The platform adds a step to the image pipeline: start the service, run the warmup workload, write the archive, and ship it in the image. The archive must be created with the same JDK and the same application JARs as production, so it belongs in the same build that produces the image.
5Resources: Let Startup Burst
During warmup, compiler threads and application threads compete for CPU, and with a tight CPU limit the container is throttled. Allowing the pod to use more CPU during startup, through a limit higher than the request, no limit with a proper request, or in-place resizing where the platform supports it, shortens the JIT phase directly. The cost is that bursting pods borrow capacity from the node, so node headroom must account for several pods starting at peak.
6Scaling Policy: Do Not Wait for the Peak
The cheapest cold start is one that happens before the peak. If peaks are predictable, daily or weekly, we scale ahead of them on a schedule or from a forecast, so new pods are warm when traffic arrives. A minimum replica count sized for normal peak load means reactive scaling only handles unusual spikes. Reactive scaling itself should trigger earlier, on a lower CPU target or on request rate, to leave time for the two minutes it takes a pod to become useful. Scaling down should be slower than scaling up, so the fleet does not throw away warm pods only to start cold ones again.
| Lever | Effect on cold start | Cost |
|---|---|---|
| Warmup before ready | users never hit a cold pod | longer time to ready |
| Load balancer slow start | gradual share for new pods | slower relief at peak |
| AOT cache in image | less class loading and JIT warmup | extra build step |
| CPU burst at startup | faster JIT phase | node headroom |
| Predictive scaling, min replicas | fewer cold starts at peak | idle capacity off-peak |
7Measurement: Time to Steady State
We make cold start visible. Each service reports time to ready and time to steady state, defined for example as the time until a pod's p99 is within 10 percent of the fleet's p99, plus the latency of requests served by pods younger than five minutes as a separate series. These go on the standard dashboard. After any change, such as a JDK upgrade, a new framework version or an image change, we compare them, because cold start regressions are easy to introduce and rarely noticed until a peak.
8Follow-up questions
Why not just keep many more replicas so you never scale at peak?
That works but costs money all day for a problem that lasts a few minutes. A minimum replica count for normal peaks plus predictive scaling covers most of the need, and the per-pod techniques make the remaining reactive scaling cheap. The right mix depends on the cost of idle capacity versus the cost of the latency impact.
Would native image solve this instead?
It removes JIT warmup and most class loading, so start and first requests are fast. But it needs a closed-world build, may need configuration for reflection, and often has lower peak throughput than C2 code without profile-guided optimisation. For a fleet, the AOT cache keeps full Java behaviour and gets a good part of the benefit, so I would start there and use native image for specific services that need it.
How do you keep warmup traffic representative across many services?
The platform records a sample of each service's real requests, sanitises it to remove personal data and side effects, and stores it as the service's warmup set, refreshed regularly. The same set drives the AOT cache training run. Teams can review it, and a check fails if warmup covers too few of the endpoints that carry real traffic.
9Conclusion
In this answer, we designed a layered fix for cold starts. Each pod warms up before reporting ready, the load balancer ramps traffic with slow start, images carry CDS or AOT cache archives from a training run, and pods may burst CPU during startup for the JIT. Predictive scaling and a minimum replica count keep cold starts away from the peak, and time to steady state is tracked per service so regressions are caught after changes.
Open with
I would design it in layers. First, inside the pod, readiness is gated on a warmup phase: the service runs representative, side-effect-free requests against its own endpoints and only reports ready when latency has stabilised.
Then, if they want more
The platform can provide that as a shared library with recorded, sanitised traffic per service. Second, the load balancer uses slow start, so a new pod gets a small share of traffic that ramps up over a minute or two instead of its full share at once.
Third, the image ships a CDS or AOT cache archive created in the build from a training run; on JDK 25 that cache can include method profiles, which cuts both class loading and JIT warmup. Fourth, pods can burst CPU during startup, because the JIT needs CPU and a throttled pod warms up much more slowly.
Fifth, the scaling policy should avoid reacting at the peak: scale ahead of predictable peaks, keep a minimum replica count for normal peak load, trigger reactive scaling earlier, and scale down slowly. Finally, I would make time to steady state a standard service metric, along with latency for young pods, and compare it after every JDK, framework or image change.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 25, Java 24
- 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 "During peak hours your autoscaler adds pods, and each new pod causes elevated p99...": https://scrivio-interview-library.netlify.app/java/jit-compilation/fb4a547650/