The 12-Factor App

Intro & Practice

ThoughtWorks

Zhang Yuchen

Methodology

Suitable for deployment on modern cloud platforms

Clean contract with underlying OS, maximum portability

Automation setup with declarative formats

Continuous deployment for maximum agility

Scala up without significant changes

DevOps +

DevOps is the result of implementing lean principles to the whole IT value stream. IT value stream extends development into production, combining all ‘distant relatives’ that descended from the original Programmer.

 

- Gene Kim

frequent deployment

stable

easy to maintain

simple & flexible

easy to learn

no gap between dev and ops

knowledge and comm

Codebase & Config

git: notification-publisher

git: notification-publisher-deploy

prod

staging

...

env

MY_ITEMS_HOST: https://api.host-to-dest.com
API_VERSION: v2
SERVER_USE_FORWARD_HEADERS: true

One App, One Repo

Backing Services & Port Binding

Treat backing services as attached resources

Export services via port binding

mysql://host/db

smtp://auth@host

s3://host/bucket

http://host.com

No distinction between local and remote

Store in config

Easy to replace in development

Expose port as service

Service as resource

Processes

Twelve-factor processes are stateless and share-nothing

Cache for post process

Upload file to S3

Parallelism processing

Store session in Redis

Presist data in memory

Process dependecy

  • First class process
  • Base of scale up
  • Presist in backing services
  • Stateless

Build Release Run

Code

--------

   -----------

Unit Test

Code Quality

Style Check

Integration

.....

Product

Config

Release

V1
V2

...

Pick a release

What about rollback?

Dev/prod Parity - I

  • Changes go to production in 10 mins
  • Dev & QA monitor the deployment and service states
  • Use docker-compose to build local dev env

Have a parity env, we could mange more than 10 services 

Weeks

Hours

Different People

Divergent

Same People

Similar

HOW TO ?

Dev/prod Parity - II

dev:
  extends:
    file: docker-compose-common.yml
    service: _base
  environment:
    USER:
  links:
  - setting_db

redis:
  extends:
    file: docker-compose-common.yml
    service: redis

setting_db:
  extends:
    file: docker-compose-common.yml
    service: postgres

comm_setting_api:
  extends:
    file: docker-compose-common.yml
    service: _base
  command: bash -c "script/start_server.sh"
  ports:
    - "8080:80"
  links:
    - setting_db
    - redis

Cache

DB

API

compose file

Log & Alarm & Diagnostic

Logfile on disk

Output log in stream

  • presist

  • forward to center
  • analyze
  • archival
  • congiurable
  • App should not concern local resources
  • Consider log, APM, diagnostic, alarm as same pattern

Wrap Up

5 Dev, 1 QA, 1 Ops

  • more than 20 repo
  • more than 20 pipelines
  • 11 apps: services, front-end, stream processors and admin apps
  • Persistences:  RDS, Psql, MySQL, Redis, S3 ...
  • Others: SQS, Kensis, SES, SNS ...
  • Maintains: Log, APM, CloudWatch, Pager

Changes go to prod in MINS

Release more than 190 times in developing

Q & A

Thanks!

12-Factor App

By Yuchen Zhang

12-Factor App

  • 669