Graceful Shutdown
Why Graceful Shutdown Matters
Spring Boot graceful shutdown (server.shutdown=graceful) waits for in-flight requests to complete before stopping. In Kubernetes production deployments with rolling updates, graceful shutdown eliminates dropped requests during pod termination—completing active requests within timeout period (default 30s) while rejecting new requests for zero-downtime deployments.
Problem: Immediate shutdown drops in-flight requests during Kubernetes rolling updates.
Solution: server.shutdown=graceful with spring.lifecycle.timeout-per-shutdown-phase.
Implementation Example
// Implementation details for graceful-shutdown
// See full guide for comprehensive examplesProduction Configuration
server:
shutdown: graceful # => Wait for in-flight requests
spring:
lifecycle:
timeout-per-shutdown-phase: 30s # => Max wait timeProduction Patterns
Best Practices:
- Follow Spring Boot conventions
- Test in staging before production
- Monitor metrics and health checks
- Use environment-specific configuration
Trade-offs
| Aspect | Spring Boot Approach | Manual Approach |
|---|---|---|
| Complexity | Auto-configured (simple) | Manual configuration (complex) |
| Flexibility | Conventions with overrides | Full control |
| Maintenance | Framework-maintained | Custom code maintenance |
| Production ready | Defaults optimized | Requires tuning |
Production recommendation: Always enable graceful shutdown in Kubernetes. Essential for zero-downtime deployments.
Next Steps
- See related in-the-field guides for comprehensive production patterns
Last updated