How to update your AppFog app with ZERO downtime
As those of you who have deployed apps on AppFog may know, when you’re updating an app (most likely using a simple af update <app-name> command with the AppFog Ruby gem), you tend to confront downtime during the deployment process. The AppFog update process involves stopping your app, then re-staging and re-starting. Obviously, for some of you that downtime is problematic.
Here’s how we suggest deploying apps without any downtime, and with the added benefit of being able to roll back quickly if there are problems.
Let’s say your app, called AppFogFTW, is running on AppFog at appfogftw.com (that’s a mouthful!).
1. Deploy identical versions of the app: appfogftw at appfogftw.com and appfogftw2 at appfogftw2.com. Here’s what the two apps will look like in the CLI if you run the af list command, which lists all of your currently deployed apps.
| appfogftw | 1 | RUNNING | appfogftw.com, www.appfogftw.com | appfogftw2 | 1 | RUNNING | dev.appfogftw.com
2. Develop your app at appfogftw2, deploying new code until you are ready to make a push to appfogftw.com. That way it can potentially have 404 errors while updating but your users won’t see them. Run a normal update:
af update appfogftw2
3. When you are ready to push to production, first map appfogftw2 to appfogftw.com and www.appfogftw.com, and then map appfogftw to dev.appfogftw.com:
af map appfogftw2 appfogftw.com af map appfogftw2 www.appfogftw.com
4. Now, you have two applications running at the same URL (appfogftw and appfogftw2) and they are load balanced. You can use this time to test appfogftw2 in production if you like.
| appfogftw | 1 | RUNNING | appfogftw.com, www.appfogftw.com | appfogftw2 | 1 | RUNNING | dev.appfogftw.com, appfogftw.com, www.appfogftw.com
5. Finally map appfogftw to dev.appfogftw.com and unmap appfogftw from appfogftw.com and www.appfogftw.com:
af map appfogftw dev.appfogftw.com af unmap appfogftw2 dev.appfogftw.com af unmap appfogftw appfogftw.com af unmap appfogftw www.appfogftw.com
6. If there are any troubles with appfogftw2, rollback is trivial. You just map appfogftw back to appfogftw.com. Users will never see any downtime and you can rollback easily.
| appfogftw | 1 | RUNNING | dev.appfogftw.com | appfogftw2 | 1 | RUNNING | appfogftw.com, www.appfogftw.com
7. Now you can develop against appfogftw (instead of appfogftw2) and when you are ready to deploy to production, you can reproduce the same steps as above.
af update appfogftw
And that’s it!
If you have devised other ways of implement zero-downtime updates, please share any tips here in the comments. Happy updating!
-
http://twitter.com/halilweb Halil Özgür
-
M G
-
esseti
-
Jasdeep Khalsa
