Quick revision
The short answer
I would set a standard that @PostConstruct never makes remote calls, because they block context startup and a dependency that is down fails the whole application. Warm-up runs after startup, for example on ApplicationReadyEvent, with timeouts and a degraded mode when a dependency is unavailable, and the service reports ready only when warm-up completes, through a readiness health indicator. The pattern ships in a shared starter so every team gets it the same way.
What to remember
In this answer, we set a standard for startup work. Remote calls do not belong in @PostConstruct, because they block context startup and turn an outage in a dependency into a failure of every service. Warm-up runs after ApplicationReadyEvent on its own thread, with timeouts and an explicit choice between starting degraded and staying not ready. A readiness health indicator exposes the warm-up state while liveness stays independent of dependencies, and the whole pattern ships in a shared starter so every team behaves the same.
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.
I would set a standard that @PostConstruct never makes remote calls, because they block context startup and a dependency that is down fails the whole application. Warm-up runs after startup, for example on ApplicationReadyEvent, with timeouts and a degraded mode when a dependency is unavailable, and the service reports ready only when warm-up completes, through a readiness health indicator. The pattern ships in a shared starter so every team gets it the same way.
Why this question is asked
Warming caches and checking dependencies at startup is a reasonable instinct: we want the first request to be fast and we want to know early if something is wrong. But when dozens of services do it inside @PostConstruct, startup becomes slow and fragile, and an outage in one dependency can stop every other service from starting, which turns a partial outage into a total one. Interviewers ask this at the fifteen-year level to see whether we can turn a technical understanding of the lifecycle into a standard that many teams follow. In this answer, we will look at why @PostConstruct is the wrong place, what the standard pattern is, how readiness and Kubernetes probes fit in, how to degrade gracefully, and how to roll the pattern out through a starter.
1Why Remote Calls in @PostConstruct Hurt
A @PostConstruct method runs while Spring is building the application context, on the single startup thread, inside the creation of that one bean. Every other bean that comes after it waits. If a cache warm-up calls a catalogue service and takes 20 seconds, startup takes 20 seconds longer, and Kubernetes cannot even tell whether the application is stuck or busy, because the web server and health endpoints may not be up yet.
Worse, an exception in @PostConstruct fails the creation of the bean, and that fails the whole context. So if the catalogue service is down, our service does not start at all. In Kubernetes the pod crashes, restarts, crashes again and goes into CrashLoopBackOff. Now picture twenty services doing this during an incident in a shared dependency: none of them can start or scale, even for the requests that do not need that dependency. The startup design has turned one failure into many.
| In @PostConstruct | After ApplicationReadyEvent | |
|---|---|---|
| Startup time | includes every remote call | context ready in seconds |
| Dependency down | context fails, CrashLoopBackOff | service starts, reports not ready or degraded |
| Visibility | no health endpoint until it finishes | readiness shows warm-up state |
| Timeouts | often missing, startup hangs | required by the standard |
| Retry | whole pod restarts | warm-up retries in the background |
2The Standard: Warm Up After Startup
The rule I would write is short: @PostConstruct may only do fast, local work, such as validating configuration or building an in-memory structure from data already available. Anything that calls a database, another service or a remote cache runs after the application has started. Spring Boot publishes ApplicationReadyEvent when the context is complete and the web server is running, which is the natural trigger.
The warm-up should run on its own thread, so it does not hold up the event publishing, and it should record its state somewhere a health indicator can read it. The code below shows the shape of it.
Notice that the class reports three states, not two. PENDING keeps the instance out of traffic. DONE and DEGRADED both let it in, the second with a detail that dashboards and alerts can show. The decision about whether a failed warm-up should block traffic is made explicitly, per service, instead of by an exception that happens to crash startup.
3Readiness and Kubernetes Probes
Kubernetes uses three probes. A startup probe gives a slow application time to start before the other probes begin. A liveness probe decides whether the container should be restarted. A readiness probe decides whether the pod receives traffic. Spring Boot exposes the last two as /actuator/health/liveness and /actuator/health/readiness when it runs on Kubernetes, and we can add our own indicators to the readiness group.
- Context starts
@PostConstructdoes local work only - ApplicationReadyEventwarm-up thread starts
- Readiness OUT_OF_SERVICEliveness UP, no traffic yet
- Warm-up finished in time?YesState DONE, readiness UPNoState DEGRADED, readiness UP with detail
- Pod receives trafficcache fills on demand if degraded
5 steps in order. Play them, or step through them one at a time.
The important part is what we leave out of liveness. Liveness should only say whether this process is healthy, not whether its dependencies are. If liveness included the warm-up or the catalogue service, an outage there would make Kubernetes restart every pod in a loop, which is exactly the cascade we are trying to avoid. Readiness is the right place for 'not ready yet'.
4Degrading Gracefully When Dependencies Are Down
Every remote call in a warm-up needs a timeout, because a dependency that hangs is worse than one that fails fast. The standard should give a default, for example 5 seconds per call and 60 seconds for the whole warm-up, and require a written decision for each warm-up: if it cannot complete, does the service start degraded, or stay not ready?
For most caches, starting degraded is right: the cache fills on demand, the first requests are a little slower, and the service is available. For a few services, being cold is genuinely unsafe, for example a pricing service that must not answer from an empty table. Those stay not ready, and the readiness probe keeps them out of traffic without crashing them, so they recover by themselves when the dependency returns, instead of restarting in a loop.
5Rolling It Out Through a Shared Starter
A standard that each team implements by hand will be implemented twenty different ways. So the platform team puts the pattern into the company's shared Spring Boot starter: a small WarmUpTask interface that services implement, a runner that executes the tasks on ApplicationReadyEvent with the default timeouts, one readiness indicator that reports their combined state, and the probe configuration above. A service then writes only its warm-up logic.
I would also add a check that makes the rule visible: the starter can log a warning when a bean's @PostConstruct takes more than, say, 500 milliseconds, using the startup step data Spring Boot can record. And the standard needs a short document with the reasons, because teams follow rules they understand much more reliably than rules they are given.
6Follow-up questions
What should go in a startup probe for such a service?
The startup probe can point at liveness with a generous failure threshold, so Kubernetes waits long enough for the context to start. Since the slow warm-up now happens after startup and is covered by readiness, the startup probe only needs to cover context startup, which the standard keeps short.
Is it ever right to fail startup when a dependency is missing?
Yes, for configuration that is simply wrong, such as a missing URL or credential, because no amount of waiting fixes it and a failed rollout is the safest outcome. The distinction is between our own configuration, which we validate at startup, and the availability of other systems, which we handle at runtime.
How do you handle many instances warming up at once?
If fifty pods start together, their warm-ups hit the dependency together. The starter can add random jitter before each warm-up and limit concurrency, and large caches can be loaded from a shared snapshot instead of from the source service.
7Conclusion
In this answer, we set a standard for startup work. Remote calls do not belong in @PostConstruct, because they block context startup and turn an outage in a dependency into a failure of every service. Warm-up runs after ApplicationReadyEvent on its own thread, with timeouts and an explicit choice between starting degraded and staying not ready. A readiness health indicator exposes the warm-up state while liveness stays independent of dependencies, and the whole pattern ships in a shared starter so every team behaves the same.
Open with
The standard I would set is that @PostConstruct only does fast local work, like validating configuration, and never calls remote systems. The reason is that @PostConstruct runs on the startup thread while the context is being built, so every remote call adds to startup time, and any exception fails the whole context.
Then, if they want more
When a shared dependency is down, every service that warms up from it crash-loops, and a partial outage becomes a total one. Instead, warm-up runs after startup, triggered by ApplicationReadyEvent, on its own thread, with a timeout on every call and a time limit for the whole warm-up.
Each service decides explicitly what happens if warm-up fails: most start degraded and fill caches on demand, and a few that must not run cold stay not ready.
The state is exposed through a readiness health indicator in the readiness group, so Kubernetes only sends traffic when warm-up is done, while liveness stays independent of dependencies so we never restart pods because someone else is down.
Then I would put the whole thing into our shared starter: a warm-up task interface, the runner with default timeouts and jitter, the combined readiness indicator and the probe settings, plus a warning for slow @PostConstruct methods and a short document explaining why.
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 Framework reference, Core technologies
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 "Many services warm caches and call remote services in @PostConstruct, and startup in...": https://scrivio-interview-library.netlify.app/spring-boot/bean-lifecycle/cba50d6d74/