Menu

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.

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

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.