Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push to Heroku without putting the app down

Just wondering how everyone pushes updates to their production server on Heroku, without bringing the app down for a few couple of seconds?

Pushing to Heroku (especially using something like Unicorn), takes a while for the web app to load. Especially when there are end-users trying to access the site. They end up with 503 pages.It takes up to 30 secs to a minute for Unicorn processes to load.

like image 833
Christian Fazzini Avatar asked Apr 19 '12 23:04

Christian Fazzini


2 Answers

There are TWO things you need to accomplish this, and it's not trivial.

1) Migrations need to be backwards compatible (i.e., run while the app is live). See this article about that: http://pedro.herokuapp.com/past/2011/7/13/rails_migrations_with_no_downtime/

2) Deploy using TWO heroku apps. I opened a ticket with Heroku on this topic and this was their reply:

We're currently working on a solution to provide a zero-downtime deploy but do not have an ETA on when this might be available.

In the meantime a workaround that might be possible would be to deploy to two separate apps. You can push new code to the second app, spin it up, then move the domain names over to the second app. Wash and repeat on the next deploy. This is less than ideal but might get you the desired result in the interim.

If you do this, you will want to automate as much as possible since there's a lot of ways to mess that up. Here's an article on that topic: http://casperfabricius.com/site/2009/09/20/manage-and-rollback-heroku-deployments-capistrano-style/

Why?

These two solutions must both be done because the database migrations must work in BOTH (live and to-be-live) versions of the code. Once you have that working, THEN you can solve the second problem of having the application itself not seem like it went down. There is no supported way to spin up and spin down individual dynos once a push is started.

UPDATE: There is a beta feature available with Heroku now. To use do the following prior to pushing:

heroku labs:enable -a APP_NAME preboot

This will change the behavior of the app during pushes. It will push up a parallel instance that will warm up for two minutes. Almost exactly two minutes after the push, all traffic will route to the new app. Be careful with migrations, as I mentioned above, as they are still an issue.

like image 200
Michi Kono Avatar answered Oct 12 '22 04:10

Michi Kono


Heroku is currently testing their new preboot feature in beta. You might wanna check it out. Unfortunately it only works for ≥2 web dynos. And it also doesn't seem to work for heroku scale web=… which would be important to make it work with HireFireApp.com.

like image 24
Ortwin Gentz Avatar answered Oct 12 '22 04:10

Ortwin Gentz