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.

56badf521701d4f9b3a394d3ef6e90c4?s=128

Randall Degges

November 14, 2019
Tweet

Transcript

  1. @rdegges @rdegges 12 Factors of PAIN and SUFFERING Sad Programming

    Stories
  2. @rdegges HEY, I'm Randall. Head of DevRel @ OKTA Python/JS/Go

    Hacker Open Source * Author Builder
  3. @rdegges The 12 Factor App "A methodology for building simple,

    scalable, and dependable web applications."
  4. @rdegges I fucked up.

  5. @rdegges I. Codebase One codebase tracked in revision control, many

    deploys. Code Prod Stag Dev1 Dev2
  6. @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
  7. @rdegges

  8. @rdegges II. Dependencies Explicitly declare and isolate dependencies.

  9. @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
  10. @rdegges Image Optimization API Shrink this image! OK! Let me

    optimize that for you. VPS - optipng - jpegoptim - gifsicle - ... code optipng gifsicle
  11. @rdegges III. Config Store config in the environment DATABASE_URL MAX_THREADS

    API_KEY PRICE
  12. @rdegges Asterisk Fuuuuuuuuuuuuuck. Phone calls SMS Etc. Rackspace API Key

    Code GitHub! - $25,000
  13. @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
  14. @rdegges Blog MySQL I should make a blog. I should

    give out pirated movies to everyone. ERROR: No disk space MySQL
  15. @rdegges V. Build, Release, Run Strictly separate build and run

    stages. Code Build Config Release
  16. @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
  17. @rdegges

  18. @rdegges VI. Processes Execute the app as one or more

    stateless processes.
  19. @rdegges Conference Call App Datacenter Conference Call App Conference Call

    App 818-217-9229 555-444-3333 925-431-1337
  20. @rdegges VII. Port Binding Expose services via port binding. 0.0.0.0:80

    localhost:443 Routing App $PORT App $PORT App $PORT
  21. @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
  22. @rdegges IRC Web App daemon(); process process process process IRC

    Room IRC Room IRC Room
  23. @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
  24. @rdegges Process 1 Load Balancer Requests Process 2 Process 3

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

    similar as possible. Code Postgres SQLite VARCHARRRRR
  26. @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
  27. @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
  28. @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
  29. @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!
  30. @rdegges @rdegges Thank You rdegges.com developer.okta.com @oktadev