The 12 Factors of Go
The 12 Factor App methodology is a set of best practices to follow when building modern software applications. It was created by Heroku as a guide for developers to optimize application development for their platform as a service. At the core, the 12FA methodology is a marketing document, but the concepts behind individual practices outline best practices that can be followed regardless of the platform where you publish your apps.
What is it about?
The 12 Factor Apps should follow the following principles:
I. Codebase - One codebase tracked in revision control, many deploys
II. Dependencies - Explicitly declare and isolate dependencies
III. Config - Store config in the environment
IV. Backing services - Treat backing services as attached resources
V. Build, release, run - Strictly separate build and run stages
VI. Processes - Execute the app as one or more stateless processes
VII. Port binding - Export services via port binding
VIII. Concurrency - Scale out via the process model
IX. Disposability - Maximize robustness with fast startup and graceful shutdown
X. Dev/prod parity - Keep development, staging, and production as similar as possible
XI. Logs - Treat logs as event streams
XII. Admin processes - Run admin/management tasks as one-off processes
As you can see, the requirements for 12 Factor Apps go beyond just writing code. They specify how source code is shared and stored, how configuration is managed, how you should lay out your development and production environments, and how to structure your application to enable scaling capabilities and insight into how your application is running.
There are several programming languages which can be used to develop 12 Factor Apps. My personal favorite is Go, because it has very strong concurrency support, enabling vertical scaling beyond just one CPU core out of the box. With Node you would need to resort to a process manager like Docker or PM2 in order to take advantage of all your CPUs from the start. While this is in line with the 8th rule of 12FA, I find that less moving parts ultimately result in less problems.
Docker is the ideal tool to satisfy many of these requirements, regardless of what programming language you would use for your APP. With the inclusion of swarm, Docker has become a solid process manager which can serve as a functional replacement of PaaS architecture like Heroku. As such it provides the mechanisms that reduce the complexity of the applications which are managed with it.
Writing software for almost two decades, I nursed several applications from one server by scaling them to two, and progressively up to 60 high powered virtual machines as traffic grew. But, having the power of the cloud behind you, top-tier companies like Shopify run hundreds of such processes without breaking a sweat.
Netflix at one point had an idle pool of 12 thousand spot instances daily. Can you imagine the steps you have to take to get to that scale? Let me give you a hint: The 12 Factor App is a good start.
I want to write a book going trough the development of a 12 Factor App and the tooling work that goes with it. I would like to go thru all the individual steps and break down why they are important, while at the same time building a real-world Go application that completely follows the 12 Factor App rules. If you’re interested in this, leave your e-mail below to subscribe to updates. A good thing which you can do is leave your thoughts on this Reddit thread.
Note: I have published 12 Factor Applications with Docker and Go on Leanpub. The book is under active development and available for purchase. Thanks for your support!
While I have you here...
It would be great if you buy one of my books:
- Go with Databases
- Advent of Go Microservices
- API Foundations in Go
- 12 Factor Apps with Docker and Go
Want to stay up to date with new posts?