nabarun pal
Infrastructure@Clarisights
Python and Go loving polyglot
Wears multiple hats in Kubernetes community
@theonlynabarun
Slide 4
Slide 4 text
twelve factor application
Slide 5
Slide 5 text
1. Declarative formats to setup automation
2. Clean contract and maximum portability
3. Suitable for deployment on modern cloud platforms
4. Minimizing divergence across deployments
5. Agile scaling without much changes to underlying infrastructure
Goals
Slide 6
Slide 6 text
codebase
One codebase tracked in revision control, many deploys
Slide 7
Slide 7 text
➔ Code should always be version controlled
➔ All deploys of the app should have the
same code
➔ Different versions of the code may exist
Slide 8
Slide 8 text
dependencies
Explicitly declare and isolate dependencies
Slide 9
Slide 9 text
➔ Declare dependencies in requirements.txt or
Pipfile depending on your choice of tooling
➔ Achieve isolation using virtualenv or Pipenv
Slide 10
Slide 10 text
config
Store config in the environment
Slide 11
Slide 11 text
➔ Code should always be version control
➔ All deploys of the app should have the
same code
Slide 12
Slide 12 text
backing services
Treat backend services as attached resources
Slide 13
Slide 13 text
➔ The application should not care about
where external resources like databases,
cache are running
➔ The application should just care about
the correct configuration provided to it
Slide 14
Slide 14 text
build, release, run
Strictly separate build and run stages
Slide 15
Slide 15 text
➔ Isolation of build, release and run stages
➔ Releases should be unique and
immutable
Slide 16
Slide 16 text
processes
Execute the app as one or more stateless processes
Slide 17
Slide 17 text
➔ Processes should not share state
amongst themselves
➔ They should be completely stateless
➔ Any required state needs to be in backing
databases
Slide 18
Slide 18 text
port binding
Export services via port binding
Slide 19
Slide 19 text
➔ Publish app as service through ports
➔ Self contained and doesn’t need runtime
injection of web servers
➔ One application can act as a backing
service for another app through URIs
Slide 20
Slide 20 text
concurrency
Scale out via the process model
Slide 21
Slide 21 text
➔ Processes are first class citizens
➔ Workloads should be able scale across
machines
➔ NEVER try to do process management
yourself - DELEGATE
Source: https://12factor.net/concurrency
Slide 22
Slide 22 text
disposability
Maximize robustness with fast startup and graceful shutdown
Slide 23
Slide 23 text
➔ Processes should be destroyable at will
➔ Minimal startup time
➔ Graceful shutdown on termination signal
➔ Functionality should be idempotent
Slide 24
Slide 24 text
dev/prod parity
Keep development, staging, and production as similar as possible
Slide 25
Slide 25 text
➔ Try to bridge gaps in workflow
➔ Development environment and
deployments should be as similar as
possible
➔ Use same services in all environments
Slide 26
Slide 26 text
logs
Treat logs as event streams
Slide 27
Slide 27 text
➔ Logs are are chronological event streams
➔ Must be written unbuffered to stdout
➔ Log shippers are responsible to collect
➔ Ship to warehouses like Elasticsearch
for slicing and dicing
Slide 28
Slide 28 text
admin processes
Run admin/management tasks as one-off processes
Slide 29
Slide 29 text
$ createdb todo
$ psql todo < schema/schema.sql
---
$ python manage.py migrate
➔ Ad-hoc tasks like database migrations
should be run as a separate job
➔ The runtime environment should be same
as the main process