Skip to content

Instantly share code, notes, and snippets.

@crcastle
Last active Jan 10, 2018
Embed
What would you like to do?
Heroku: Scale from 0 to 100 servers in 5 minutes
# Prep
# Do this in a team, not personal app, because we don't want to use Free/Hobby
export HEROKU_ORGANIZATION=demo-org
####### Start Demo Here
# I'm going to deploy a simple app to Heroku
# Add a new "feature"
# Scale it up to 100 servers (cause our company got mentioned on Techcrunch!)
# Then scale it down to 20 (to save $$$ since the load has gone down)
# And I'm going to do all this in less than 5 minutes (might need to be 7 or 10 min)
# (depending on audience) Try to do that in your IaaS environment
# OK, let's get started
# I'm going to create an a folder for our app
mkdir myapp
cd myapp
# Then I'm gonna make a simple PHP app, but
# Heroku supports all the major languages: Ruby, Node, Java, Python, Go, etc
echo "Hello world" > index.php
# Let's add that file to source control
# Cause source control is a foundational tool for all dev teams
git init
git add .
git commit -m 'First commit'
# Now let's use the Heroku command line tool
# I'm going to create an empty Heroku app
heroku create
# And push my code to it
git push heroku master
# And that's it. Our app is live on the internet!
heroku open
# OK, now our CEO has asked for an improvement
# She wants bigger and more impactful
# So I'm going to add a little fun to it
# (Use vi or whatever editor is quickest for you to edit index.php)
# (I change it to <marquee><h2>Hello world!</h2></marquee> for the lolz)
git add .
git commit -m 'Add more impact'
git push heroku master
heroku open
# There we go!
# Now we need to scale up because we got mentioned in Techcrunch!
# And quickly!
# But this is a live demo so let me show that this is real
# (split terminal or open new terminal in same directory)
heroku logs -t
# Watching our logs, you'll see 99 new dynos get spun up in a few seconds
# (back in original terminal)
heroku ps:scale web=100
# Optional: Refresh web browser to show requests going to different dynos
# OK, now let's scale down since the load has subsided some
# Because we don't want to waste money on unused capacity
heroku ps:scale web=25
####### End Demo
# Don't forget to delete your app.
heroku apps:destroy --app ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment