Why this matters
- Kubernetes sends SIGTERM — apps must drain in-flight HTTP and stop accepting new work.
- Hard kills mid-checkout cause duplicate charges and angry customers.
- Actuator and Spring Boot 3 lifecycle hooks are the production answer interviewers want.
Graceful shutdown
L1 · Fresherserver.shutdown=graceful stops accepting new HTTP work and waits for in-flight requests to finish.
Kubernetes termination
L2 · IntermediateSet terminationGracePeriodSeconds longer than your longest request plus shutdown hooks.
SmartLifecycle
L3 · AdvancedBeans implement ordered startup/shutdown for Kafka consumers and batch schedulers.
SIGTERM handling
L4 · ExpertCoordinate with load balancers to drain connections before SIGKILL — readiness probe should fail first.
Hook
Kubernetes sends SIGTERM during a BookStore rollout. In-flight POST /api/orders must finish, message listeners should stop accepting new work, and the JVM exits before the pod kill timeout — graceful shutdown wires Spring’s lifecycle to platform signals.
Server and context shutdown
server:
shutdown: graceful
spring:
lifecycle:
timeout-per-shutdown-phase: 30s
Boot 3.5 stops accepting new HTTP connections, waits for active requests, then closes the application context in defined phases.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 6 sections
- SmartLifecycle beans
- RabbitMQ and Kafka listeners
- BookStore in action
- Runnable BookStore lab
- Failure modes in production
- PreStop hook
Test yourself
Answer these before moving on — recall is what makes it stick.