Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to 12-Factor Apps

Introduction to 12-Factor Apps

These slides are from my talk at Philly Microservices meetup on January 28th, 2016.

Ross Kukulinski

January 28, 2016
Tweet

More Decks by Ross Kukulinski

Other Decks in Technology

Transcript

  1. @RossKukulinski 12 Factor Apps TLDR; • http://12factor.net • Written by

    Andrew Wiggins (Heroku Founder) • ‘Manifesto’ for building SaaS Apps • Non-specific re: Language, DB, OS, etc
  2. @RossKukulinski 1. Codebase • Use revision control (Git, Mecurial, Subversion)

    • One-to-one correlation between codebase and app • Multiple codebases: not an app, it’s a distributed system. Each component is an app • Multiple apps sharing the same code NOT OK • Refactor into set of modules/libraries to be used by dependency manager
  3. @RossKukulinski 2. Dependencies • You app probably uses sub-modules or

    libraries • Never rely on implicit existence of system-wide packages • Use explicit dependency declaration • gemfile, pip/virtualenv, autoconf, npm • (Containers can really help here…)
  4. @RossKukulinski 3. Config • Application configuration defines differences between deploys

    (staging, production, dev) • e.g. username/passwords for backing services • Config should NOT be declared as constants in code • Note: This does not include internal app config • Config SHOULD be defined in environment variables*
  5. @RossKukulinski 4. Backing services • Treat backing services as attached

    resources • e.g. MySQL, RabbitMQ, Redis, SMTP • Whether they are local, remote, 3rd party • Resources should be able to be attached/detached from deploys at will • e.g. what happens if your db crashes?
  6. @RossKukulinski 5. Build, release, run 1. Build • Converts code

    to executable bundle • Fetches dependencies • Compiles binaries & assets 2. Release • Combines build with current config 3. Run • Application is run in the execution environment
  7. @RossKukulinski 5. Build, release, run • Every release should have

    unique ID • git-sha, timestamp, auto-incrementing number • Impossible to make changes to code at runtime • Builds triggered by developers when code is deployed
  8. @RossKukulinski 6. Processes • Apps are executed as one or

    more processes • Processes should be stateless and share-nothing • Data persisted to stateful backing service • Memory/Filesystem cache OK for single- transaction cache • “Sticky Sessions” are a violation!
  9. @RossKukulinski 7. Port binding • Applications should be completely self-contained

    • e.g. php might run inside Apache, Java in Tomcat • Apache/Tomcat should be injected as a dependency as part of the application • Application should export HTTP as a service binding to a port • Or other protocol: XMPP, Redis, Mysql, etc • App can become a backing service for another app
  10. @RossKukulinski 8. Concurrency • Processes are first class citizen •

    Workloads handled by different process types (microservice!) • (Note: internal threads ok — e.g. VM or EventMachine) • Application must be able to span multiple processes running on multiple physical machines • e.g. Scale horizontally • Apps should never demonize or write PID files • Rely on the OS process managers
  11. @RossKukulinski 9. Disposability • Cattle, not pets! • Process can

    be started or stopped at any time • Processes should attempt to minimize startup time • Processes shut down gracefully on SIGTERM • Sudden death of process should be ok • Job queues FTW
  12. @RossKukulinski 10. Dev/prod parity • App should be designed for

    continuous deployment • Time gap should be small between dev -> prod • Developers should be involved in deploy / monitoring production • Development and production environments should be as similar as possible
  13. @RossKukulinski 11. Logs • Logs should be time-ordered event streams

    • Apps should not concern with routing or storage of its output stream • Use stdout • Production log stream captured by execution environment (routed via Fluent/Logstash/etc) • Logs should be indexed and capable of analysis • ElasticSearch/Splunk/Loggly/etc
  14. @RossKukulinski 12. Admin processes • Database migrations, REPL inspection, one-time

    scripts • Should be run in identical environment as long- running processes • Run against a release, using same codebase and config