Scrivio Interview library
ScenarioPrincipal7 min read · updated 12 November 2026

Your company is weighing a move of some services from Spring's runtime dependency injection to a compile-time DI framework to reduce startup time. How would you evaluate the move?

I would start by measuring where startup time actually goes, because dependency injection is often a small part compared with I/O, database migrations, ORM setup and auto-configuration. Then I would compare a compile-time DI framework against what Spring already offers: AOT processing, class data sharing, lazy initialisation and trimming unneeded starters. I would count the cost of losing Spring integrations and team familiarity, pilot one service measuring startup, memory, developer speed and operations, and avoid a fleet-wide switch without clear measured gains.

Why this question is asked

Startup time has become a real cost: autoscaling waits for new instances, serverless functions pay it on every cold start, and slow tests slow every developer. Compile-time DI frameworks such as Dagger, Micronaut or Quarkus's build-time processing promise much faster startup by doing at build time what Spring does at runtime. Interviewers ask this scenario to see whether a senior engineer evaluates such a move with measurements and total cost, or with benchmarks from a blog. In this answer, we will recap the difference between runtime and compile-time DI, measure a typical service, look at what Spring can already do, weigh the costs that do not show in a benchmark, and plan a pilot with clear decision criteria.

1A Quick Recap: Runtime Versus Compile-Time DI

Spring's container does most of its work when the application starts. It scans the classpath for annotated classes, reads them with reflection, evaluates auto-configuration conditions, builds bean definitions, and then creates and wires beans. Compile-time DI frameworks do the equivalent work in an annotation processor during the build and generate plain Java code that calls constructors directly, so at startup there is little left to discover.

So the promise is real: less reflection, less scanning, less work at startup, and often less memory. The question is how much of our service's startup that work actually represents.

2Measure Before Deciding

Spring Boot can record its own startup steps. With BufferingApplicationStartup and Actuator's startup endpoint, we see how long each phase and each bean took to create.

Java
SpringApplication app = new SpringApplication(OrderServiceApp.class);
app.setApplicationStartup(new BufferingApplicationStartup(10_000));
app.run(args);
// GET /actuator/startup -> steps with durations, for example:
// spring.boot.application.starting 0.1 s
// spring.beans.instantiate entityManagerFactory 2.4 s (Hibernate metadata, schema validation)
// spring.beans.instantiate flyway 1.6 s (migrations check against the database)
// spring.beans.instantiate kafkaConsumers 0.9 s (broker connections)
// context refresh total 7.8 s
Where 7.8 seconds of startup went in one example service
PhaseSecondsChanges with compile-time DI?
JVM start and class loading1.0a little (fewer classes)
Scanning, conditions, bean definitions1.3yes, mostly removed
Hibernate and schema validation2.4no
Flyway migration check1.6no
Kafka and HTTP client connections0.9no
Other bean creation0.6partly
Illustrative numbers: measure your own services before deciding.

Numbers like these are typical of a business service. Here, Hibernate, Flyway and broker connections take almost five of the eight seconds, and they would take the same time under any DI framework, because they are I/O and library initialisation, not wiring. The part a compile-time framework removes, scanning, reflection and condition evaluation, might be one or two seconds. We should get our own numbers for three or four representative services, because the decision depends on them.

3What Spring Already Offers

Before changing frameworks, we compare with the cheaper options inside Spring. Spring AOT processing does much of the same build-time work: it evaluates conditions and generates bean registration code during the build, and it can run on the JVM with spring.aot.enabled=true, not only in native images. Class data sharing, CDS, stores parsed classes in an archive the JVM maps at startup; Spring Boot 3.3 and later can produce one, and recent JDKs add an ahead-of-time cache that goes further (check your Java and Boot versions). Teams commonly report startup drops of a third or more from these alone.

Lazy initialisation, spring.main.lazy-initialization=true, creates beans on first use instead of at startup, which helps development and tests but moves latency and errors to the first request, so it suits some services more than others. Trimming starters removes auto-configurations we do not use; a service that pulls in a web stack, JPA and three messaging starters it never touches pays for all of them. For the extreme case, a GraalVM native image built with Spring AOT gives sub-second startup and much lower memory, at the cost of longer builds and some library limits.

So there are two separate comparisons to make: compile-time DI against Spring with these options applied, not against default Spring; and native image against JVM for both frameworks, since Micronaut and Quarkus also reach their best numbers in native images.

4The Costs That Do Not Show in a Benchmark

Moving off Spring means losing integrations we use every day: Spring Data repositories, Spring Security, Spring's transaction management, our internal starters, and the conventions every engineer in the company knows. Each service rewritten is weeks of engineering time, and each new framework means a second set of libraries to patch, a second way to configure observability, and on-call engineers who must understand both.

Team familiarity is a real cost, too. Hiring for Spring is easy; hiring for a less common framework is harder, and moving people between teams becomes harder when services differ. These costs are paid every year, while the startup gain might matter only for a few services that scale up and down often.

5A Pilot With Clear Criteria

If the measurements show that DI and configuration are a large share of startup for services where startup matters, I would pilot. I would pick one service with real startup pain, such as one that autoscales often or runs as a function, and build two candidates: the service on Spring with AOT, CDS and trimmed starters, and the same service on the compile-time framework. Then I would compare startup time, memory at idle and under load, throughput, build time, how long a typical change takes developers, and what changes in deployment, monitoring and on-call.

I would agree the decision rule up front, for example: switch only if the new framework is at least 50 percent faster to start than optimised Spring and the business case values that, with no regression in throughput or observability. If the gain is clear, we use the new framework where startup matters most, not across the whole fleet. A fleet-wide switch for a gain we have only measured in benchmarks is how companies end up with two half-migrated stacks.

Step throughEvaluating a move to compile-time DI
  1. Measure startup phases in 3 to 4 real servicesBufferingApplicationStartup, /actuator/startup
  2. Is DI and configuration a large share?
    YesContinueNoOptimise I/O and libraries instead
  3. Apply AOT, CDS, lazy init, trimmed startersthe optimised Spring baseline
  4. Is startup still a business problem?
    YesPilot one service on both stacksNoStay on Spring
  5. Clear measured gain over optimised Spring?
    YesAdopt where startup mattersNoStay on Spring

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

Most evaluations stop at the first or second decision.

6Follow-up questions

When is a compile-time DI framework clearly the right choice?

When startup or memory dominates the cost and the service is small: serverless functions with frequent cold starts, command-line tools, or a fleet of tiny services where memory per instance multiplied by thousands of instances costs real money. A new service in such a niche, with a team willing to learn the framework, is a better candidate than rewriting an existing Spring service.

Why not just enable lazy initialisation everywhere?

Because it moves work and failures to the first request. A misconfigured bean that used to fail at startup, where the deployment stops, now fails when a customer hits it, and the first requests after each start are slower. It is useful for local development and tests, and for services where a slow first request is acceptable, but it is a trade, not a free gain.

How do you keep the comparison fair?

Use the same service, the same database and broker, the same JVM version and container limits, and measure both cold and warm starts several times. Compare against Spring with its optimisations applied, and include build time and developer experience in the results, since a framework that starts faster but slows every change is not a win.

7Conclusion

In this answer, we evaluated a move from Spring's runtime DI to a compile-time DI framework. We started by measuring startup phases, which often shows that I/O, ORM setup and migrations, not wiring, dominate. We compared against Spring's own options, AOT, CDS, lazy initialisation and trimming starters, and counted the costs a benchmark hides: lost integrations, two stacks to maintain and lost team familiarity. A pilot on one service with agreed criteria then decides, and any adoption targets the services where startup really matters rather than the whole fleet.

What to say in the interviewAbout 90 seconds aloud

Open with

I would treat it as a measurement question first. I would turn on BufferingApplicationStartup and Actuator's startup endpoint for three or four representative services and see where the seconds go.

Then, if they want more

In most business services, Hibernate initialisation, Flyway, and connections to databases and brokers take most of the time, and those cost the same in any framework; scanning, reflection and condition evaluation, which compile-time DI removes, may be one or two seconds out of eight.

Then I would compare with what Spring already offers, because the fair baseline is optimised Spring, not default Spring: AOT processing on the JVM, class data sharing, trimming starters we do not use, lazy initialisation where a slow first request is acceptable, and native images for the extreme cases.

I would also count the costs that do not appear in benchmarks: losing Spring Data, Security and our internal starters, rewriting services, running two stacks with different patching and observability, and losing team familiarity and easy hiring.

If startup is still a real business problem after that, I would pilot one service with genuine pain, like one that autoscales often, built both ways, and compare startup, memory, throughput, build time, developer speed and operations against criteria we agreed beforehand. I would adopt the new framework only where the measured gain matters, and avoid a fleet-wide switch.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 3.3
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 "Your company is weighing a move of some services from Spring's runtime dependency...": https://scrivio-interview-library.netlify.app/spring-boot/dependency-injection/f0be0517f9/