Quick revision
The short answer
My principle is that wiring and configuration errors must surface at build time or at startup, never in production traffic. Any optimisation that delays them, such as lazy initialization, needs compensating checks like tests that start the full context, while optimisations that move checks earlier, as AOT does, are welcome. I would write this down as a platform rule, check it in CI, and allow exceptions only with explicit review.
What to remember
In this answer, we saw that the cost of a wiring or configuration error grows sharply the later it surfaces, so the long-term principle is that such errors must appear at build or startup, never in production traffic. Optimisations that delay errors, like lazy initialization, need compensating checks such as an eager full-context test; optimisations that move checks earlier, like AOT, are welcome. The principle becomes a written platform rule, checked in CI, with exceptions only after explicit review.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
My principle is that wiring and configuration errors must surface at build time or at startup, never in production traffic. Any optimisation that delays them, such as lazy initialization, needs compensating checks like tests that start the full context, while optimisations that move checks earlier, as AOT does, are welcome. I would write this down as a platform rule, check it in CI, and allow exceptions only with explicit review.
Why this question is asked
Every few years a new startup optimisation arrives, and each one quietly changes when mistakes become visible. Lazy initialization delays them, AOT processing brings some forward, and checkpoint-based techniques can freeze state at build time. Without a principle, each team decides alone, usually by looking at the startup number. Interviewers ask this of senior leaders to hear a rule that will still be right after the next optimisation arrives. In this answer, we will see why the moment of failure matters, state the principle, look at how common optimisations score against it, and turn it into a platform rule with checks and an exception process.
1Why the Moment of Failure Matters
A wiring error, such as a missing bean, or a configuration error, such as a malformed URL, has the same cause wherever it appears, but its cost depends on when it appears. Found at build time, it costs a developer a few minutes. Found at startup, it fails a deploy, which is visible and safe, because the old version keeps serving. Found in production traffic, it hits users, happens far from the change that caused it, and costs an incident.
So the cost of an error grows sharply the later it surfaces, often by orders of magnitude. That makes the moment of failure an engineering property worth managing, just like startup time or latency.
| Surfaces at | Who notices | Typical cost |
|---|---|---|
| Build (compile, AOT, tests) | Developer | Minutes |
| Startup (deploy) | Pipeline, deployer | A failed deploy, old version keeps serving |
| First use in production | A user | An incident, investigation, trust |
| Rare path weeks later | A user, much later | Hard diagnosis, far from the change |
2Stating the Principle
The principle I would set is short: wiring and configuration errors must surface at build or startup, not in production traffic. It is not a ban on any technique. It says that whatever we do to make startup faster, the guarantee that a broken configuration fails before users see it must hold.
From that follows a simple test for any optimisation: does it move errors earlier, keep them where they are, or move them later? Earlier is welcome. Later is allowed only if something else restores the guarantee.
3How Common Optimisations Score
Lazy initialization moves errors later: beans that are never created at startup cannot fail at startup. Used in production, it needs compensating checks, such as a CI test that starts the full context eagerly with production-like configuration, and smoke tests after deploy that exercise each feature.
Spring AOT processing moves some checks earlier. It evaluates the bean definitions at build time and generates code for them, so certain problems, such as conditions that cannot be resolved or a bean definition that cannot be built, fail the build. That is good, with one caution: AOT fixes the bean arrangement at build time, so a profile or property that changes which beans exist at runtime may not behave as expected, which is itself a reason to keep such decisions at build time. GraalVM native image goes further and fails the build on many reachability problems, though missing reflection hints can still fail at runtime unless tests run on the native image.
- Does it move errors later?YesRequire compensating checksNoAccept, note any new risks
- Compensating checks in CI?YesAccept the optimisationNoReject or add checks first
- Record the decisionplatform rule and exception register
3 steps in order. Play them, or step through them one at a time.
4Writing It as a Platform Rule and Checking It in CI
A principle that lives only in a talk is forgotten. The platform guide should state it, and the pipeline should enforce it. Every service's CI runs a test that starts the full application context with production-like configuration and eager initialization, regardless of what production uses, so every bean is created at least once before release. Configuration properties are validated with @Validated, so bad values fail that test.
A CI rule can also flag spring.main.lazy-initialization=true in production configuration files and require the exception process described next. Services that use AOT or native images also run their tests on the AOT-processed application, so the build checks what will actually run.
5Exceptions, With Explicit Review
Some workloads have good reasons to bend the rule, for example a function that must start in under a second and uses lazy initialization or a checkpoint. Those are allowed, but only with an explicit review: the team writes down which errors may now surface later, which compensating checks they add, and who owns the risk. The decision goes into an exception register with a review date.
This keeps the principle durable. When the next optimisation arrives, the question is not whether it is fashionable but where it moves errors, and the review process already exists to answer it.
6Follow-up questions
Is it realistic to catch all wiring errors before production?
Not all, but almost all wiring and configuration errors can be caught by starting the full context with production-like configuration. Errors that depend on real data or rare inputs are a different class, handled by testing and monitoring.
Does the eager CI test make startup slower for developers?
It runs in CI, not on every local restart, so developers can keep lazy initialization locally. The cost is one context start per build, usually seconds.
How would you persuade teams who like their fast lazy startup?
Show the cost table with a real incident, and offer the alternative: profile startup and fix the slow beans, which usually recovers most of the time without moving errors. Then the rule asks them to give up very little.
7Conclusion
In this answer, we saw that the cost of a wiring or configuration error grows sharply the later it surfaces, so the long-term principle is that such errors must appear at build or startup, never in production traffic. Optimisations that delay errors, like lazy initialization, need compensating checks such as an eager full-context test; optimisations that move checks earlier, like AOT, are welcome. The principle becomes a written platform rule, checked in CI, with exceptions only after explicit review.
Open with
The principle I would set is that wiring and configuration errors must surface at build time or at startup, never in production traffic. The reason is cost. The same missing bean costs minutes at build time, a failed but safe deploy at startup, and an incident if a user finds it.
Then, if they want more
So for every startup optimisation I would ask one question: does it move errors earlier or later? AOT processing moves some checks to build time, because bean definitions are evaluated during the build, so I welcome it, while making sure profile-dependent bean decisions are also made at build time.
Lazy initialization moves errors later, because beans that are not created cannot fail at startup, so if a team uses it in production they need compensating checks. The main one would be a platform-provided test that every service runs in CI: start the full context eagerly with production-like configuration and validated properties, so every bean is created once before release.
I would also want smoke tests after deploy for lazy services. Then I would write the principle down in the platform guide, enforce it in CI, flag lazy initialization in production config, and accept exceptions only through an explicit review that records the compensating checks and the owner of the risk.
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 "Lazy initialization, AOT and other startup optimisations each change when errors appear....": https://scrivio-interview-library.netlify.app/spring-boot/boot-startup/582851a5e9/