Implementing Zero-Downtime Deployments for Spring Boot
Fast recall
Quick revision
Core answer
Whether you understand that zero-downtime deployment requires both infrastructure changes (rolling update strategy) and application changes (graceful shutdown, backward-compatible migrations).
Configuring a rolling update in Kubernetes but not configuring graceful shutdown in Spring Boot, so in-flight requests are dropped when a pod terminates.
Mention the combination of readiness probes, graceful shutdown, preStop hooks, and database backward compatibility as necessary and together sufficient conditions for true zero-downtime.
Interview-ready guide
Interview answer
Zero-downtime deployment requires four things working together: a rolling update strategy at the infrastructure level, graceful shutdown in the application, backward-compatible database changes, and correct health check configuration. Any one of these missing causes dropped requests.
Kubernetes rolling update
strategy.type: RollingUpdatewithmaxUnavailable: 0means Kubernetes never takes a pod out of rotation until a new pod is ready;maxSurge: 1allows one extra pod during the rollout — which means at leastdesiredpods are always serving traffic- The new pod must pass its readiness probe before Kubernetes stops routing to the old pod; configure
readinessProbe.httpGet.path: /actuator/health/readinesswith appropriateinitialDelaySecondsfor Spring Boot's startup time
Graceful shutdown in Spring Boot
- When Kubernetes sends SIGTERM to a pod, Spring Boot should wait for in-flight requests to complete before shutting down — configure
server.shutdown=gracefulandspring.lifecycle.timeout-per-shutdown-phase=30s - Without graceful shutdown, SIGTERM immediately kills the process, dropping any request that was being processed at that moment
Database migration compatibility
- During a rolling deployment, old and new versions run simultaneously — which means any database change must be backward-compatible with the old version; adding a NOT NULL column without a default breaks the old version
- Follow the expand-contract pattern: add the new column as nullable (old version ignores it); deploy the new version that writes to it; add the NOT NULL constraint after all pods are on the new version
Connection draining
- Configure the load balancer to drain connections from pods being terminated — Kubernetes sends SIGTERM to the pod and simultaneously removes it from the service endpoints; in-flight requests to the pod continue until they complete or the drain timeout expires
- Set
terminationGracePeriodSecondsto at least the load balancer's drain timeout (typically 30-60 seconds)
Implementing Zero-Downtime Deployments for Spring Boot
Direct Answer
Zero-downtime deployment requires: rolling update strategy, Spring Boot graceful shutdown, readiness probes, backward-compatible DB migrations, and a preStop hook to drain in-flight requests.
Common Mistakes & Pitfalls
Configuring a rolling update in Kubernetes but not configuring graceful shutdown in Spring Boot, so in-flight requests are dropped when a pod terminates.
Check your understanding
Answer these without looking back at the article.
- What is the expand-contract database migration pattern?
- How do you configure Kubernetes rolling update strategy for zero downtime?
- What is the difference between liveness and readiness probes in Kubernetes?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.