Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Build and restart times for a large Spring service are 4 minutes, and developers avoid running it locally. How would you improve inner-loop development?

First measure where the 4 minutes go, split into build, tests and context start-up, because each has a different fix. Then shorten each part: IDE incremental compilation with DevTools restart instead of full rebuilds, a fast test set separated from slow integration tests, Gradle or Maven build caches, and lazy or trimmed start-up for local runs. If the service is still slow after that, the size of the service itself is the problem, and splitting it into modules or smaller services is the lasting fix.

Why this question is asked

The inner loop is the cycle a developer repeats dozens of times a day: change code, build, run, check the result. When one turn takes 4 minutes, developers stop running the service, push changes to CI to test them, and lose focus while they wait. Interviewers ask this design question because the right answer starts with measurement rather than a favourite tool, and ends with a judgement about architecture. In this answer, we will measure the loop, then work on compilation and restart, tests, build caching and start-up, and finally look at when the real fix is modularising the service.

1Measure Where the Time Goes

A 4-minute loop is a total, and we cannot fix a total. The first step is to break it down. Gradle gives a build scan or a --profile report that shows each task's time; Maven can time its phases with a build extension or simply with timestamps in the log. For start-up, Spring Boot's ApplicationStartup support, BufferingApplicationStartup exposed through the Actuator startup endpoint, records how long each bean and each phase took.

Suppose the measurement looks like the table below. It changes the conversation immediately: the biggest cost is running the whole test suite on every build, not compiling, and context start-up is the second.

Java
// Record start-up steps for a local run
public static void main(String[] args) {
SpringApplication app = new SpringApplication(OrdersApplication.class);
app.setApplicationStartup(new BufferingApplicationStartup(10_000));
app.run(args);
}
// GET /actuator/startup -> steps such as spring.beans.instantiate with durations
// e.g. pricingRulesLoader 23.4 s (loads every rule from a remote service)
Where the 4 minutes went (example measurement)
StepTimeMain cause
Compile all modules35 sfull rebuild instead of incremental
Run all tests2 min 10 sintegration tests run on every build
Package the jar15 snot needed to run locally
Context start-up60 sone bean loads remote data, broad scanning
Measure first: the slowest step is often not the one we guessed.

2Compile Incrementally and Restart With DevTools

The loop should not rebuild and repackage the whole project to try a change. Running the application from the IDE, or with mvn spring-boot:run or gradle bootRun, avoids packaging entirely. The IDE compiles only the changed files, in a second or two.

DevTools then removes most of the restart cost. It keeps dependency jars in a base class loader and only reloads our classes in a fresh restart class loader, so a restart skips the JVM start and the loading of thousands of library classes. For small changes inside a method body, the debugger's hot swap can even avoid a restart. Together, these turn a full rebuild into a few seconds of compile plus a restart.

3Split Fast Tests From Slow Ones

Running every test on every local build is the most common cause of a slow loop. Unit tests, which test a class with no Spring context and no external systems, take milliseconds each. Integration tests, which start a Spring context and often a database in a container, take seconds each. A suite of 2,000 unit tests and 300 integration tests can spend 90 percent of its time in the integration tests.

So we separate them. Locally, developers run the fast set by default and the tests for the area they are changing; CI runs everything. In Maven, Surefire runs unit tests in the test phase and Failsafe runs integration tests in the verify phase; in Gradle, a separate test task or JUnit tags do the same. Within integration tests, reusing one Spring context across test classes, by avoiding needless @MockitoBean or property differences that force a new context, often halves their time.

Java
// JUnit tags separate the sets
@Tag("integration")
@SpringBootTest
class OrderFlowIT { ... }
// build.gradle
tasks.test { useJUnitPlatform { excludeTags("integration") } } // local default: about 20 s
tasks.register("integrationTest", Test) {
useJUnitPlatform { includeTags("integration") } // CI: about 2 min
}

4Use Build Caches

A build cache stores the outputs of build steps, keyed by their inputs. If nothing that a task depends on has changed, the build reuses the stored output instead of running the task again. Gradle has a local build cache and supports a remote one shared by CI and developers, so a module that CI already compiled and tested on the same inputs does not need to be built again on a laptop. For Maven, the Apache Maven Build Cache Extension provides a similar incremental cache; check its current status and limits for your version.

Caches pay off most in multi-module builds, where a change in one module leaves the others untouched. They also make the next step, modularisation, much more effective.

5Make Local Start-up Lighter

A 60-second context start usually has a few heavy causes, and the startup endpoint names them. A bean that loads remote data at start-up can load lazily or use a local stub in a dev profile. A broad component scan or unused auto-configuration can be narrowed. For local runs only, spring.main.lazy-initialization=true creates beans when they are first used instead of at start-up, which can cut start time sharply, at the cost of finding wiring errors later. Local dependencies such as databases and brokers can start once with Docker Compose support or Testcontainers and stay up across restarts, instead of starting with every run.

YAML
# application-local.yaml
spring:
main:
lazy-initialization: true # 60 s -> about 18 s in our example
pricing:
rules:
source: classpath:rules-sample.json # instead of the remote service

6When the Service Is Simply Too Large

If, after all this, start-up and builds are still slow, the service is probably doing too much. A single deployable with 40 modules, 900 beans and five teams committing to it will always have a slow loop, and every team pays for the others' code.

There are two steps, in order of cost. First, modularise inside the build: clear Gradle or Maven modules with enforced boundaries, so caches and incremental builds skip most of the code, and tests can be run per module. Spring Modulith can help verify module boundaries. Second, if parts have different owners, release rhythms or scaling needs, extract them into separate services. That is a bigger decision with its own costs in operations and consistency, so it should be driven by more than build time, but a painful inner loop is often the first visible symptom.

Step throughImproving the inner loop, in order
  1. Measure build, tests, start-upbuild scan, startup endpoint
  2. IDE incremental compile + DevToolsseconds instead of minutes
  3. Fast tests locally, all tests in CItags or Surefire and Failsafe
  4. Local and remote build cachesskip unchanged modules
  5. Lighter local start-uplazy init, stubs, long-lived containers
  6. Still too slow?
    YesModularise or split the serviceNoKeep measuring each quarter

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

7Follow-up questions

What target would you set for the inner loop?

For a change in one class, I aim for under 10 seconds from saving the file to seeing the result in a running application, and under a minute for the local fast test set. Those numbers are what keeps developers running the service instead of waiting for CI. Publishing the measured numbers on a dashboard keeps them from creeping back up.

Is lazy initialisation safe to use?

For local runs it is usually fine and very effective. In production it moves failures from start-up to the first request that needs a broken bean, and it can make the first requests slow, so I keep it in a local profile only and keep eager initialisation in tests and production.

How do you persuade teams to invest in this?

Turn the waiting time into a number. If 30 developers each run the loop 20 times a day and save 3 minutes per run, that is 30 hours a day, almost four full-time engineers. Few investments show such a clear return.

8Conclusion

In this answer, we saw that a slow inner loop must first be measured, split into build, tests and start-up. We then shortened each part: IDE incremental compilation and DevTools restart, fast tests locally with integration tests in CI, local and remote build caches, and lighter local start-up with lazy initialisation, stubs and long-lived dependency containers. When the service stays slow after that, modularising it, or splitting it, is the lasting fix.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by measuring, because four minutes is a total and each part has a different fix. A Gradle build scan or Maven timings show build and test time, and BufferingApplicationStartup with the Actuator startup endpoint shows which beans slow the context.

Then, if they want more

Often most of the time is tests. Then I would work through the parts. Developers run the app from the IDE or with bootRun, with incremental compilation and DevTools, so a change is a couple of seconds of compiling plus a restart that reuses all the dependency classes.

Tests get split: unit tests run locally by default, integration tests are tagged or run by Failsafe and always run in CI, and we stop forcing new Spring contexts in tests. We add build caching, Gradle's local and remote cache or the Maven build cache extension, so unchanged modules are skipped.

For start-up, a local profile with lazy initialisation and stubs for remote data, and Docker Compose or Testcontainers dependencies that stay up across restarts. I would set a target, say under ten seconds for a one-class change.

If it is still slow after all that, the service is too big, and I would modularise the build first and consider splitting the service where ownership and release needs differ.

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 "Build and restart times for a large Spring service are 4 minutes, and developers avoid...": https://scrivio-interview-library.netlify.app/spring-boot/developer-experience/7151eab174/