WHAT IS A
12 FACTOR APP?Arch9: Amsterdam, The
Netherlands
HELLO!
I am Dmytro Panin
Found of Java, Cloud, IoT
⦿
CLOUD IS
EVERYWHERE
⦿
“Cloud - access to a pool of
computing resources
(servers, storage, networks,
services etc) that can be
rapidly provisioned and
made available with minimal
overhead”
⦿
⦿
The 12 factors are
language and technology
agnostic
⦿
BENEFITS
OF THE 12
FACTORS
▸ Minimize time and cost for a
new developer joining the
project
▸ Maximum portability between
execution environments
▸ Scale up without significant
changes
⦿
12 factors
Set of principles that prepare your app for the best experience
in cloud
⦿
CODEBASE
One codebase tracked in revision control, many deploys
1
One codebase per
application
1
Submodules if exist
should be separated
by VCS
1
DEPENDENCIES
Explicitly declare and isolate dependencies
2
System-wide
12 factor app never
relies on system-
wide dependenciesDEPENDENCIE
S
Isolated
dependencies are
declared explicitly
2
CONFIG
Store config in the environment
3
12 FACTOR
CONFIG
Backing services
Resource handles
to the services
that are required
for the app
Example:
Database
Passwords
Credentials to
external services
Example:
Twitter
Per-deploy values
Values that differ
based on an
environment
Example:
Hostname
3
12 FACTOR
CONFIG
Backing services
Resource handles
to the services
that are required
for the app
Example:
Database
Passwords
Credentials to
external services
Example:
Twitter
Per-deploy values
Values that differ
based on an
environment
Example:
Hostname
3
12 FACTOR
CONFIG
Backing services
Resource handles
to the services
that are required
for the app
Example:
Database
Passwords
Credentials to
external services
Example:
Twitter
Per-deploy values
Values that differ
based on an
environment
Example:
Hostname
3
NOT 12
FACTOR
CONFIG
Configuration of a framework is not
12 factor app conf
Routes do not vary between deploys, thus, better stored in
code.
3
CONFIGURATION
FILES
3
Number of configuration
files that you have right
now for all of your
environments
Number of
environments may grow
over time as well as
number of configuration
files in your app’s
repository
CONFIG
The 12 factor app stores config in
environment variables3 ▸ OS-agnostic standard
▸ Little chance of committing into the repo
Having config separated helps to scale out easier
THE LITMUS
TEST
3
BACKING
SERVICES
Treat backing services as attached resources
4
RESOURCES
4
LOCAL OR
3rd PARTY
4 The code for a twelve-factor app
makes no distinction between local
and third-party services
BUILD, RELEASE, RUN
Strictly separate build and run stages
5
STAGES
5
BUILD RELEASE RUN
Strict separation between the stages
VERSIONING
Every release should always have a
unique release ID5 ▸ Timestamp
▸ Incrementing number
A release cannot be mutated once it is
created
PROCESSES
Execute the app as one or more stateless processes
6
STATELESS
6
Twelve-factor processes are stateless and share-nothing
Any data that needs to persist must be stored in a stateful
backing service
STICKY
SESSIONS
6
Sticky sessions are a violation of the twelve factors
PORT BINDING
Export services via port binding
7
SELF
CONTAINED
7
The 12 factor app is self-contained
▸ Do not require an application container
▸ Embeds a webserver library
The web app exports HTTP as a service by
binding to a port
SELF
CONTAINED
7
The 12 factor app is self-contained
▸ Do not require an application container
▸ Embeds a webserver library
The web app exports HTTP as a service by
binding to a port
SELF
CONTAINED
7
The 12 factor app is self-contained
▸ Do not require an application container
▸ Embeds a webserver library
The web app exports HTTP as a service by
binding to a port
CONCURRENCY
Scale out via the process model
8
VERTICAL
8
Scale up is not enough
HORIZONTAL
8
Scale out
PROCESS
MODEL
8 Microservices
DISPOSABILITY
Fast startup and graceful shutdown
9
DISPOSABILIT
Y
9
Maximize robustness
▸ Minimize startup time
▸ Shut down gracefully
RESILIENCE
9 Be robust against sudden death
DISPOSABILITY
9 Don’t be too attached to your servers
Servers are a commodity
DEV/PROD
PARITY
Keep dev, staging and prod as similar as possible
10
TOOLS
10
SQLite ≠ MySQL
TIME
10
Code is in production
a few hours after a
commit
PERSONNEL
10
Developers should
deploy their code
LOGS
Treat logs as event streams
11
LOGS
11
LOGS
11
12 factor app don’t route or storage its output stream
ADMIN
PROCESSES
Run admin/management tasks as one-off processes
12
▸ Codebase
▸ Dependencies
▸ Config
▸ Backing services
▸ Build, release, run
▸ Processes
▸ Port binding
▸ Concurrency
▸ Disposability
▸ Dev/prod parity
▸ Logs
▸ Admin processes
LET’S
RECAP
⦿
DETAILS
http://12factor.net
⦿
QUESTIONS?

12 factor app