Master Graceful Shutdown and Deployment Strategies with Spring Cloud
This article explains how to perform graceful service shutdowns and various deployment techniques—including /shutdown, /pause, and /service‑registry endpoints, EurekaAutoServiceRegistration, blue‑green, rolling, and canary deployments—using Spring Cloud to ensure zero‑downtime upgrades and smooth traffic migration.
Introduction
In production, upgrading services without affecting user experience is critical. Graceful shutdown aims to take a service out of rotation without interrupting users.
Common Shutdown Methods
Method 1: kill PID
Uses the operating system to terminate the Java process. This is a brute‑force approach and not graceful.
Method 2: /shutdown endpoint
Spring Boot provides an /shutdown actuator endpoint. Enable it in application.yml:
management:
endpoint:
shutdown:
enabled: true
endpoints:
web:
exposure:
include: shutdownSend a POST request to /actuator/shutdown to stop the application.
Method 3: /pause endpoint
Spring Boot can expose a /pause endpoint (requires the restart endpoint). Configuration:
management:
endpoint:
# enable pause endpoint
pause:
enabled: true
# restart endpoint is required
restart:
enabled: true
endpoints:
web:
exposure:
include: pause,restartPOST to /actuator/pause marks the instance as DOWN in Eureka while the process continues to run.
Method 4: /service-registry endpoint
Expose the /service-registry actuator endpoint to deregister the instance from Eureka:
management:
endpoints:
web:
exposure:
include: service-registryPOST to /actuator/service-registry?status=DOWN removes the instance from the registry.
Using EurekaAutoServiceRegistration
Programmatically control registration:
@RestController
@RequestMapping("/graceful/registry-service")
public class GracefulOffline {
@Autowired
private EurekaAutoServiceRegistration eurekaAutoServiceRegistration;
@RequestMapping("/online")
public String online() {
this.eurekaAutoServiceRegistration.start();
return "execute online method, online success.";
}
@RequestMapping("/offline")
public String offline() {
this.eurekaAutoServiceRegistration.stop();
return "execute offline method, offline success.";
}
}Deployment Strategies
Blue‑Green Deployment
Run two identical environments, route traffic to one, switch to the other for upgrades, then retire the old one.
Rolling Update
Update a subset of instances gradually, keeping a single cluster alive while replacing nodes.
Canary Deployment
Deploy a new version to a small percentage of users, monitor, then gradually increase traffic if healthy.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
