Slide 1

Slide 1 text

Building Apps for Immutable Servers Daniel Gomes 1 #SymfonyCon @_dcsg

Slide 2

Slide 2 text

Building Apps for Immutable Servers Daniel Gomes 2 #SymfonyCon @_dcsg

Slide 3

Slide 3 text

Scaling Apps with Immutable Servers Daniel Gomes 3 #SymfonyCon @_dcsg

Slide 4

Slide 4 text

Disclaimer • No Code • Not going to build an App 4 #SymfonyCon @_dcsg

Slide 5

Slide 5 text

About me Daniel Gomes Problem Solver @ @phplx organizer Twitter: @_dcsg Blog: dcsg.me 5 #SymfonyCon @_dcsg

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

The Beginning 7 Photo by José Alejandro Cuffia on Unsplash

Slide 8

Slide 8 text

Build the App 8 Photo by Charles Deluvio on Unsplash

Slide 9

Slide 9 text

1st Infrastructure Architecture 9 One Server to rule them all #SymfonyCon @_dcsg

Slide 10

Slide 10 text

Server/Monolith 10 Database Cron Jobs Queues Cache Application Server #SymfonyCon @_dcsg

Slide 11

Slide 11 text

Launch the App 11 Photo by NASA on Unsplash

Slide 12

Slide 12 text

Users growth Users per hour 0 250 500 750 1000 April May June July August September 12 #SymfonyCon @_dcsg

Slide 13

Slide 13 text

Server Unavailable https://http.cat/503 13 #SymfonyCon @_dcsg

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

We need to SCALE!!! 15 Photo by Linda Xu on Unsplash #SymfonyCon @_dcsg

Slide 16

Slide 16 text

Easy! 16 Photo by Aziz Acharki on Unsplash

Slide 17

Slide 17 text

Is that easy? https://martinfowler.com/bliki/PhoenixServer.html 17

Slide 18

Slide 18 text

Can we scale this? 18 Database Cron Jobs Queues Cache Application Server #SymfonyCon @_dcsg

Slide 19

Slide 19 text

Can we scale this? 19 YES and NO Database Cron Jobs Queues Cache Application Server #SymfonyCon @_dcsg

Slide 20

Slide 20 text

Vertical Scaling 20 #SymfonyCon @_dcsg

Slide 21

Slide 21 text

More Memory 21 Vertical Scaling #SymfonyCon @_dcsg

Slide 22

Slide 22 text

More CPU 22 Vertical Scaling #SymfonyCon @_dcsg

Slide 23

Slide 23 text

More Disk 23 Vertical Scaling #SymfonyCon @_dcsg

Slide 24

Slide 24 text

Fine tuning PHP | PHP-FPM NGINX | Apache 24 Vertical Scaling #SymfonyCon @_dcsg

Slide 25

Slide 25 text

Horizontal Scaling 25 #SymfonyCon @_dcsg

Slide 26

Slide 26 text

Horizontal Scaling 26 Database Cron Jobs Queues Cache Application Instance 4 Instances Current Goal #SymfonyCon @_dcsg

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

Why? 30 #SymfonyCon @_dcsg

Slide 31

Slide 31 text

Persistence and State 31 Horizontal Scaling #SymfonyCon @_dcsg

Slide 32

Slide 32 text

The “new” Architecture 32 Database Cron Jobs Queues Cache Application Server Load Balancer Application Cluster AMQP Cluster DB Cluster CDN/Assets #SymfonyCon @_dcsg

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

But… problems happen! https://http.cat/500 34 #SymfonyCon @_dcsg

Slide 35

Slide 35 text

SSH’s into production machine and live fixes are done 35 Photo by Markus Spiske on Unsplash #SymfonyCon @_dcsg

Slide 36

Slide 36 text

Problem Solved 36 Photo by Aziz Acharki on Unsplash

Slide 37

Slide 37 text

Or not? 37 #SymfonyCon @_dcsg

Slide 38

Slide 38 text

The new cluster state Fixed Instance Instances
 not in same state 38 #SymfonyCon @_dcsg

Slide 39

Slide 39 text

Configuration Drift 39 #SymfonyCon @_dcsg

Slide 40

Slide 40 text

Configuration Drift 40 #SymfonyCon @_dcsg

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

The cluster state after a few weeks State A State C State B State B 41 #SymfonyCon @_dcsg

Slide 44

Slide 44 text

Snowflake Server 42 #SymfonyCon @_dcsg

Slide 45

Slide 45 text

Long running Servers 43 Snowflake Servers #SymfonyCon @_dcsg

Slide 46

Slide 46 text

No consistency between Servers 44 Snowflake Servers #SymfonyCon @_dcsg

Slide 47

Slide 47 text

Hard to reproduce 45 Snowflake Servers #SymfonyCon @_dcsg

Slide 48

Slide 48 text

Lack of Confidence 46 Snowflake Servers #SymfonyCon @_dcsg

Slide 49

Slide 49 text

How can we solve this? 47 Snowflake Servers #SymfonyCon @_dcsg

Slide 50

Slide 50 text

Configuration Management with Automation Tools 48 #SymfonyCon @_dcsg

Slide 51

Slide 51 text

Configuration Management The process of systematically handling changes to a system in a way that it maintains integrity over time. 49 #SymfonyCon @_dcsg

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

Applying to the cluster state State A State C State B State B Config Management Apply State D 51 #SymfonyCon @_dcsg

Slide 54

Slide 54 text

The cluster state after CM ran State D State D State D State D 52 #SymfonyCon @_dcsg

Slide 55

Slide 55 text

Automation Tools for CM 53 #SymfonyCon @_dcsg

Slide 56

Slide 56 text

Quick recap 54 #SymfonyCon @_dcsg

Slide 57

Slide 57 text

Quick recap • Vertical & Horizontal Scaling 54 #SymfonyCon @_dcsg

Slide 58

Slide 58 text

Quick recap • Vertical & Horizontal Scaling • Configuration Drift 54 #SymfonyCon @_dcsg

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

Phoenix Servers https://martinfowler.com/bliki/PhoenixServer.html 55

Slide 62

Slide 62 text

“A server should be like a phoenix, regularly rising from the ashes.” - Martin Fowler in PhoenixServer 56 #SymfonyCon @_dcsg

Slide 63

Slide 63 text

Phoenix Servers • Avoid configuration drifts • Disposable servers • Servers can be built from scratch 57 #SymfonyCon @_dcsg

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

The cluster Re-launch an instance State D State D State D 58 #SymfonyCon @_dcsg

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

Spinning up new servers is not a problem anymore! 59 #SymfonyCon @_dcsg

Slide 72

Slide 72 text

But… 60 #SymfonyCon @_dcsg

Slide 73

Slide 73 text

Is Idempotence guaranteed? 61 #SymfonyCon @_dcsg

Slide 74

Slide 74 text

What if the packages repositories are down? 62 #SymfonyCon @_dcsg

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

How can we fix this? 64 #SymfonyCon @_dcsg

Slide 79

Slide 79 text

Immutable Servers https://martinfowler.com/bliki/ImmutableServer.html 65

Slide 80

Slide 80 text

"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

Slide 81

Slide 81 text

Final image with everything baked in. 67 #SymfonyCon @_dcsg

Slide 82

Slide 82 text

No changes after it’s built 68 #SymfonyCon @_dcsg

Slide 83

Slide 83 text

Include scripts to start the Application on boot. 69 #SymfonyCon @_dcsg

Slide 84

Slide 84 text

Easy to scale-out, deploy, and rollback 70 #SymfonyCon @_dcsg

Slide 85

Slide 85 text

Therefore… 71 #SymfonyCon @_dcsg

Slide 86

Slide 86 text

Confidence 72 #SymfonyCon @_dcsg

Slide 87

Slide 87 text

Reliability 73 #SymfonyCon @_dcsg

Slide 88

Slide 88 text

Trust 74 #SymfonyCon @_dcsg

Slide 89

Slide 89 text

Sleep quietly 75 Photo by Lauren Kay on Unsplash

Slide 90

Slide 90 text

And also… 76 #SymfonyCon @_dcsg

Slide 91

Slide 91 text

The Twelve-Factor App 77 https://12factor.net/ #SymfonyCon @_dcsg

Slide 92

Slide 92 text

Reproducible Builds 78 https://reproducible-builds.org/docs/definition/ #SymfonyCon @_dcsg

Slide 93

Slide 93 text

How do we Build it? 79 #SymfonyCon @_dcsg

Slide 94

Slide 94 text

CI/CD Pipelines 80 #SymfonyCon @_dcsg

Slide 95

Slide 95 text

Build !== Run 81 #SymfonyCon @_dcsg

Slide 96

Slide 96 text

Immutable Server Build Process Spin up Base Image 82 #SymfonyCon @_dcsg

Slide 97

Slide 97 text

Immutable Server Build Process Spin up Base Image Run Config Management (puppet, chef, ansible) 82 #SymfonyCon @_dcsg

Slide 98

Slide 98 text

Immutable Server Build Process Server in desire state configure application
 environment Spin up Base Image Run Config Management (puppet, chef, ansible) 82 #SymfonyCon @_dcsg

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

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

Slide 101

Slide 101 text

Build Image Stages Flow Example Base Image OS Hardening Common tools
 (vim, htop, etc) etc 83

Slide 102

Slide 102 text

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

Slide 103

Slide 103 text

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

Slide 104

Slide 104 text

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

Slide 105

Slide 105 text

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

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

Build Tools 85

Slide 108

Slide 108 text

Next Steps 86 #SymfonyCon @_dcsg

Slide 109

Slide 109 text

High-Availability • Auto-scaling • Web Tier • Application Services Tier • Backing Services Tier (DB, AMQP, etc) • Chaos Monkey • Chaos Kong 87 #SymfonyCon @_dcsg

Slide 110

Slide 110 text

Final Notes 88 #SymfonyCon @_dcsg

Slide 111

Slide 111 text

Prepare your Application for Immutable Servers 89 #SymfonyCon @_dcsg

Slide 112

Slide 112 text

But only use Immutable Servers when you REALLY NEED! 90 #SymfonyCon @_dcsg

Slide 113

Slide 113 text

Resources • https://martinfowler.com - Martin Fowler • https://medium.com/netflix-techblog/chaos- engineering-upgraded-878d341f15fa • https://symfony.com/blog/new-in-symfony- reproducible-builds 91 #SymfonyCon @_dcsg

Slide 114

Slide 114 text

Questions Twitter: @_dcsg
 Blog: dcsg.me ? we are hiring! 92 #SymfonyCon @_dcsg

Slide 115

Slide 115 text

Thanks! 93 #SymfonyCon @_dcsg