How to Achieve Zero‑Downtime Application Deployments with Spring Boot and Eureka
This article explains why zero‑downtime releases are essential for modern services, defines three maturity levels, compares common release patterns, outlines the required technical components, and provides step‑by‑step Spring Boot/Eureka procedures—including configuration and graceful‑shutdown scripts—to keep applications available during deployment.
Why Zero‑Downtime Releases Matter
Traditional deployments follow a stop‑update‑start cycle, causing visible service interruptions (white‑screens, time‑outs). In always‑on, online‑first services even a few seconds of downtime can lead to user loss and hidden economic impact.
Maturity Levels for Non‑Stopping Deployments
Level 1: The entire release process does not interrupt service.
Level 2: Single‑function applications stay online; internal or low‑traffic validation is allowed before the final switch.
Level 3: Multi‑function (linked) applications stay online; internal or low‑traffic validation is also required.
Common Release Modes and Their Trade‑offs
Blue‑Green, Rolling, and Canary releases can provide user‑transparent deployments, but each has different resource and complexity requirements. Mature environments often prefer Canary; less‑ready setups may avoid the high resource cost of Blue‑Green.
Key Technical Components
Application Management Platform – orchestrates the release workflow.
Layer‑4 Load Balancer – distributes traffic based on network‑level attributes.
Layer‑7 Load Balancer – routes traffic to specific service instances.
Container/VM Platform – creates, updates, and destroys runtime instances.
DNS System – manages domain registration and resolution.
Service Registry (e.g., Eureka) – registers services and enables discovery.
Service Routing Basics
Two routing patterns are common:
North‑South: client → L4 LB → L7 LB → service (requires load‑balancer handling during a release).
East‑West: client → service directly (relies on the application framework for graceful handling).
Graceful Shutdown Strategies
During a release two failure scenarios can affect users:
In‑flight requests are killed (e.g., kill -9), causing errors.
The service stops without notifying callers, so traffic continues to a dead instance.
North‑South traffic can be protected by the load balancer:
Block new requests to the instance while allowing existing requests to finish.
Destroy the container or update the VM, then remove the block.
East‑West traffic requires the application itself to handle shutdown:
Implement a shutdown hook (e.g., Spring Boot actuator/shutdown) that waits for ongoing requests.
Notify downstream callers or mark the instance as DOWN in the service registry before termination.
Method 1 – Allow up to 5 seconds of interruption
management:
endpoint:
shutdown:
enabled: true
endpoints:
web:
exposure:
include: shutdownExpose the endpoint and invoke:
curl -X POST http://HOST/actuator/shutdownMethod 2 – No interruption, no notification
management:
endpoint:
shutdown:
enabled: true
service-registry:
enabled: true
endpoints:
web:
exposure:
include: shutdown,service-registryMark the instance as DOWN before termination:
curl -X POST http://HOST/actuator/service-registry?status=DOWNAfter a short wait (e.g., 5 seconds, matching Eureka’s fetch interval), shut down:
curl -X POST http://HOST/actuator/shutdownMethod 3 – No interruption, with notification
Same configuration as Method 2. Before shutting down, retrieve the list of clients from the registry, push a notification forcing them to refresh their service list, then shut down as above.
Development Guidelines for Zero‑Downtime Compatibility
APIs: Add new fields with defaults, extend field lengths, never change existing semantics, avoid deleting fields, deprecate only after all callers have migrated.
Databases: Add columns with defaults, extend column sizes, never alter existing meanings, avoid dropping columns, create new tables when needed, and migrate data before retiring old tables.
Messages: Preserve old formats; if incompatibility arises, introduce new topics and optionally add a forwarding layer.
Caches: Prefer backward‑compatible formats; otherwise add special handling logic.
Implementation Example for Spring Boot + Eureka
1. Add spring-boot-starter-actuator to the project.
management:
endpoint:
shutdown:
enabled: true
service-registry:
enabled: true
endpoints:
web:
exposure:
include: shutdown,service-registry2. Adjust Eureka client settings (e.g., eureka.client.registry-fetch-interval-seconds=5) to ensure the client refreshes its registry quickly after an instance is marked DOWN.
3. Before destroying a container or updating a VM, invoke the service‑registry endpoint to mark the instance as DOWN:
curl -X POST http://HOST/actuator/service-registry?status=DOWN4. Optionally wait the fetch interval (≈5 seconds) and then shut down the instance:
curl -X POST http://HOST/actuator/shutdownRouting Strategies for East‑West vs. North‑South
When using a service registry:
Providers register themselves in Eureka; consumers discover providers via Eureka or via a Layer‑7 load balancer that queries Eureka.
In a non‑microservice setup, providers can be manually registered on the load balancer and consumers call the LB directly.
Grouping can be used to separate environments (e.g., pre‑prod vs. prod) or traffic sources (e.g., Wi‑Fi vs. external). Routing policies can be configured on the load balancer to allow or block traffic between groups.
Load‑Balancer Deployment Considerations
In segmented network architectures firewalls often block direct pod‑to‑pod communication, making a proxy‑style load balancer essential. Two common deployment patterns are:
Separate Layer‑4 and Layer‑7 load balancers (layered deployment) to leverage the strengths of each.
Unified proxy that handles both traffic distribution and routing.
Summary
Zero‑downtime deployment is achieved by combining a suitable release mode (Canary, Rolling, etc.), a well‑designed service‑routing architecture (north‑south or east‑west), load‑balancer support for graceful instance draining, and strict backward‑compatible development practices for APIs, databases, messages, and caches. By following the outlined shutdown methods and compatibility guidelines, teams can keep services available throughout the deployment lifecycle without user‑visible interruptions.
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.
dbaplus Community
Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.
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.
