Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

A large Spring Boot service takes 45 seconds to start, mostly before the web server is listening. How would you analyse and reduce startup time across your service fleet?

First measure: record startup steps with the ApplicationStartup API, for example BufferingApplicationStartup with the Actuator startup endpoint, and find which beans and phases take the time. The usual culprits are bean initialisation doing network calls or cache warming, large classpath scans and auto-configurations nobody uses, so we fix or defer those, remove unused starters, and then consider lazy initialisation, class data sharing, Spring AOT or CRaC where they fit. Across a fleet, we turn the findings into defaults in internal starters so every service benefits.

Why this question is asked

A 45-second startup is more than an annoyance. It slows every deployment and rollback, makes autoscaling react late, lengthens test feedback, and on Kubernetes it forces generous probe settings that hide real failures. At a senior level the interviewer wants a method, not a list of tricks: how we find out where the time goes, how we fix the causes, which platform features help, and how we spread the improvement across many services. In this answer, we will measure startup, read the result, fix the common causes, look at the runtime options, and then talk about doing it for a whole fleet.

1A Quick Recap: Where Startup Time Goes

When a Spring Boot service starts, SpringApplication prepares the environment and then calls refresh() on the ApplicationContext. Refresh parses configuration classes, scans packages, evaluates the conditions of every auto-configuration, creates every non-lazy singleton bean, and only at the end starts the web server's connectors so the port accepts traffic.

So if most of the 45 seconds pass before the server listens, the time is almost certainly inside refresh, and most likely in bean creation, where our constructors and @PostConstruct methods run. JVM class loading and JIT warm-up add to it, but rarely account for tens of seconds by themselves. The first job is to stop guessing and find the exact beans.

2Measure With ApplicationStartup

Spring Framework records startup steps through the ApplicationStartup interface. By default it is a no-op. Spring Boot provides BufferingApplicationStartup, which keeps the steps in memory, and the Actuator startup endpoint exposes them as JSON. Each step has a name such as spring.beans.instantiate, the bean name, a start time and a duration.

Java
public static void main(String[] args) {
SpringApplication app = new SpringApplication(BillingApplication.class);
app.setApplicationStartup(new BufferingApplicationStartup(10_000)); // keep up to 10,000 steps
app.run(args);
}
// application.yml: management.endpoints.web.exposure.include: health,startup
// GET /actuator/startup, sorted by duration:
// spring.beans.instantiate beanName=fxRateCache duration=PT18.2S
// spring.beans.instantiate beanName=entityManagerFactory duration=PT6.9S
// spring.context.config-classes.parse duration=PT3.1S

Notice that the result points at specific beans. FlightRecorderApplicationStartup sends the same steps to Java Flight Recorder if we prefer to look at them with other JVM events. A plain log at DEBUG level for org.springframework and the JVM option -Xlog:class+load help with the parts outside refresh. Measure on production-like hardware with production-like configuration, because a laptop with a local database gives a misleading picture.

3Fix What the Measurement Finds

The biggest wins are usually in our own beans. A bean that calls a remote service in its constructor, loads a large cache, runs a schema check or waits for a slow dependency blocks every later step. In the example, fxRateCache spends 18 seconds downloading exchange rates. We can load it asynchronously after ApplicationReadyEvent and report readiness only when it is warm, so the process starts quickly and the readiness probe tells Kubernetes when to send traffic. Liveness then no longer needs a huge initial delay.

Next come framework costs that we pay for features we do not use. The --debug flag prints the conditions evaluation report, which lists every auto-configuration that matched. Starters that pull in unused technologies, a JMS client, a second web stack, a template engine, can be removed, and specific auto-configurations can be excluded. Broad @ComponentScan or entity scanning over large packages and Hibernate building metadata for hundreds of entities also show up here; narrowing scan packages and checking Hibernate's settings help.

Step throughWorking through a slow startup
  1. Record steps with BufferingApplicationStartupsort by duration
  2. Is a single bean slow?
    YesFix or defer its work, use readinessNoGo on
  3. Unused auto-configurations or starters?
    YesRemove or exclude themNoGo on
  4. Large scans or entity metadata?
    YesNarrow packages, tune HibernateNoGo on
  5. Still too slow for the workload?
    YesTry CDS, AOT, lazy init or CRaCNoDone, track the number
  6. Measure again and record the resultsame hardware and config

6 steps in order. Play them, or step through them one at a time.

4Runtime Options, and What Each Costs

Once the obvious causes are gone, several platform features can cut the remaining time. Lazy initialisation, spring.main.lazy-initialization=true, or @Lazy on specific beans, delays bean creation until first use. It speeds startup but moves errors and latency to the first request, so it suits non-critical beans better than a global switch for production. Class data sharing, CDS, stores loaded class metadata in an archive the JVM maps at the next start; Spring Boot 3.3 and later can extract the application in a CDS-friendly layout, and newer JDKs add an AOT cache through Project Leyden that goes further, so check your Boot and JDK versions for the exact options.

Spring AOT processes the configuration at build time and generates bean registration code, removing much of the scanning and condition evaluation from startup; it is required for GraalVM native images, which start in a fraction of a second but need build-time knowledge of reflection and fixed conditions. CRaC, Coordinated Restore at Checkpoint, snapshots a warmed-up JVM and restores it, which Spring Framework 6.1 and later supports, but it needs a JDK that implements it and care with open connections and secrets. Each option has a cost in build complexity or behaviour, so we pick based on how often the service starts.

Options after fixing the causes
OptionTypical gainCost
Lazy initialisationmoderateerrors and latency move to first use
Class data sharing / AOT cachemoderate, JVM sideextra build step, archive per build
Spring AOT on the JVMmoderateconditions and profiles fixed at build
GraalVM native imagevery largelong builds, reflection hints, no runtime changes
CRaCvery largespecial JDK, checkpoint handling of resources
Measure each on our own service; gains vary with the application.

5Spreading the Fix Across the Fleet

With many services, the same causes repeat. So after fixing the first service, we make the good defaults the easy path. An internal starter, a shared dependency every service already uses, can enable BufferingApplicationStartup and the startup endpoint, set sensible scanning, provide an async cache-warming helper tied to readiness, and include the CDS build step in the shared build plugin. Services get the improvement by upgrading one dependency.

We also make startup a tracked number. Each service reports its time to ready at every deployment, a dashboard shows the slowest services, and a guide records the causes we found and their fixes. When the next service hits 45 seconds, the team does not start from zero.

6Follow-up questions

Why not just set lazy initialisation everywhere?

Because it hides problems. A misconfigured bean then fails at the first request that uses it, possibly hours after deployment, and the first user pays for creating many beans. It is useful in development and for selected beans, but for production services it is better to fix slow beans than to defer all of them.

How do we stop Kubernetes from killing a slow-starting pod?

Use a startup probe, which gives the container time to start before liveness checks begin, and point readiness at Spring Boot's readiness state. That way we do not need a long initial delay on the liveness probe, and traffic only arrives once the service is really ready.

Is the time before refresh ever significant?

Sometimes. A very large classpath, slow class loading from a network file system, or heavy logging configuration can add seconds before refresh begins. JVM logs of class loading and the startup steps for the environment phase show it. CDS helps most with this part.

7Conclusion

In this answer, we analysed a 45-second startup by recording startup steps with BufferingApplicationStartup and the startup endpoint, then fixed the causes it revealed: beans doing network calls or cache warming during initialisation, unused auto-configurations and starters, and large scans. We weighed lazy initialisation, class data sharing, Spring AOT, native images and CRaC by what each costs. Finally we shared the findings and defaults through internal starters and tracked startup time so the whole fleet benefits.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by measuring rather than guessing. Spring has the ApplicationStartup API, so I would set BufferingApplicationStartup on the SpringApplication, expose the Actuator startup endpoint, and sort the recorded steps by duration.

Then, if they want more

That usually points at a few specific beans. Since most of the time is before the server listens, it is inside refresh, typically bean creation. The common causes are beans that do real work during initialisation: calling a remote service, warming a large cache, running schema checks.

I would move that work after ApplicationReadyEvent or into a background task and report readiness only when it is done, with a startup probe in Kubernetes.

Then I look at framework cost: the conditions report shows auto-configurations that match but are not needed, so I remove unused starters and exclude what we do not use, and I narrow broad component or entity scanning.

After that, depending on how often the service starts, I would consider lazy initialisation for non-critical beans, class data sharing or the newer JDK AOT cache, Spring AOT, or CRaC where our JDK supports it, each with its own trade-off.

For the fleet, I would put the measurement setup, a cache-warming helper and the CDS build step into our internal starter and build plugin, track time to ready on a dashboard, and write up the causes so the next team fixes it in a day.

About this answer

Last updated
12 November 2026
Versions it names
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 "A large Spring Boot service takes 45 seconds to start, mostly before the web server is...": https://scrivio-interview-library.netlify.app/spring-boot/ioc-container/019d5d1acb/