Quick revision
The short answer
To make deploys invisible, I would set standards at four levels: every service supports graceful shutdown with tested settings, the platform coordinates load balancer removal, preStop delays and termination grace periods so no team has to get the timing right alone, clients retry idempotent requests on connection errors, and we measure the error rate during deploys as a quality metric. Then we practise deploys under load in staging so the standards are proven rather than assumed.
What to remember
In this answer, we saw that deploy errors repeat because the timing between load balancer, application and process stop is easy to get wrong and is often left to each team. The long-term standard is graceful shutdown with tested settings in every service, platform-owned coordination of load balancer removal, preStop delays and grace periods, bounded client retries for idempotent requests, deploy error rate as a tracked metric, and regular deploy practice under load in staging.
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.
To make deploys invisible, I would set standards at four levels: every service supports graceful shutdown with tested settings, the platform coordinates load balancer removal, preStop delays and termination grace periods so no team has to get the timing right alone, clients retry idempotent requests on connection errors, and we measure the error rate during deploys as a quality metric. Then we practise deploys under load in staging so the standards are proven rather than assumed.
Why this question is asked
Deploy-time errors are a quiet tax. Each one is small, a few failed requests or a brief spike of 502s, so no single incident gets priority, yet they appear in incident reports again and again and they make teams afraid to deploy often. Interviewers ask this at senior level because the fix is not one property but a set of standards across application, platform and clients. In this answer, we will see why these problems keep coming back, set the standard for each layer, decide how to measure it, and see how to make it stick across many teams.
1Why Deploy Problems Keep Coming Back
A deploy stops old instances while traffic continues. To be invisible, three parties must cooperate in the right order: the load balancer must stop sending new traffic, the application must finish the requests it already has, and only then may the process be stopped. Connection draining is the name for that middle part, letting existing connections finish while no new ones arrive.
When every team configures its own part, the order breaks in different ways. One service forgets graceful shutdown, another has a Spring timeout longer than the Kubernetes grace period and gets killed mid-request, a third has no preStop delay so traffic arrives after it stopped accepting. Each mistake is easy to make and hard to see in a quick test with no load. That is why the problems repeat: the knowledge lives in a few people, not in the platform.
2The Application Standard
Every service must support graceful shutdown with settings we have tested. In practice the platform starter sets them, so teams get them by doing nothing.
Notice that background work is part of the standard too. A Kafka consumer or an async task killed mid-way can be as visible to users as a failed HTTP request, so each kind of work needs its own stop behaviour within the same time budget. Services that need a longer timeout, such as a report endpoint that takes 50 seconds, can raise it, but the platform then raises their grace period to match.
3The Platform Standard: Coordinating the Timing
The hardest part to get right is the timing between the load balancer and the pod, so the platform should own it rather than each team. The deployment template sets a preStop delay long enough for our slowest router to remove the pod, measured on our own clusters, and computes terminationGracePeriodSeconds from the preStop delay plus the service's shutdown timeout plus a margin. For services behind a cloud load balancer, the template also aligns the target group's deregistration delay with the same budget.
7 messages in order. Play them, or step through them one at a time.
The order matters: stop new traffic, drain, then stop the process.
4The Client Standard: Retry What Is Safe
Even with perfect timing, a few failures remain: a keep-alive connection closed by the server just as the client reuses it, or a node lost during the deploy. So the shared HTTP client configuration retries idempotent requests, such as GET, PUT and DELETE, once or twice on connection errors, with a short backoff and jitter. Requests that create things, such as POST, are retried only when they carry an idempotency key that the server uses to recognise a repeat.
The retry policy must be shared and bounded. If every layer retries three times, one failure becomes 27 calls under load, so the standard says retries happen at one layer, usually the caller closest to the failed service.
5Measuring Deploys as a Quality Metric
A standard without a number decays. I would define deploy error rate as the 5xx responses and client connection errors for a service during its deploy window, compared with the same length of time before the deploy. The platform records the deploy window automatically and the dashboard shows the extra errors per deploy. A target such as zero extra errors in 95 percent of deploys turns invisible deploys from a hope into something we can track.
Then we practise. Once a month, and for every change to the platform template, we run deploys under realistic load in staging: steady traffic from a load generator, a rolling deploy in the middle, and the error count checked automatically. When a deploy produces errors, we fix the template once and every service benefits.
| Layer | Standard | Checked by |
|---|---|---|
| Application | Graceful shutdown with tested settings | Platform starter, startup check |
| Platform | preStop delay, grace period, LB deregistration | Deployment template |
| Clients | Bounded retries for idempotent requests | Shared client library |
| Measurement | Extra errors per deploy as a metric | Deploy dashboard |
| Practice | Deploys under load in staging | Monthly and on template change |
6Follow-up questions
How do you get many teams to adopt the standard?
Make the standard the default, not a document. If the platform starter and the deployment template carry the settings, a service gets them by upgrading. Then the dashboard shows which services still have deploy errors, and we help those teams directly rather than sending reminders.
What about long-running requests or WebSocket connections?
They cannot drain within a normal budget, so they need their own design: clients that reconnect cleanly, servers that tell clients to reconnect before shutting down, and a longer grace period for those specific services. The standard names them as an exception with its own settings.
Why measure deploy errors separately from overall error rate?
Because they are small in total and hide in the daily average. A service with 20 errors per deploy and 10 deploys a day looks healthy overall, yet users hit 200 avoidable errors daily. Measuring the deploy window makes the problem visible and proves when it is fixed.
7Conclusion
In this answer, we saw that deploy errors repeat because the timing between load balancer, application and process stop is easy to get wrong and is often left to each team. The long-term standard is graceful shutdown with tested settings in every service, platform-owned coordination of load balancer removal, preStop delays and grace periods, bounded client retries for idempotent requests, deploy error rate as a tracked metric, and regular deploy practice under load in staging.
Open with
I would treat invisible deploys as a platform property rather than something each team gets right on its own, because the failures come from timing between layers. First, every service supports graceful shutdown with settings we have tested, delivered by the platform starter, including background work such as executors and listeners, all fitting one time budget.
Then, if they want more
Second, the platform coordinates the order: deregister from the load balancer, keep the pod serving during a preStop delay we measured on our own clusters, then send SIGTERM, and set terminationGracePeriodSeconds from the preStop plus the shutdown timeout plus a margin. The deployment template computes that, so no team has to.
Third, clients retry idempotent requests on connection errors, with bounded retries at one layer, and POSTs only with an idempotency key. Fourth, we measure the extra errors during each deploy window as a quality metric, with a target such as zero extra errors for 95 percent of deploys, and show it per service.
Finally, we practise deploys under load in staging every month and whenever the template changes, so the standards are proven, not assumed. When something fails, we fix the template once and every service benefits.
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 "Graceful shutdown and connection draining problems appear in many incidents during...": https://scrivio-interview-library.netlify.app/spring-boot/embedded-servers/1b8ffd1514/