What is Zero Downtime deployment?
Zero Downtime deployment is a deployment strategy which enables the user to access the application/website continuously while deployment or some maintenance is going on.
e.g. most of us use gmail.com or yahoo.com but never see any downtime alert from these companies for service unavailability because these companies has already Zero Downtime deployment in place.
When does Zero Downtime deployment required?
Zero Downtime deployment is required whenever the application is deployed more than one server/node/cluster and application high availability is required .
How to implement Zero Downtime deployment?
Whenever application deployed on more than one server/node/cluster then there is also a Load Balancer required to balance the traffic on each server. This load balancer will helps us to implement this Zero Downtime deployment. How?
STRATEGY 1:
Lets start to implement by below steps:
1. Need to have one servlet/ rest controller/ any component which could pinged from load balancer every 3 seconds or else.
2. Step(1) component always return a HTTP status 200 to Load balancer which states the application is working fine and enable the load balancer to send the traffic to that particular server.
3. Step(1) component looks for a particular location either file or folder to stop new traffic on current server.
5. Once the component found the expected file or folder then return HTTP status 503 to load balancer.
6. Load balancer decides to send the traffic if server sends HTTP status 200 otherwise load balancer stops the traffic to that particular server.
7.Once the Load balancer stops the traffic to that server then wait for 10-15 mins to complete the ongoing transactions.
8.Now this one server is free from traffic and ready to do deployment.
9. Deploy the new version of application and verify the application.
10. Once verification is done then change the file or folder then the component starts sending HTTP status 200 to load balancer to receive the traffic.
11. Now repeat the same process for each server.
12. User won’t impacted during this zero downtime deployment strategy
STRATEGY 2:
1. All application has application context root as ‘/’ or ‘/somename’.
2.In this strategy, zero downtime deployment by this context root .
3. Suppose, there is one application deployed on two server with context root ‘/payment’
4.Load balancer is responsible to send the traffic to all servers.
5.Context root ‘/payment’ is active on every server.
6.To implement zero downtime, new version will be deployed on the same server but with different context root like “/payment/newversion”.
7. New version can be verified with new context root “/payment/newversion”
Current Application Context Root= “/payment”
New Version Application Context Root= “/payment/newversion”
8. Once the verification completed then change the context root between Current and new version of application
Current Application Context Root= “/payment/old”
New Version Application Context Root= “/payment”
9. Now, all traffic will come to new version
10. In this approach, there is small risk to lose application level data singleton synchronization.
You can find sample implementation to start and stop the traffic to load balancer using health servlet.
git source here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
final String maintenanceFilePath = "/opt/maintenance/"; try { if (maintenanceFilePath != null) { File file = new File(maintenanceFilePath); if (!file.isDirectory() && file.exists()) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); response.getWriter().append(DISABLED_STRING); LOGGER.warn("Application Server Node is in {} mode", DISABLED_STRING); return true; } } } catch (Exception e) { LOGGER.error("Error in isMaintenanceOn {}", e); } |
Conclusion:
This is very important part of application high availability implementation. I hope that this blog will help you to implement your own zero downtime deployment strategy.
good
Nice stuff
Remarkable! Its actually awesome piece of writing, I have got much clear idea concerning from this piece of writing.
carolineol