12-factor app

What is 12-factor app?

Twelve-factor app is a methodology for building distributed applications that run in the cloud and are delivered as a service. The approach was developed by Adam Wiggins, the co-founder of Heroku, a platform as a service, which is now part of Salesforce. Wiggin's goal was to synthesize best practices for deploying an app on Heroku and provide developers who are new to the cloud with a framework for discussing the challenges of cloud-native applications.

Although some factors might seem self-evident to developers today, interest in developing apps that adhere to common best practices continues to grow with the rise of microservices and applications that are composed of loosely coupled web services.

The 12 factors of the 12-factor app methodology.
These 12 factors are best practices for building and maintaining cloud-native apps.

The 12 factors

The methodology includes twelve factors developers should think about when building native cloud apps. The twelve factors are the following:

1. Codebase

Use one codebase even when building cross-platform apps. Address the needs of specific devices with version control.

2. Dependencies

Explicitly declare and isolate all dependencies.

3. Configuration

Don't store config as constants in code. Instead, design the app to read its config from the environment.

4. Backing services

Treat back-end services as attached resources to be accessed with a URL or other locator stored in config.

5. Build, release, run

Strictly separate build and run stages.

6. Processes

Execute the app as one or more stateless processes. Data that must be persistent should be stored in a stateful backing service.

7. Port binding

Use port binding to export services.

8. Concurrency

Scale out apps horizontally, not vertically.

9. Disposability

Use fast startups and graceful shutdowns to maximize resiliency.

10. Parity

Facilitate continuous deployment by ensuring that development, staging and production environments are as similar as possible.

11. Logs

Treat logs as event streams. Logs should not be concerned with routing or storing the app's output.

12. Admin processes

Run admin tasks as one-off processes from a machine in the production environment that's running the latest production code.

Benefits of the 12-factor app

The goal of the 12-factor framework is to help developers build apps that use an architecture that ensures speed, reliability, agility, and portability as well as ultimately results in a resilient and reliable application.

When a developer uses the 12-factor app DevOps methodology, applications will have certain characteristics in common that address a variety of scenarios as an app scales. For example, the methodology recommends that apps use declarative formats for setup automation to assist new developers that enter the project later.

Apps should also be written to have maximum portability between execution environments and scale easily without significant reworking. Twelve-factor apps can be written in any programming language and in combination with any back-end service, such as a database.

This was last updated in April 2024

Continue Reading About 12-factor app

Dig Deeper on Software design and development

Cloud Computing
App Architecture