Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Frequent deployments and autoscaling mean your services start and stop thousands of times a day. How do you set standards for startup and shutdown behaviour across the company and keep them enforced?

We write down the behaviour every service must have, namely a graceful drain at shutdown, a bounded shutdown time that fits the platform's grace period, and readiness only after warm-up, and then we implement it once, in a shared Spring Boot starter built on graceful shutdown and lifecycle phases. We keep it enforced with a shutdown-under-load test in every pipeline and a fleet-wide metric of errors during deployments, and we review the standard whenever the platform or Spring's defaults change.

Why this question is asked

When a company deploys many times a day and autoscales on load, its services start and stop thousands of times daily. Each start or stop that is slightly wrong costs a handful of failed requests, duplicated messages or slow first responses. One bad shutdown is noise; thousands a day become a steady error rate that nobody can explain. Interviewers ask this leadership question to see whether we can turn a technical concern into a standard that hundreds of engineers follow without thinking about it. In this answer, we will define what good startup and shutdown look like, see how to implement it once instead of in every service, how to test and measure it, and how to keep the standard alive as things change.

1Why Starts and Stops Become a Fleet Problem

Consider a fleet of 300 services, each with several instances, deployed a few times a day and scaled up and down with traffic. That easily gives 5,000 instance starts and stops a day. If each careless shutdown drops just two in-flight requests, that is 10,000 failed requests daily, spread thinly across every service so that no single team sees a problem worth fixing. The same applies to startup: an instance that is marked ready before its caches and connection pools are warm serves its first requests slowly, and with autoscaling that happens exactly when load is highest.

This is why the problem needs a company-level answer. Each team can fix its own service, but the knowledge involved, such as Kubernetes termination timing, Spring lifecycle phases and Kafka consumer group behaviour, is specialised and easy to get wrong. A standard captures that knowledge once.

2Defining the Required Behaviour

A standard has to be short and testable, otherwise nobody follows it. We describe behaviour, not implementation. At shutdown, a service stops receiving new traffic before it stops serving, finishes in-flight requests, messages and jobs, and exits within a bounded time that is smaller than the platform's grace period. At startup, a service reports ready only after it can serve real requests at normal speed: connections opened, caches and JIT warmed if that matters, and its Kafka consumers joined. Liveness, meaning the process is not stuck, is kept separate from readiness, so a slow warm-up never causes a restart loop.

Company standard for start and stop
RequirementConcrete ruleHow we check it
Drain before stopno new traffic after SIGTERM + 5sshutdown-under-load test in CI
Bounded shutdownapp done in 40s; grace period 60sphase timings in CI and in production
No lost workrequests finish, offsets after processingtest counts lost and duplicate items
Ready means warmreadiness after pools and warm-upp99 latency of first minute per instance
Liveness is separateliveness never waits on dependenciesprobe configuration in the starter
Each rule is a number or a yes/no question, so it can be tested.

3Implementing It Once in a Starter

The standard only works if following it is the easy path. So we implement it in the company's internal Spring Boot starter, the dependency every service already has. The starter sets server.shutdown=graceful, sets spring.lifecycle.timeout-per-shutdown-phase to a value that fits our grace period, enables the health probe groups for liveness and readiness, configures executors and schedulers to wait for tasks at shutdown, and gives our shared components, such as the messaging wrapper and the outbox relay, SmartLifecycle phases that stop them in the right order. Teams get the behaviour by upgrading a version number.

Properties
# Defaults in the company starter (application defaults, overridable per service)
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=20s
management.endpoint.health.probes.enabled=true
management.endpoint.health.group.readiness.include=readinessState,db,warmup
spring.task.execution.shutdown.await-termination=true
spring.task.execution.shutdown.await-termination-period=20s
# Platform template: preStop sleep 5s, terminationGracePeriodSeconds 60

Notice the readiness group includes a warmup indicator. The starter provides a small hook where a service registers its warm-up work, such as loading a reference cache, and readiness stays down until it finishes. The platform template matches the numbers: 5 seconds for endpoints to update, 20 seconds per lifecycle phase, and a margin below the 60 second grace period. Keeping these numbers in one place is what stops them drifting apart.

4Enforcing It With Tests and Fleet Metrics

A standard that is not checked decays. We enforce it in two places. In CI, the starter ships a reusable test that starts the service with Testcontainers, sends a steady load of requests and messages, triggers shutdown in the middle, and fails if any request got a connection error, if any message was lost, or if shutdown took longer than its budget. Because it is one shared test, teams adopt it with a few lines.

In production, we measure it as a fleet metric: errors and connection resets during deployment windows, Kafka rebalance duration and duplicate deliveries, instances killed by SIGKILL after the grace period, and first-minute latency of new instances. We publish it per service on a shared dashboard. This turns a hidden cost into a visible number, and it lets us talk to the few teams with real problems instead of reminding everyone.

Step throughKeeping the standard enforced
  1. Standard written as testable rules
  2. Starter implements defaultsteams upgrade a version
  3. Shared shutdown test in every pipelinefails the build
  4. Fleet metric: errors during deploymentsper service dashboard
  5. Service above threshold?
    YesWork with that teamNoNothing to do
  6. Review on platform or Spring changesupdate starter and numbers

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

Most services get the behaviour for free; effort goes to the outliers.

5Reviewing the Standard When Things Change

The right numbers and settings depend on the platform and on Spring's defaults, and both move. Spring Boot 3.4 made graceful shutdown the default for embedded servers; a new Kubernetes version or service mesh may change how quickly endpoints update; a switch to virtual threads may change how executors drain. We review the standard on each Spring Boot minor upgrade and each platform change, with an owner named for it, and record the reasoning behind each number so the next person can change it safely. A standard is a living agreement, and the shared test is what tells us when it no longer holds.

6Follow-up questions

How do you get teams to adopt the starter if they have their own setup?

We make adoption cheap and visible. The fleet dashboard shows each service's deployment error rate, which gives teams a reason; the starter gives them a fix that costs a version bump; and for services with unusual needs we accept documented overrides. Mandating it without data rarely works, but showing a team that their deployments cause 400 errors a day usually does.

What is a sensible bounded shutdown time?

It depends on the work. For request-serving services, 20 to 30 seconds is usually plenty, because requests last milliseconds or seconds. For services running long jobs, the answer is not a longer timeout but jobs that checkpoint and resume. The bound must always be lower than the platform's grace period, otherwise the platform kills the process and the drain is wasted.

Why keep liveness separate from readiness?

Because they answer different questions. Readiness says whether the instance should get traffic now, and it may be down during warm-up or when a dependency is unavailable. Liveness says whether the process is stuck and should be restarted. If liveness depended on warm-up or on a database, a slow start or a database outage would make the platform restart every instance, which turns a small problem into an outage.

7Conclusion

In this answer, we saw how to turn startup and shutdown behaviour into a company standard. We defined the required behaviour as short, testable rules, such as graceful drain, bounded shutdown time and readiness only after warm-up, implemented them once in a shared starter on top of Spring Boot's graceful shutdown and lifecycle phases, enforced them with a shared shutdown-under-load test and a fleet metric of deployment errors, and reviewed the standard whenever the platform or Spring's defaults change.

What to say in the interviewAbout 80 seconds aloud

Open with

With thousands of starts and stops a day, small mistakes add up to a steady error rate, so I would treat it as a fleet standard. First I would define the behaviour in a few testable rules: stop receiving traffic before stopping serving, finish in-flight requests, messages and jobs, exit within a bound below the platform's grace period, and report ready only after warm-up, with liveness kept separate.

Then, if they want more

Then I would implement it once in our internal Spring Boot starter: graceful shutdown, a timeout per shutdown phase that fits the grace period, probe groups including a warm-up indicator, executors that wait for tasks, and lifecycle phases for our shared messaging components, with the platform template using matching numbers.

To enforce it, the starter ships a shared test that shuts the service down under load and fails on lost or failed work, and we track errors during deployments, SIGKILLs and first-minute latency per service as a fleet metric on a dashboard, so we can help the outliers.

Finally I would name an owner and review the standard with each Spring Boot upgrade or platform change, since defaults like graceful shutdown changed in Boot 3.4.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 3.4
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 "Frequent deployments and autoscaling mean your services start and stop thousands of...": https://scrivio-interview-library.netlify.app/spring-boot/bean-lifecycle/c4880925e6/