Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Spring's lifecycle model was designed for long-running application servers. With containers, autoscaling and serverless, what changes in how you design startup and shutdown?

In containers, autoscaling and serverless, startup and shutdown stop being rare events and become part of normal operation. Startup time now drives scaling speed, cost and recovery, so heavy initialisation must be measured and reduced; shutdown happens many times a day and must be graceful, draining traffic, finishing work and releasing resources. Readiness and liveness should reflect the application's lifecycle state rather than the mere existence of a process, AOT, CDS and checkpoint/restore move work from runtime to build time, and all of this should be standardised in shared starters so every service behaves the same.

Why this question is asked

Spring's lifecycle grew up in a world where an application server started on Monday and ran for weeks. A two-minute startup was an inconvenience, and shutdown was a planned maintenance event. Today a service may start and stop dozens of times a day as pods are rescheduled, nodes are drained and traffic rises and falls. Interviewers ask this at the twenty-year level to hear how an architect rethinks the design of startup and shutdown for that world, and how to turn those ideas into something hundreds of services follow. In this answer, we will look at what changed, then at startup, shutdown, health signals and build-time work, and finally at how to standardise it.

1What Changed, and Why It Matters

The bean lifecycle itself has not changed much: Spring still creates singletons, calls their init callbacks, runs the application and destroys the beans in order at shutdown. What changed is how often each phase runs and who is waiting for it. In a container platform, every scale-out waits for startup, every deployment is a wave of shutdowns and startups, and every node maintenance moves pods around. In serverless platforms, a cold start can sit directly in a user's request.

So two properties that used to be nice to have become operational requirements. Startup time is now part of how fast we can absorb a traffic spike and how fast we recover from failures. Shutdown behaviour is now part of whether a normal deployment produces errors. Both must be designed and measured, not left to whatever the beans happen to do.

Old and new assumptions about the lifecycle
ConcernLong-running serverContainers and serverless
How often it startsweekly or monthlymany times a day per service
Who waits for startupan operatorautoscaling, users, failure recovery
How it stopsplanned maintenanceSIGTERM at any time, with a grace period
Health signalprocess is runningready for traffic, alive, or draining
Where startup work runsalways at runtimepartly moved to build time

2Startup: Measure It and Make It Cheap

The first change is to treat startup time as a budget. If a checkout service takes 60 seconds to become ready, then adding capacity during a sudden spike takes at least a minute, and the autoscaler must keep extra idle pods to cover that gap, which costs money every hour. If it takes 10 seconds, we can run leaner and react faster.

So we measure it. Spring Boot can record startup steps with BufferingApplicationStartup, and the actuator startup endpoint shows which beans took longest. In most services a few beans dominate: a cache loaded from a database, a client that downloads metadata, a remote configuration lookup. The design rule that follows is simple: the context should start quickly and locally, and expensive or remote work moves to after startup, with readiness telling the platform when the service is truly ready, rather than hidden in @PostConstruct methods that block everything.

Java
// main(): record startup steps
SpringApplication app = new SpringApplication(CheckoutApp.class);
app.setApplicationStartup(new BufferingApplicationStartup(4096));
app.run(args);
// GET /actuator/startup (shortened): the three slowest steps
// spring.beans.instantiate beanName=productCache PT21.4S <- loads 2 million rows in @PostConstruct
// spring.beans.instantiate beanName=taxRulesClient PT6.2S <- remote call at startup
// spring.beans.instantiate beanName=entityManagerFactory PT3.1S

3Shutdown: Frequent, So It Must Be Graceful

When a pod is stopped, Kubernetes sends SIGTERM, waits for a grace period, 30 seconds by default, and then kills the process. In that window the service must do three things in the right order: stop receiving new work, finish the work it already accepted, and release its resources. Spring gives us the pieces. Graceful shutdown of the web server, server.shutdown=graceful and the default in recent Spring Boot versions (check your version), stops accepting requests and drains in-flight ones in a SmartLifecycle phase. Message listener containers and task executors have their own stop and await settings. Only after these phases does Spring destroy singletons, running @PreDestroy and closing pools.

The architectural point is that shutdown must be designed for the whole service, not bean by bean. A preStop delay covers the seconds in which load balancers are still routing to the pod. Long jobs must be resumable or idempotent, because a pod may be stopped in the middle of one, and in serverless platforms there may be almost no shutdown phase at all. Anything that must not be lost is written durably when it happens, never kept in memory until @PreDestroy.

Step throughA designed shutdown for one pod
  1. preStop delayload balancers stop routing
  2. SIGTERM: readiness refuses traffic
  3. Web server drains requestsgraceful shutdown phase
  4. Listeners and executors stop and finish worktheir own SmartLifecycle phases
  5. Singletons destroyed@PreDestroy, pools and clients closed
  6. Done before the grace period?
    YesClean exitNoSIGKILL: remaining work lost

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

4Health Signals That Reflect the Lifecycle

In the old world, 'healthy' meant the process was running. A platform needs finer signals, and Spring Boot provides them as availability states. Liveness says whether the process is in a working state or broken beyond repair, which is what Kubernetes uses to decide on a restart. Readiness says whether it should receive traffic now, which can be false during warm-up, during shutdown, or while a critical dependency is unavailable. Spring Boot publishes these states as the lifecycle progresses, setting readiness to refuse traffic when the context starts closing, and exposes them at /actuator/health/liveness and /actuator/health/readiness.

The design rule is to connect these signals to real lifecycle state and to keep them separate. Readiness may include our own warm-up indicator. Liveness should almost never include external dependencies, because a database outage that makes every pod fail liveness would cause the platform to restart all of them at once, turning a dependency problem into a restart storm.

5Moving Work From Runtime to Build Time

The newer tools change the lifecycle model itself. Class data sharing and the JDK's AOT cache move class loading and linking work into an archive created during the build or a training run. Spring AOT evaluates configuration at build time and generates code that registers beans directly, and GraalVM native images compile the whole application ahead of time, so the runtime skips much of what the bean factory normally does. Checkpoint/restore goes further and saves a warmed, running process, so a new instance resumes after startup instead of performing it.

Each of these shifts a decision. With AOT, conditions and profiles are fixed at build time. With checkpoint/restore, beans that hold sockets or files must close them before the checkpoint and reopen them after restore through Lifecycle callbacks, and secrets captured in the snapshot need care. So the architect's question becomes which work truly needs runtime information and which can be done once, earlier, and the answer differs per class of service.

6Standardising It in Starters

None of this works if each team rediscovers it. I would put the patterns into the company's shared Spring Boot starter: probe endpoints enabled with the right groups, graceful shutdown and phase timeouts set consistently with the platform's grace period, a warm-up framework that runs after ApplicationReadyEvent and feeds readiness, sensible executor and listener shutdown settings, and startup recording with a warning when a bean's initialisation exceeds a budget. The deployment templates carry the matching preStop delay and probe settings.

Then I would make the behaviour visible with dashboards of startup time and deployment errors per service, and a short guide explaining each default. The goal is that a new service gets fast, predictable startup and clean shutdown by default, and that deviating from it is a conscious, documented decision.

7Follow-up questions

How do you justify the effort to management?

With numbers that already matter to them: the idle capacity we pay for because scale-out is slow, the error rate during each deployment, and the time to recover from a node failure. Reducing startup from 60 to 15 seconds and removing deployment errors are easy to show on a dashboard and translate directly into cost and reliability.

Does serverless change the advice?

It makes it stricter. Startup may be inside a user request, so native images, checkpoint/restore or very light contexts matter more, and there may be no reliable shutdown phase, so work must be durable and idempotent from the start rather than cleaned up at the end.

8Conclusion

In this answer, we saw that containers, autoscaling and serverless turn startup and shutdown into everyday operations. Startup time drives scaling, cost and recovery, so we measure it and move heavy work out of initialisation. Shutdown is frequent, so it must drain traffic, finish work and release resources in a designed order within the grace period. Readiness and liveness should reflect real lifecycle state, AOT, CDS and checkpoint/restore move work to build time with their own trade-offs, and a shared starter plus deployment templates make every service behave the same.

What to say in the interviewAbout 80 seconds aloud

Open with

The lifecycle model itself still works, but the assumptions around it changed. Services now start and stop many times a day, so startup and shutdown are normal operations, not maintenance events.

Then, if they want more

For startup, I treat time to ready as a budget, because it decides how fast we scale out, how much idle capacity we pay for, and how quickly we recover from a failed node.

We measure it with BufferingApplicationStartup and the actuator startup endpoint, and usually a few beans that load data or call remote systems in @PostConstruct dominate, so that work moves after startup and readiness reflects it.

For shutdown, SIGTERM can come at any time with a grace period, so the service must stop taking work, drain what it accepted and then release resources: a preStop delay, graceful shutdown of the web server, proper stop phases for listeners and executors, and only then bean destruction, with durable writes for anything that must not be lost.

Health should reflect lifecycle state: readiness for warm-up and draining, liveness only for the process itself, never for dependencies. AOT, CDS and checkpoint/restore move work to build time, each with trade-offs. And I would standardise all of it in the shared starter and deployment templates, with dashboards so teams can see the effect.

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.
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 "Spring's lifecycle model was designed for long-running application servers. With...": https://scrivio-interview-library.netlify.app/spring-boot/bean-lifecycle/a22ad205c6/