Setting the stage: AWS EC2#
The easiest – and perhaps most important – way to understand Heroku is to first understand what it looks like to deploy an app using the run of the mill infrastructure as a service offerings like EC2. EC2 stands for elastic compute cloud, all made up words, frankly.
Once you’ve created your AWS account you’ll have the option of either logging in as a Root user or an IAM user. It’s better security practice to login as an IAM user with the right permissions, but having the unrestricted access the Root user provides makes it a lot easier to login with that user, which is what we’ll do.
Launch an EC2 instance#
Once you navigate to the EC2 console dashboard you can click the Launch Instance button to get started. You’ll notice that in gray it says that you’ll be launching in N. Virginia. If you are in a different part of the US states or country you’ll want to change the location in the top right and launch your instance there.
Select a Machine Image#
You’ll want to choose an Amazon Machine Image (AMI), which is a special Amazon type of virtual appliance that is used to create a virtual machine in EC2 for you. The AMI will have the operating system you want to use, the AWS accounts that can access it and the storage device.
Choose an Instance Type#
Now depending on the CPU, memory, storage and network performance you’ll need for your application you can pick an instance type that fits.
Still with me?
Here you’ll want to make sure you have the correct network, role, and other settings configured correctly before you move on to adding storage.
Add Storage#
You’ll want to choose a storage size that meets the needs of your application. For example, you’ll want more storage space if your application requires image file storage compared to an application that doesn’t need to store any data.
Security Groups#
If you want to SSH into the machine you can choose SSH from the Type dropdown in this step. However, for a production application you’ll want to open up ports 80 to handle HTTP, port 443 for HTTPS and if you happen to have an admin dashboard you might open a Custom TCP port like 8080.
SSH into your machine#
You’ll want to run chmod 600 ./Ec2keypair.pem to restrict the read and write permissions for the file and then set up the SSH environment with ssh-add ./Ec2keypair.pem before you can SSH into the machine.
All of this to get a basic server running in the cloud. Simpler than buying and running hardware yourself? Yes. But not very simple at all.
The basic Heroku product and how it works#
So there’s a lot of work required to get up and running with EC2, even though it is way better than the old days (buying servers from scratch). And Heroku itself is actually built on top of EC2! But the name of the game here is simplicity, and that’s what Heroku sells to developers.
I started using Heroku when they still had Heroku Garden – this was the first version of the product – and were only focused on the Ruby programming language. The main value prop, outside of the infrastructure, was a web based code editor. Not everyone had Ruby on their machines or couldn’t install it so easily in those days. So having a development environment in the cloud sounded awesome. I was excited and sad when they sunset Heroku Garden back in 2009.
If there is one thing, you should remember as to why developers think Heroku is so magical, it’s:
git push heroku main
With this single command (after a bit of configuration, admittedly), you can completely redeploy your application with brand new code from a GitHub repository. To do that with EC2, you’d need to first make sure to add a key pair so you can SSH into the EC2 instance. Once you’ve SSH into the instance, you’ll go through the process of installing the required packages to get your application up and running. Before that you’ll want to install Git so you can clone your repository from your GitHub account.
The CLI experience provided by the Heroku gem is truly remarkable. To create an application:
sudo gem install heroku
heroku create myapp
That’s it. To deploy said application:
git push heroku main
You also have various commands to work with your application:
// Add a domain
heroku domains: add danishkhan.org
// View real time logs from your application so you can debug
heroku logs
// Execute shell commands on the remote machine for more in depth stuff
heroku run
// View the status of remote processes running (like an installation)
heroku ps
So many valuable commands easily accessible through the terminal allows developers to understand what is happening with their application while offloading the server maintenance and upgrades to Heroku. So when you break down what you’re really getting when you pay for Heroku, in addition to just infrastructure (that’s cheap), it’s this very nice, thoughtfully designed developer experience that saves time and headache.
Buildpacks and addons, plus pricing#
Outside of the core Heroku experience, it’s worth noting a few pieces of the ecosystem they’ve worked on.
The first is Buildpacks – they continue improving the developer experience by helping automate the build process for any language or framework, allowing developers to no longer worry about how to package their applications for deployment.
You might be thinking that this sounds like Docker, and you’re right. But using Heroku or community supported Buildpacks means you don’t have to learn Docker and maintain the tool used to install the libraries and packages that are used to build their application. Whenever old tools are replaced with new ones those will be updated in the Buildpacks by Heroku or the community. Developers can be confident if they are spinning up a testing or development environment that their application will run and they can get straight to their work.
The second is the Heroku add-on marketplace. With add-ons, it just takes one click to add various services – like a database – allowing a developer not to worry about manually configuring them. By clicking the button on the right of the screenshot below you can easily install a PostgreSQL database. When you need to scale you can either do that vertically by picking a larger plan or horizontally by adding read-only followers.
Making something feel like magic doesn’t come cheap. Dynos, which are isolated virtualized Linux containers, are the building blocks that power a Heroku app. If you get a Product Hunt driven bump in traffic, you can run heroku ps:scale web=8 to scale your web Dynos to 8 (extremely easily), but this of course comes at a cost.
The equivalently sized and powered EC2 instance relative to a Heroku Dyno is way cheaper, which is to say that Dynos are very expensive for the infrastructure you’re getting:
Price comparisons across these products are imperfect at best, but you get the message.
For a startup, Heroku makes much sense because it allows them to focus on what will make them ramen profitable – in other words, they can stop worrying about infrastructure and focus on features. Once they’ve added more dynos to their application, they’ll start running the numbers to find that hiring a team of people to migrate and run their application on EC2 looks rather appealing. But before then – Heroku can be a powerful way to not deal with this shit.
When infrastructure costs grow alongside usage, developers start looking for other ways to improve the application and cut costs. Heroku achieves its magic by forcing developers to build their applications in a specific way, so once you want to try something different, you may have to migrate away to do it.
Further reading#
- 2010 Introduction to Heroku video by Heroku’s Co-founder, James.
- The decline of Heroku is an excellent article about what Heroku was and whether it can rise again.
- Adam, the Co-founder and CTO of Heroku, coined the term 12-factor app. This became how developers would build for the web and is still relevant today.