Autoscale your Heroku app in 15 minutes

This blog covers two types of autoscaling for heroku apps/dynos that Neptune supports out of the box.

  1. Load-based autoscaling
    • Whenever load is high for an app, scale up heroku dynos
    • Whenever throughput is low for an app, scale down heroku dynos
  2. Time-based autoscaling
    • At 6pm everyday, scale down heroku dynos
    • At 8am everyday, scale up heroku dynos

What is Autoscaling?

Autoscaling helps you improve your app availability by allowing you to scale up or scale down dynos automatically in response to an event. It helps you ensure that you are running the desired number of dynos to handle the traffic. It can increase the number of dynos during traffic spikes and decrease the number of dynos during traffic downtime to reduce costs. Autoscaling is well suited both to applications that have stable demand patterns or that experience hourly, daily, or weekly variability in usage.

Load-based vs Time-based Autoscaling
Load-based autoscaling allows you to scale up or down dynos based on the load or throughput. For example, if the web throughtput is higher than a threshold (say average+10%), you might want to increase the number of dynos for your app.

Time-based autoscaling allows you to scale up or down dynos based on a schedule. For example, every day at 6pm, you can reduce the number of dynos by half. Similarly at 8am every day, you can bring up the number of dynos back to normal.

Why Autoscale Heroku?

Autoscaling provides two key benefits:

1. Better app availability (i.e. better customer experience)
You can follow the demand curve for your apps closely, reducing the need to manually provision dyno capacity in advance. For example, if the load/throughput for your app goes above a certain threshold, you can increase the #dynos. Similarly, you can set conditions to remove dynos when the load is low. Your developers will have peace of mind since you app is already designed for traffic spikes.

2. Save costs
Autoscaling avoids over provisioning issues and saves costs by running only the required number of dynos. For example, you might need less dynos during the night, where as you need more dynos during the day. By running only the desired number of dynos, you can save costs on your heroku monthly bills.

Autoscaling Setup

In this setup, we'll describe how to autoscale up your dynos based on load (or) on a given schedule. Once scale up is configured, you can follow similar steps for scaling down dynos.

Step 1: Determine and setup your autoscaling trigger

Do you want to autoscale based on load? or based on time? If you want to use load-based autoscaling, simply configure an alarm in your monitoring tool or logging tool. If you want to use time-based autoscaling, proceed to step2 directly.

Neptune supports different types of triggers including Librato, NewRelic, PaperTrial/LogEntries, AWS CloudWatch or even a custom webhook. It also supports cron trigger for time-based-autoscaling.

The below load-based autoscaling triggers are popular among our customers:
1. Whenever throughput rate exceeds some threshold (NewRelic Alarm)
2. Whenever aggregate dyno CPU utilization is > 80% (Librato Alert)
3. Whenever saved search is triggered (PaperTrial/LogEntries alert)
4. Whenever SideKiq queue size is too high (AWS CloudWatch Alarm)
5. Whenever a REST API POST is called for a webhook endpoint (Neptune Custom Webhook)

Step 2: select a Neptune autoscaling use case template
popular heroku use case templates

Step 3: configure your autoscaling action

Edit Runbook to make sure you've entered correct heroku APP_NAME. Also, make sure you modify the #dynos you want to autoscale by.

Heroku Autoscaling Runbook

Finally, give a rule name and click on "Create Rule". That's it!

Whether you are launching a gaming app or e-commerce app, you can now have the piece of mind that your app scales to customer traffic spikes automatically.

Sign up here to start autoscaling your Heroku app today! Please post any feedback below.

Here are some quick references:
1. Quick 2 min video on getting started guide for Heroku
2. Explore the Heroku Autoscaling Runbook templates:

comments powered by Disqus
Subscribe to get DevOps best practices delivered to you directly