Scrivio Interview library
DesignAdvanced9 min read · updated 12 November 2026

Your company runs 300 Spring Boot services on Kubernetes and autoscaling is slow because pods take 45 seconds to be ready. What fleet-wide options would you evaluate?

Before choosing any technique, we profile a handful of typical services to find the causes they share, because a fleet of 300 usually has the same three or four problems copied everywhere. Then we remove unused starters and eager remote calls, try Class Data Sharing or the JDK AOT cache as a cheap fleet-wide gain, move the most startup-sensitive services to GraalVM native images where their libraries allow it, and fix the Kubernetes side: probes that detect readiness promptly and autoscaling that reacts to predicted load instead of waiting for CPU to climb.

Why this question is asked

When a pod needs 45 seconds to become ready, autoscaling is always late. Traffic rises, the autoscaler asks for more pods, and for most of a minute the existing pods carry the extra load alone, which is often exactly when latency alarms fire. Interviewers ask this at a senior level because the answer is a programme of work across many teams, not a single flag. In this answer, we will see where the 45 seconds usually go, how to measure them, the application-level fixes, the JVM-level options (CDS, the AOT cache and native images), and finally the Kubernetes side, because part of the delay often has nothing to do with Java at all.

1Where the 45 Seconds Usually Go

Readiness is the moment Kubernetes starts sending traffic to a pod. Between scheduling the pod and that moment, several things happen one after the other: the image is pulled, the container starts the JVM, the JVM loads and links thousands of classes, Spring creates the application context and all its beans, the application does its own startup work, and finally the readiness probe succeeds. Any of these can dominate.

In large fleets the same causes appear again and again. Services carry starters they no longer use, so Spring creates data sources, message listeners and clients for nothing. Beans call other systems while they are being created: they load a cache from a remote service, run database migrations, or wait for a broker connection. CPU limits are set low for the steady state, typically half a core, while the JVM needs several cores for a few seconds to load classes and compile hot code. And a long probe initial delay means a pod ready after 20 seconds is only marked ready at 40.

Step throughThe startup path of one pod
  1. Image pullseconds to tens of seconds for large images on a fresh node
  2. JVM start and class loadingthousands of classes read, verified and linked
  3. Spring context refreshbean creation, auto-configuration, proxies
  4. Application startup workmigrations, cache warm-up, remote calls
  5. Readiness probeinitial delay plus probe period before traffic arrives

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

Each layer adds to the time before the pod takes traffic; measure each one before fixing any.

2Profile Typical Services First

With 300 services we cannot study each one, but we do not need to. We pick five to ten that represent the common stacks, for example a web service with JPA, a Kafka consumer and a batch-style service, and we measure them properly. Spring Boot can record every startup step if we give the application a BufferingApplicationStartup, and the Actuator startup endpoint then returns the steps with their durations.

Java
@SpringBootApplication
public class OrdersApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(OrdersApplication.class);
app.setApplicationStartup(new BufferingApplicationStartup(4096)); // keep up to 4096 steps
app.run(args);
}
}
// management.endpoints.web.exposure.include=startup
// POST /actuator/startup -> JSON with each step, for example:
// spring.beans.instantiate beanName=productCache duration=PT11.2S
// spring.beans.instantiate beanName=flyway duration=PT6.4S
// spring.beans.instantiate beanName=entityManagerFactory duration=PT4.1S

Notice what this kind of output tells us. In the example, two beans account for 17 seconds, and neither of them is Spring's own overhead: one loads a product cache over HTTP and one runs migrations. We also compare the log line Started OrdersApplication in 31.2 seconds with the pod's creation and ready times from kubectl describe pod; the gaps show how much is image pull and probe configuration rather than Java. When three or four services show the same pattern, one fix in the shared platform starter or Helm chart reaches all 300.

3Remove Unused Starters and Eager Remote Calls

The cheapest gains come from not doing work. A starter that is on the classpath but unused still triggers auto-configuration, which creates beans, opens connection pools and sometimes tries to connect to a server. A dependency report per service, compared with what the code really uses, usually finds a few that can go. Each removed starter also makes the image smaller, which shortens the image pull.

Eager remote calls are the bigger prize. A bean that loads a cache in its constructor or in a @PostConstruct method blocks the whole context refresh until the remote call returns. The fix is to load such data lazily on first use, or to warm the cache in the background once the application is up. Database migrations belong in a separate job that runs once per release, not in every pod at every start: with 20 replicas, running Flyway in each pod means 20 pods checking the same schema history table on every scale-up.

Java
// Before: blocks context refresh for about 11 seconds
@Bean
ProductCache productCache(CatalogClient client) {
return new ProductCache(client.loadAll()); // remote call during startup
}
// After: start fast, load when the application is up
@Bean
ProductCache productCache() { return new ProductCache(); }
@EventListener(ApplicationReadyEvent.class)
void warm(ApplicationReadyEvent e) {
executor.submit(() -> cache.loadFrom(client)); // readiness can wait for this if needed
}

If the service must not take traffic before the cache is warm, it can keep its readiness state as refusing traffic until the load finishes, using Spring Boot's availability support (AvailabilityChangeEvent with ReadinessState). The JVM and context are already up, so only the data load remains.

4Class Data Sharing and the JDK AOT Cache

Class Data Sharing, CDS, lets the JVM save the classes it loaded during one run into an archive file, and map that archive into memory on later runs instead of reading, parsing and verifying every class again. Recent Spring Boot versions support it directly: we extract the jar into a layout the JVM can archive, do one training run that stops right after the context refreshes, and start production pods with the archive. Spring Boot 3.3 added this support, and the Paketo buildpacks can do the training run during the image build; check your versions for the exact flags.

Java 24 and 25 go further with the AOT cache from Project Leyden. It stores not only parsed classes but also linked classes and, from Java 25, method profiles from the training run, so the JIT compiler can optimise hot code sooner. Spring Boot 3.5 can use it in the same way as CDS. Reported gains for Spring applications are often 30 to 50 percent, with no code change.

Text
# Extract the jar into a layout that suits CDS and the AOT cache (Boot 3.3+)
java -Djarmode=tools -jar orders.jar extract --destination app
# Java 25: training run that exits after the context refresh, writing the cache
java -XX:AOTCacheOutput=app.aot -Dspring.context.exit=onRefresh -jar app/orders.jar
# Production start uses the cache
java -XX:AOTCache=app.aot -jar app/orders.jar # Started OrdersApplication in 9.8 seconds (was 17.5)

There is a catch: the archive must come from the same JDK build and the same classpath as the production run, otherwise the JVM ignores it and starts normally. So it belongs in the image build, created by the same pipeline that builds the image, never copied between images. Because it needs no code changes, this is the option we can roll out across the whole fleet through the shared base image and build template.

5Native Images Where Startup Matters Most

A GraalVM native image compiles the application ahead of time into a single executable. Spring Boot's AOT processing runs during the build, works out which beans exist and generates code for them, so at runtime there is no classpath scanning and no class loading. Startup drops from tens of seconds to well under a second, and memory use falls too.

The cost is real, which is why we would not apply it to all 300 services. Builds take several minutes and need a lot of memory. Libraries that use reflection or dynamic proxies need reachability metadata, and some older libraries do not have it. Bean conditions are fixed at build time, and peak throughput can trail a warmed-up JIT. So we pick the services where startup really changes the result: those with spiky traffic, those that scale to zero, and small stateless services with modern dependencies. A trial native build of one of them tells us quickly whether its libraries cooperate.

Fleet options compared
OptionTypical gainCostWhere to use
Remove starters and eager callsoften the largest single gaina review per serviceevery service
CDS or JDK AOT cacheabout 30 to 50% of JVM startupbuild pipeline change onlythe whole fleet via base image
GraalVM native imagestartup under 1 secondlong builds, library limitsspiky or scale-to-zero services
Probe and CPU tuningremoves waiting that is not Javachart changeevery service
Predictive scalingpods start before the peakmetrics and policy workservices with known daily peaks

6Fix the Kubernetes Side: Probes, CPU and Scaling Policy

Part of the 45 seconds is often configuration. A readiness probe with initialDelaySeconds of 30 and periodSeconds of 10 cannot report ready before 30 seconds, whatever the application does. The better pattern is a startupProbe that checks frequently, say every 2 seconds, with enough failureThreshold to cover the slowest start, followed by a readiness probe on Spring Boot's /actuator/health/readiness endpoint. The pod is then marked ready within about 2 seconds of the application being ready.

CPU limits deserve a look as well. A JVM given half a core is throttled during class loading and JIT compilation, so it may start in 15 seconds with two cores and 40 with half a core. Raising the request or dropping the CPU limit for these services is often the cheapest fix of all.

Finally, the autoscaler itself. Scaling on CPU means we wait for pods to get busy, then wait again for new pods to start. For services with predictable daily peaks, we can scale on request rate or queue length, which rise before CPU does, or schedule extra replicas ahead of known peaks, for example with KEDA's cron scaler, and keep a sensible minimum replica count. Faster startup and earlier scaling multiply each other: a pod that starts in 10 seconds, requested 5 minutes before the peak, never makes users wait.

7Follow-up questions

How would you roll this out across 300 services without blocking teams?

Through the platform rather than through each team. The shared base image and build template gain the CDS or AOT cache training step, the shared Helm chart gains the startup probe and readiness endpoint, and the platform starter stops running migrations in the pods. Teams then only review their own starters and eager calls, guided by a startup report from the Actuator endpoint that we publish for every service. We track the median and slowest readiness times per service on a dashboard, so the work stays visible.

Is lazy initialisation a good fleet-wide fix?

Usually not on its own. spring.main.lazy-initialization=true makes the context refresh faster because beans are created on first use, but the cost moves to the first requests, which then see high latency, and configuration errors appear later instead of at startup. It can help a few services with many rarely used beans, but for autoscaling it often just moves the slowness into the period when the new pod is already taking traffic.

8Conclusion

In this answer, we saw that slow readiness across a fleet is best attacked by first profiling a few representative services, because the causes are shared. Removing unused starters and eager remote calls, moving migrations out of the pods and fixing probes and CPU limits usually give the largest gains for the least work. CDS or the JDK AOT cache can then be rolled out through the base image for every service, native images reserved for the services where startup decides the outcome, and autoscaling moved from CPU alone to request rate or predicted load.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by measuring rather than picking a technology. I would take five to ten representative services and break the 45 seconds down: image pull, JVM start, Spring context refresh and application startup work using BufferingApplicationStartup and the Actuator startup endpoint, and the probe delay, comparing the Spring started log line with the pod's ready time.

Then, if they want more

In my experience a few causes are shared across the fleet, so I fix them centrally. The usual ones are unused starters, beans that call remote services or run migrations during startup, CPU limits that throttle the JVM while it loads classes, and readiness probes with long initial delays.

Those changes go into the platform starter and the shared Helm chart. Next, I would add Class Data Sharing or, on Java 24 and later, the JDK AOT cache to the shared image build, since Spring Boot 3.3 and later support it with a training run and it needs no code changes.

I would check the exact flags against our versions. For the services where startup really decides the result, such as spiky or scale-to-zero ones, I would evaluate GraalVM native images, after checking that their libraries are supported.

Finally, I would change the autoscaling to react to request rate or scheduled peaks instead of CPU alone, and track pod-ready time per service on a dashboard to prove the gains.

About this answer

Last updated
12 November 2026
Versions it names
Java 25, Java 24, Spring Boot 3.3, Spring Boot 3.5
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 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 "Your company runs 300 Spring Boot services on Kubernetes and autoscaling is slow because...": https://scrivio-interview-library.netlify.app/spring-boot/boot-startup/cb697a7e62/