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

Building Apps for Immutable Servers

Daniel Gomes
December 06, 2018

Building Apps for Immutable Servers

The deck title is the original one but I changed it to be more accurate with the content. So the new title is "Scaling Apps with Immutable Servers".

This talk was presented at SymfonyCon 2018 in Lisbon.

Daniel Gomes

December 06, 2018
Tweet

More Decks by Daniel Gomes

Other Decks in Programming

Transcript

  1. About me Daniel Gomes Problem Solver @ @phplx organizer Twitter:

    @_dcsg Blog: dcsg.me 5 #SymfonyCon @_dcsg
  2. 6 • Different types of Scaling • Configuration Drift/Management •

    Different types of Servers • Build Process for your Web/Application Server Some Topics to Cover #SymfonyCon @_dcsg
  3. Users growth Users per hour 0 250 500 750 1000

    April May June July August September 12 #SymfonyCon @_dcsg
  4. Server does not handle the load CPU Usage 0 50

    100 150 200 10:00 10:10 10:20 10:30 10:40 10:50 11:00 11:10 11:20 14 #SymfonyCon @_dcsg
  5. We need to SCALE!!! 15 Photo by Linda Xu on

    Unsplash #SymfonyCon @_dcsg
  6. Can we scale this? 18 Database Cron Jobs Queues Cache

    Application Server #SymfonyCon @_dcsg
  7. Can we scale this? 19 YES and NO Database Cron

    Jobs Queues Cache Application Server #SymfonyCon @_dcsg
  8. Horizontal Scaling 27 Load balancer Cluster Database Cron Jobs Queues

    Cache Application Server 1 Database Cron Jobs Queues Cache Application Server 2 Database Cron Jobs Queues Cache Application Server 3 Database Cron Jobs Queues Cache Application Server 4 #SymfonyCon @_dcsg
  9. Horizontal Scaling 28 Load balancer Cluster Database Cron Jobs Queues

    Cache Application Server 1 Database Cron Jobs Queues Cache Application Server 2 Database Cron Jobs Queues Cache Application Server 3 Database Cron Jobs Queues Cache Application Server 4 Will this work? #SymfonyCon @_dcsg
  10. Horizontal Scaling 29 Load balancer Cluster Database Cron Jobs Queues

    Cache Application Server 1 Database Cron Jobs Queues Cache Application Server 2 Database Cron Jobs Queues Cache Application Server 3 Database Cron Jobs Queues Cache Application Server 4 Will this work? NO #SymfonyCon @_dcsg
  11. The “new” Architecture 32 Database Cron Jobs Queues Cache Application

    Server Load Balancer Application Cluster AMQP Cluster DB Cluster CDN/Assets #SymfonyCon @_dcsg
  12. Our new Application Cluster 33 Load Balancer Application Cluster AMQP

    Cluster DB Cluster CDN/Assets #SymfonyCon @_dcsg
  13. SSH’s into production machine and live fixes are done 35

    Photo by Markus Spiske on Unsplash #SymfonyCon @_dcsg
  14. Configuration Drift • Manual ad-hoc changes and updates to servers

    that are not recorded 40 #SymfonyCon @_dcsg
  15. Configuration Drift • Manual ad-hoc changes and updates to servers

    that are not recorded • Servers in your infrastructure became more and more different from each others 40 #SymfonyCon @_dcsg
  16. The cluster state after a few weeks State A State

    C State B State B 41 #SymfonyCon @_dcsg
  17. Configuration Management The process of systematically handling changes to a

    system in a way that it maintains integrity over time. 49 #SymfonyCon @_dcsg
  18. Configuration Management Spin up Base Image Run Config Management Server

    in desired state Changes Edit config file Upgrade/install package … Running Server 50 #SymfonyCon @_dcsg
  19. Applying to the cluster state State A State C State

    B State B Config Management Apply State D 51 #SymfonyCon @_dcsg
  20. The cluster state after CM ran State D State D

    State D State D 52 #SymfonyCon @_dcsg
  21. Quick recap • Vertical & Horizontal Scaling • Configuration Drift

    • Problems of the Snowflake Servers 54 #SymfonyCon @_dcsg
  22. Quick recap • Vertical & Horizontal Scaling • Configuration Drift

    • Problems of the Snowflake Servers • Configuration Management 54 #SymfonyCon @_dcsg
  23. “A server should be like a phoenix, regularly rising from

    the ashes.” - Martin Fowler in PhoenixServer 56 #SymfonyCon @_dcsg
  24. Phoenix Servers • Avoid configuration drifts • Disposable servers •

    Servers can be built from scratch 57 #SymfonyCon @_dcsg
  25. The cluster Re-launch an instance State D State D State

    D State D Terminate 
 Instance 58 #SymfonyCon @_dcsg
  26. The cluster Re-launch an instance State D State D State

    D Config Management 58 #SymfonyCon @_dcsg
  27. The cluster Re-launch an instance State D State D State

    D Config Management 58 #SymfonyCon @_dcsg
  28. The cluster Re-launch an instance State D State D State

    D Config Management Apply State D 58 #SymfonyCon @_dcsg
  29. The cluster Re-launch an instance State D State D State

    D Config Management Apply State D 58 #SymfonyCon @_dcsg
  30. The cluster Re-launch an instance State D State D State

    D Config Management Apply State D State D 58 #SymfonyCon @_dcsg
  31. Built Process Spin up Base Image Run Config Management Server

    in desire state Install packages Create folders Create user Upload app etc Run Config Management 63 #SymfonyCon @_dcsg
  32. Built Process Spin up Base Image Run Config Management Server

    in desire state Install packages Create folders Create user Upload app etc Run Config Management Repositories unavailable 63 #SymfonyCon @_dcsg
  33. Built Process Spin up Base Image Run Config Management Server

    in desire state Install packages Create folders Create user Upload app etc Run Config Management Repositories unavailable 63 #SymfonyCon @_dcsg
  34. "An Immutable Server is a server, that once deployed, is

    never modified, merely replaced with a new updated instance." - Kief Morris in ImmutableServer 66 #SymfonyCon @_dcsg
  35. Immutable Server Build Process Spin up Base Image Run Config

    Management (puppet, chef, ansible) 82 #SymfonyCon @_dcsg
  36. Immutable Server Build Process Server in desire state configure application


    environment Spin up Base Image Run Config Management (puppet, chef, ansible) 82 #SymfonyCon @_dcsg
  37. Immutable Server Build Process Bake In the App Server in

    desire state configure application
 environment Spin up Base Image Run Config Management (puppet, chef, ansible) 82 #SymfonyCon @_dcsg
  38. Immutable Server Build Process Bake In the App App Final

    Image Server in desire state configure application
 environment Spin up Base Image Run Config Management (puppet, chef, ansible) 82 #SymfonyCon @_dcsg
  39. Build Image Stages Flow Example Base Image OS Hardening Common

    tools
 (vim, htop, etc) etc Application Base Image Install necessary software to run the App Create user/folders 83
  40. Build Image Stages Flow Example Base Image OS Hardening Common

    tools
 (vim, htop, etc) etc Application Base Image Install necessary software to run the App Create user/folders Application Final Image Upload App Script to run App at boot Composer Install Clear Cache 83
  41. Build Image Stages Flow Example Base Image OS Hardening Common

    tools
 (vim, htop, etc) etc Application Base Image Install necessary software to run the App Create user/folders Application Final Image Upload App Script to run App at boot Composer Install Clear Cache System upgrades & Security updates 83
  42. Build Image Stages Flow Example Base Image OS Hardening Common

    tools
 (vim, htop, etc) etc Application Base Image Install necessary software to run the App Create user/folders Application Final Image Upload App Script to run App at boot Composer Install Clear Cache System upgrades & Security updates Application security, package, configuration updates 83
  43. Building Tips for a Symfony App • composer install --no-dev

    --optimize-autoloader • php bin/console cache:clear --env=prod —no-debug • Clearing your APC cache • Build or pushing Assets to CDN 84 #SymfonyCon @_dcsg
  44. High-Availability • Auto-scaling • Web Tier • Application Services Tier

    • Backing Services Tier (DB, AMQP, etc) • Chaos Monkey • Chaos Kong 87 #SymfonyCon @_dcsg