Peek Under the Hood of Heroku
After completing this unit, you'll be able to:
- Explain what a dyno is.
- Distinguish between languages, buildpacks, and slugs.
- Describe how add-ons are useful, and name one that you can provision from the Heroku Elements Marketplace.
- Identify a Heroku CLI command.
Heroku Under the Hood
So far we've discussed Heroku at a high level: what it is and when you'd want to use it. And we've walked you through deploying your first Heroku app. But what exactly is Heroku? What's under the hood? Let's take a look!
At its core, Heroku is a set of tools to make deploying and running custom apps as simple as it can be. To understand these tools, we need to go a bit deeper into the weeds. This unit helps you understand the pieces that make up Heroku.
Your application's code runs on the Heroku Platform inside of structures that we call dynos. Dynos are not dinosaur-related, although that would really give new meaning to the term runaway process! Heroku's dynos are just managed runtime containers with a Linux operating system underneath. These containers run the processes that allow your custom application code to run.
Don't be intimidated by the terminology! Containerization is just a mechanism for keeping running processes isolated from one another. Think of it like this: Containers keep the strawberry jam from mingling with the mustard in your refrigerator so that your breakfast toast always tastes right. Runtime containers are the same thing, except they keep your code and configuration from touching any others. That way your app always tastes just how it should.
Containers also provide separation between two or more dynos running identical instances of your app, accepting client requests, and serving up responses. Even though one request might be served by Dyno A and another by Dyno B, your users won't know the difference. All they see is your application giving them quick responses. When you scale up your app to run on several dynos (or even dozens or hundreds), you've got extra peace of mind. If something goes wrong with your app code on one dyno, all the others can continue serving your customers.
Slugs & Buildpacks
Slugs are compressed and pre-packaged copies of your application optimized for distribution to the dyno manager. When you push code to Heroku, your code is received by the slug compiler which transforms it into a slug. At the heart of the slug compiler is a collection of scripts called a buildpack that handle different languages. All applications written in Ruby, Python, Java, Clojure, Node.js, Scala, Go and PHP are implemented and compiled using buildpacks. Scaling an application then downloads and expands the slug to a dyno for execution.
Custom buildpacks can be used to support languages or frameworks that are not covered by Heroku’s officially supported buildpacks.
Application Traffic Control: The Heroku Router
The Heroku router is the key to all this multi-dyno magic. Whenever a new web dyno starts up, it registers itself with the router, letting it know which application the dyno is running. After a dyno is registered, the Heroku router begins distributing incoming requests across all the available dynos for an application, the app's "dyno formation" — that's what we call the size and number of dynos running your app (for example, a formation of seven Performance-L dynos).
Do you find the Heroku router as fascinating as we do? To read more about how it works and what you can expect from it, check out the Heroku Dev Center documentation on routing.
Add-ons are another essential piece of the Heroku platform. These elements give you the ability to add complex functionality to your application without having to manage the underlying software or infrastructure.
A great example of a useful add-on is the Heroku Postgres database. Postgres is an enterprise-class database that's fast, reliable, and has a ton of capabilities. Best of all, when you provision a Postgres database as an add-on, the underlying infrastructure is completely managed by Heroku.
In addition to several Heroku-managed add-ons, third parties offer dozens of add-ons — data stores, email servers, monitoring tools, and just about anything else you can imagine. Developers can plug in back-end functionality, like the ability to send email or texts, with as little as one click. Many have free options that you can try and use as long as you like.
Check out the Add-ons page of the Heroku Elements Marketplace to explore all the add-ons you can incorporate into your Heroku Enterprise apps.