Scrivio Interview library
DebuggingIntermediate5 min read · updated 12 November 2026

How would you find which beans make a Boot service take 60 seconds to start?

I would give the application a BufferingApplicationStartup with setApplicationStartup and read the startup actuator endpoint, where steps such as spring.beans.instantiate show the duration for each bean; FlightRecorderApplicationStartup records the same steps in JFR instead. In the slowest beans, I would look for remote calls, schema validation, large classpath scanning and connection pools that connect eagerly, and take thread dumps during startup to see where the main thread is waiting.

Why this question is asked

A 60 second startup is long enough to slow every rollout and every scale-out, and short enough that teams have learned to live with it. Guessing at the cause rarely works, because the slow part is often a single bean doing something unexpected. Interviewers ask this to see whether we know Spring's own startup instrumentation and how to read it. In this answer, we will set up startup tracking, read the startup endpoint, use JFR as an alternative, use thread dumps to see waiting, and go through the usual culprits and their fixes.

1Recording Startup Steps

Spring Framework has an ApplicationStartup abstraction that records named steps during startup, such as creating each bean or refreshing the context. By default it is a no-op that records nothing. Giving SpringApplication a BufferingApplicationStartup makes it keep the steps in memory, with their durations and tags.

Java
public static void main(String[] args) {
SpringApplication app = new SpringApplication(CatalogApplication.class);
app.setApplicationStartup(new BufferingApplicationStartup(10_000)); // capacity in steps
app.run(args);
}
# application.yml
management:
endpoints:
web:
exposure:
include: health,startup

The capacity limits how many steps are kept; a large application with many beans needs a few thousand. The startup actuator endpoint then exposes the recorded steps. A GET returns them without clearing; a POST returns them and drains the buffer, so check your version's documentation for that detail.

2Reading the Startup Endpoint

The endpoint returns a JSON timeline. Each step has a name, tags, a start time and a duration. The steps that matter most are spring.beans.instantiate, one per bean, tagged with the bean name. Because beans create their dependencies, steps are nested, so a slow bean may be slow because of what it depends on.

Shell
curl -s localhost:8080/actuator/startup | jq -r '
.timeline.events[]
| select(.startupStep.name == "spring.beans.instantiate")
| [.duration, (.startupStep.tags[] | select(.key == "beanName") | .value)] | @tsv' \
| sort -r | head -5
# PT21.402S entityManagerFactory
# PT12.118S catalogSearchClient
# PT8.950S flywayInitializer
# PT4.211S dataSource
# PT2.034S templateEngine
Reading the top of the startup timeline
Bean or stepDurationLikely cause
entityManagerFactory21.4 sMetamodel for 600 entities + schema validation
catalogSearchClient12.1 sRemote call at init, slow DNS or timeout
flywayInitializer9.0 sMigrations or validation at every start
dataSource4.2 sPool opens connections eagerly
spring.context.beans.post-process3.5 sBroad component scan, large classpath

Notice the durations are ISO-8601 strings, so sorting them as text works only when they have the same shape; for a real report, convert them to milliseconds first. Here the picture is already clear: three beans account for about 42 of the 60 seconds. Other steps, such as spring.context.refresh and spring.context.beans.post-process, show time spent outside individual beans, for example in component scanning.

3Using JFR Instead

In environments where exposing an endpoint is not wanted, or when we want startup steps alongside CPU, allocation and I/O data, FlightRecorderApplicationStartup records the same steps as Java Flight Recorder events.

Java
SpringApplication app = new SpringApplication(CatalogApplication.class);
app.setApplicationStartup(new FlightRecorderApplicationStartup());
app.run(args);
// java -XX:StartFlightRecording:filename=startup.jfr,duration=120s -jar catalog.jar
// open startup.jfr in JDK Mission Control: Spring startup events plus method profiling

The advantage of JFR is context. If entityManagerFactory takes 21 seconds, the method profiling in the same recording shows whether that time is CPU spent building metadata, or waiting on the database for schema checks. The startup events tell us which bean; the rest of the recording tells us why.

4Thread Dumps During Startup

A simpler tool is still very effective: take a few thread dumps of the main thread while the application is starting. If the same stack appears in three dumps taken five seconds apart, that is where startup is waiting.

Shell
jcmd $(pgrep -f catalog.jar) Thread.print | sed -n '/"main"/,/^$/p'
# "main" #1 prio=5 os_prio=31 ... runnable
# at sun.nio.ch.Net.connect0(Native Method)
# ...
# at java.net.http.HttpClient.send(...)
# at com.acme.search.CatalogSearchClient.<init>(CatalogSearchClient.java:41)
# at org.springframework.beans.BeanUtils.instantiateClass(...)

This dump shows the main thread inside the constructor of CatalogSearchClient, making an HTTP call. The startup endpoint told us the bean was slow; the dump tells us exactly which line, and it works even when no instrumentation was configured in advance.

5The Usual Culprits and Their Fixes

Most slow startups come from a short list. Remote calls during bean creation, like the search client above, should move out of constructors: connect lazily on first use, or warm up in the background with readiness control. Hibernate schema validation with ddl-auto=validate reads metadata for every table; turn it off in production and validate in a test instead. Migrations that run at every start can move to a separate job before rollout.

Connection pools such as HikariCP open connections at startup; slow networks or a large minimum pool size make that visible, and the minimum can be lowered. Broad @ComponentScan packages and a large classpath make scanning slow, which narrower base packages or Spring's AOT processing can reduce. After each fix, we record startup again and compare, so we know which change helped and by how much.

6Follow-up questions

Does BufferingApplicationStartup slow the application down?

Slightly, because it records every step, which is why it is not the default. The overhead is small compared with a 60 second startup, and it can be enabled only in a profile used for investigation.

Why does the duration of a parent bean include its dependencies?

Because creating a bean creates its dependencies first, inside the same step. To find the real cost, look for the innermost slow step, or subtract the durations of nested steps from their parent.

What if the slow part is before the context refresh?

Then the timeline shows long gaps before the first bean step, for example in spring.boot.application.environment-prepared, which points at loading configuration, perhaps from a remote config server. Thread dumps during that phase show what the main thread is waiting for.

7Conclusion

In this answer, we found the slow beans in a 60 second startup with Spring's own instrumentation. BufferingApplicationStartup, set with setApplicationStartup, records steps that the startup endpoint returns, and spring.beans.instantiate steps show the time per bean; FlightRecorderApplicationStartup records the same steps in JFR with profiling context. Thread dumps during startup show where the main thread waits, and the usual culprits are remote calls, schema validation, migrations, eager connection pools and large classpath scans.

What to say in the interviewAbout 70 seconds aloud

Open with

I would use Spring's own startup instrumentation rather than guessing. In main, I would create the SpringApplication and call setApplicationStartup with a BufferingApplicationStartup with a few thousand steps of capacity, and expose the startup actuator endpoint.

Then, if they want more

The endpoint returns a timeline of steps, and the spring.beans.instantiate steps are tagged with the bean name and carry a duration, so I can sort them and see the top five beans. They are nested, so a slow bean can be slow because of a dependency, and I look for the innermost slow step.

If I cannot expose the endpoint, FlightRecorderApplicationStartup puts the same steps into a JFR recording, which also has method profiling, so I can see whether the time is CPU or waiting. I would also take a few thread dumps with jcmd during startup; if the main thread is in the same place each time, that is the wait.

The culprits are usually the same: remote calls in constructors, Hibernate schema validation, Flyway running at every start, connection pools opening connections eagerly, and broad component scanning. I would fix the biggest one first, measure again, and repeat.

About this answer

Last updated
12 November 2026
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 "How would you find which beans make a Boot service take 60 seconds to start?": https://scrivio-interview-library.netlify.app/spring-boot/boot-startup/a0e7ddc0fa/