The Twelve-Factor App🧵

a methodology for building SAAS that:

🔹Use declarative formats for automation
🔹Have a clean contract with the OS
🔹Are suitable for deployment on modern platforms
🔹Minimize divergence between dev and prod
🔹Can scale up without significant changes
The Twelve Factors:

1⃣Codebase
2⃣Dependencies
3⃣Config
4⃣Backing services
5⃣Build, release, run
6⃣Processes
7⃣Port binding
8⃣Concurrency
9⃣Disposability
1⃣0⃣Dev/prod parity
1⃣1⃣Logs
1⃣2⃣Admin processes
1⃣ Codebase

A 12-factor app is always tracked in a version control system, such as Git.

One codebase, many deploys.

A copy of the revision tracking database is known as a code repository.

There is always a 1-to-1 correlation between the codebase-app
2⃣ Dependencies

Explicitly declare and isolate dependencies.

A 12-factor app never relies on the implicit existence of system-wide packages.

12-factor apps also do not rely on the implicit existence of any system tools (for example curl).
3⃣ Config

Store config in the environment.

An app’s config is everything that is likely to vary between deploys.

The twelve-factor app stores config in environment variables.
4⃣ Backing services

Treat backing services as attached resources

The code for a twelve-factor app makes no distinction between local and third party services.
5⃣ Build, release, run

Strictly separate build and run stages.

A codebase is transformed into a deploy.

Three STAGES:
- BUILD: converts a repo into an executable (build).
- RELEASE: combines the build it with the deploy’s config.
- RUN: runs the app in the exec environment.
6⃣ Processes

Execute the app as one or more stateless processes.

The app is executed in the execution environment as one or more processes.

Any data that needs to persist must be stored in a stateful backing service, typically a database.
7⃣ Port binding

Export services via port binding.

The twelve-factor app is completely self-contained.

The web app exports HTTP as a service by binding to a port, and listening to requests coming in on that port.
8⃣ Concurrency

Scale-out via the process model.

In the twelve-factor app, processes are a first-class citizen. Processes in the twelve-factor app take strong cues from the Unix process model for running service daemons.
9⃣ Disposability

Maximize robustness with fast startup and graceful shutdown.

The app’s processes are disposable, they can be started/stopped at a moment’s notice.

Processes should:
- strive to minimize startup time.
- shut down gracefully.
- be robust against sudden death.
1⃣0⃣ Dev/prod parity

Keep dev, staging, and production as similar as possible

The 12-factor app is designed for continuous deployment, keeping the gap between dev and prod small.

The 12-factor dev resists the urge to use different backing services between dev/prod
1⃣1⃣ Logs

Treat logs as event streams.

A 12-factor app never concerns itself with routing/storage of its output stream. No logfiles.

Each process writes its unbuffered event stream to stdout.

During dev stream in the terminal to observe the app’s behavior.
1⃣2⃣ Admin processes

Run admin/management tasks as one-off processes.

The process formation is the array of processes that are used to do the app’s regular business (such as handling web requests) as it runs.
Recap:

The Twelve Factors:

1⃣Codebase
2⃣Dependencies
3⃣Config
4⃣Backing services
5⃣Build, release, run
6⃣Processes
7⃣Port binding
8⃣Concurrency
9⃣Disposability
1⃣0⃣Dev/prod parity
1⃣1⃣Logs
1⃣2⃣Admin processes
You can follow @FrancescoCiull4.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: