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

12 Factors of Pain and Suffering

12 Factors of Pain and Suffering

Want to build simple, scalable and reliable web applications? In this presentation, you'll learn all about the 12-Factor App, and the principles it teaches.

You'll also see firsthand how even an experienced programmer has screwed up these best practices in every way imaginable, sometimes with terrible consequences.

Randall Degges

November 14, 2019
Tweet

More Decks by Randall Degges

Other Decks in Programming

Transcript

  1. @rdegges The 12 Factor App "A methodology for building simple,

    scalable, and dependable web applications."
  2. @rdegges 818-217-9229 - Randall Degges - Granada Hills, CA 94519

    - He is *not* a spam bot - Etc... $$$ I hate your website. CODEBASE newsketchdomain.com CODEBASE1 CODEBASE2 domain1.com domain2.com CTRL-C + CTRL-V
  3. @rdegges How It Works { "dependencies": { "axios": "^0.18.0", "dotenv":

    "^6.1.0", "express": "^4.16.4", "vue": "^2.5.17" } } Declare Dependencies $ npm install + dotenv@6.1.0 + axios@0.18.0 + express@4.16.4 + vue@2.5.17 added 57 packages from 41 contributors and audited 128 packages in 2.064s found 0 vulnerabilities Isolate Dependencies
  4. @rdegges Image Optimization API Shrink this image! OK! Let me

    optimize that for you. VPS - optipng - jpegoptim - gifsicle - ... code optipng gifsicle
  5. @rdegges IV. Backing Services Treat backing services as attached resources.

    Production Deploy Postgres S3 SMTP smtp://auth@host https://auth@s3.amazonaws.com postgres://auth@host/db
  6. @rdegges Blog MySQL I should make a blog. I should

    give out pirated movies to everyone. ERROR: No disk space MySQL
  7. @rdegges WEbsite Code $ scp -r my_project root@104.102.96.72: Web Server

    $ ssh root@104.102.96.72 (root) $ vim my_project/admin.php
  8. @rdegges VII. Port Binding Expose services via port binding. 0.0.0.0:80

    localhost:443 Routing App $PORT App $PORT App $PORT
  9. @rdegges VIII. Concurrency Scale out via the process model. web.1

    web.2 worker.1 worker.2 worker.3 worker.4 clock.1 Process Types Scale
  10. @rdegges IX. Disposability Maximize robustness with fast startup and graceful

    shutdown. Shut down gracefully when SIGTTERM is received Shut down within a few seconds Be robust against sudden death
  11. @rdegges Process 1 Load Balancer Requests Process 2 Process 3

    Process 4 Process 5 def startup(): download_audio() listen(env["PORT"])
  12. @rdegges X. Dev/Prod Parity Keep development, staging, and production as

    similar as possible. Code Postgres SQLite VARCHARRRRR
  13. @rdegges XI. Logs Treat logs as event streams. App <log

    entry> <log entry> <log entry> <log entry> <log entry> <log entry> <log entry> ... Order by timestamp Write to STDOUT Consist of *all* process and backing services logs
  14. @rdegges Conference Call Web App Conference Call API Asterisk Asterisk

    Asterisk <billable call> <billable call> <billable call> <billable call> <billable call> ... calls.csv $ scp root@...:calls.csv . Log Router
  15. @rdegges XII. Admin Processes Run admin/management tasks as one-off processes.

    Code Admin Task Run a database migration $ python manage.py migrate Prod Infrastructure
  16. @rdegges Run a database migration New Feature Alter Table DB

    Migration Code "I only need to do this once… So..." $ python manage.py migrate Deploy Feature!