Slide 1

Slide 1 text

Elastic Scaling in a (Micro)service oriented Architecture @BastianHofmann

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Microservices

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Service Oriented Architecture

Slide 6

Slide 6 text

Monolith

Slide 7

Slide 7 text

http://blog.philipphauer.de/microservices-nutshell-pros-cons/ Monolith Microservices

Slide 8

Slide 8 text

Benefits

Slide 9

Slide 9 text

Problems

Slide 10

Slide 10 text

Problems

Slide 11

Slide 11 text

Challenges

Slide 12

Slide 12 text

Performance

Slide 13

Slide 13 text

Latency

Slide 14

Slide 14 text

Stability

Slide 15

Slide 15 text

Reliability

Slide 16

Slide 16 text

Transparency

Slide 17

Slide 17 text

Learning Curves

Slide 18

Slide 18 text

Code Reuse

Slide 19

Slide 19 text

Maintenance

Slide 20

Slide 20 text

Elastic Scaling?

Slide 21

Slide 21 text

How can we solve them

Slide 22

Slide 22 text

A lot of this is also useful for monoliths

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Questions? Ask

Slide 26

Slide 26 text

http://speakerdeck.com/u/bastianhofmann

Slide 27

Slide 27 text

https://www.flickr.com/photos/npobre/2601582256/

Slide 28

Slide 28 text

Deployment

Slide 29

Slide 29 text

How to get the services on our servers?

Slide 30

Slide 30 text

Diverse technology stacks

Slide 31

Slide 31 text

The same for every service

Slide 32

Slide 32 text

One Click Deployment

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Automation

Slide 35

Slide 35 text

Build/Test/Release pipeline

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

https://www.flickr.com/photos/40987321@N02/5580348753/

Slide 38

Slide 38 text

Base boxes

Slide 39

Slide 39 text

Services installed in a sandbox

Slide 40

Slide 40 text

https://www.docker.com/

Slide 41

Slide 41 text

https://twitter.com/mfdii/status/697532387240996864

Slide 42

Slide 42 text

Availability

Slide 43

Slide 43 text

Zero Downtime Deployments

Slide 44

Slide 44 text

Server Server Server Server

Slide 45

Slide 45 text

Stability

Slide 46

Slide 46 text

Canary environments

Slide 47

Slide 47 text

Server Server Server Server

Slide 48

Slide 48 text

Fast rollbacks

Slide 49

Slide 49 text

•Ansible •Capistrano •Saltstack •Custom •….

Slide 50

Slide 50 text

Running the service

Slide 51

Slide 51 text

How do I stop and start a service and ensure it keeps running?

Slide 52

Slide 52 text

Diverse technology stacks

Slide 53

Slide 53 text

The same for every service

Slide 54

Slide 54 text

•Supervisord •Upstart •S6 •Ruine •Monit •Circus •Restartd •…

Slide 55

Slide 55 text

Releases

Slide 56

Slide 56 text

How to synchronize changes over services?

Slide 57

Slide 57 text

API Versioning

Slide 58

Slide 58 text

GET /v23/foo/abr Host: myservice.local

Slide 59

Slide 59 text

GET /foo/abr Host: myservice.local X-Version: 23

Slide 60

Slide 60 text

GET /foo/abr?version=23 Host: myservice.local

Slide 61

Slide 61 text

GET /foo/abr Host: myservice.local Accept: application/vnd.company.v23+json

Slide 62

Slide 62 text

No backwards compatibility breaks

Slide 63

Slide 63 text

Feature Flags

Slide 64

Slide 64 text

public function hasAccess() { return featureFlag()->isActive( FeatureFlag::TEST_ONE ); }

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Shared database

Slide 68

Slide 68 text

Headers

Slide 69

Slide 69 text

GET /foo/abr Host: myservice.local X-Flag-NewFeature: 1

Slide 70

Slide 70 text

Configuration Management

Slide 71

Slide 71 text

How do I synchronize configuration over services?

Slide 72

Slide 72 text

[ "db_user": "user", "db_pw": "pw", "serviceA": "serviceA.local:8018" ]

Slide 73

Slide 73 text

Config file on disk

Slide 74

Slide 74 text

Duplication

Slide 75

Slide 75 text

Inconsistencies

Slide 76

Slide 76 text

Consul https://www.consul.io/

Slide 77

Slide 77 text

•Consul •Zookeeper •etcd •…

Slide 78

Slide 78 text

Consul Server Consul Server Consul Server Consul Agent ver Consul Agent Server Consul Agent Server Co Ag Server

Slide 79

Slide 79 text

https://github.com/sensiolabs/consul-php-sdk

Slide 80

Slide 80 text

Key/Value Store

Slide 81

Slide 81 text

$kv->put('test/foo/bar', 'bazinga'); $kv->get('test/foo/bar', ['raw' => true]); $kv->delete('test/foo/bar');

Slide 82

Slide 82 text

Credentials

Slide 83

Slide 83 text

$kv->put('test/db/pw', 'secret_pw');

Slide 84

Slide 84 text

https://www.vaultproject.io/

Slide 85

Slide 85 text

Cycling of credentials

Slide 86

Slide 86 text

Service Discovery

Slide 87

Slide 87 text

How does one service know where another service is?

Slide 88

Slide 88 text

Hostname + Port

Slide 89

Slide 89 text

Server Service A Server Service B Service C Service C

Slide 90

Slide 90 text

Configuration

Slide 91

Slide 91 text

$config = [ 'serviceA' => [ '192.168.0.1:8001', '192.168.0.2:8001', ], 'serviceB' => [ '192.168.0.1:8002', ], 'serviceC' => [ '192.168.0.2:8003', ] ];

Slide 92

Slide 92 text

Consul https://www.consul.io/

Slide 93

Slide 93 text

Load balancing?

Slide 94

Slide 94 text

Round robin in the client

Slide 95

Slide 95 text

$config = [ 'serviceA' => [ '192.168.0.1:8001', '192.168.0.2:8001', ], 'serviceB' => [ '192.168.0.1:8002', ], 'serviceC' => [ '192.168.0.2:8003', ] ];

Slide 96

Slide 96 text

Service/Server down?

Slide 97

Slide 97 text

$config = [ 'serviceA' => [ '192.168.0.1:8001', '192.168.0.2:8001', ], 'serviceB' => [ '192.168.0.1:8002', ], 'serviceC' => [ '192.168.0.2:8003', ] ];

Slide 98

Slide 98 text

Health checks

Slide 99

Slide 99 text

GET /health HTTP/1.1 Host: serviceA.local HTTP/1.1 200 OK

Slide 100

Slide 100 text

Consul for Service Discovery

Slide 101

Slide 101 text

Consul https://www.consul.io/

Slide 102

Slide 102 text

Consul Server Consul Server Consul Server Consul Agent ver Consul Agent Server Consul Agent Server Co Ag Server

Slide 103

Slide 103 text

Consul Agent Server Service A Registration Health check

Slide 104

Slide 104 text

Consul API

Slide 105

Slide 105 text

DNS

Slide 106

Slide 106 text

admin@hashicorp: dig web-frontend.service.consul. ANY ; <<>> DiG 9.8.3-P1 <<>> web-frontend.service.consul. ANY ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29981 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;web-frontend.service.consul. IN ANY ;; ANSWER SECTION: web-frontend.service.consul. 0 IN A 10.0.3.83 web-frontend.service.consul. 0 IN A 10.0.1.109

Slide 107

Slide 107 text

Monitoring

Slide 108

Slide 108 text

How are my services behaving?

Slide 109

Slide 109 text

Central Log Management

Slide 110

Slide 110 text

Elasticsearch
 Kibana Logstash

Slide 111

Slide 111 text

Logstash elasticsearch webserver webserver webserver AMQP log log log logstash logstash logstash

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

Tracing IDs

Slide 114

Slide 114 text

web server http service http service http service http service create unique trace_id for request user request trace_id trace_id trace_id trace_id log log log log log

Slide 115

Slide 115 text

https://www.loggly.com/

Slide 116

Slide 116 text

https://getsentry.com/

Slide 117

Slide 117 text

Measure everything

Slide 118

Slide 118 text

Server metrics

Slide 119

Slide 119 text

Application metrics

Slide 120

Slide 120 text

StatsD + Graphite

Slide 121

Slide 121 text

webserver webserver webserver statsd statsd statsd graphite aggregated UPD message statsd

Slide 122

Slide 122 text

https://www.librato.com

Slide 123

Slide 123 text

http://www.soasta.com/

Slide 124

Slide 124 text

Profiling

Slide 125

Slide 125 text

XHProf

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

https://tidways.io/

Slide 129

Slide 129 text

https://blackfire.io/

Slide 130

Slide 130 text

newrelic.com

Slide 131

Slide 131 text

Handling failures

Slide 132

Slide 132 text

What do I do when something breaks?

Slide 133

Slide 133 text

Errors happen

Slide 134

Slide 134 text

Detecting regressions

Slide 135

Slide 135 text

Server outages

Slide 136

Slide 136 text

Database overloads

Slide 137

Slide 137 text

Bugs

Slide 138

Slide 138 text

Service A Service B 200 OK

Slide 139

Slide 139 text

Service A Service B 5xx

Slide 140

Slide 140 text

Service A Service B Timeout

Slide 141

Slide 141 text

Circuit Breakers

Slide 142

Slide 142 text

Service A Service B 200 OK Circuit Breaker Status: closed Error rate: 0

Slide 143

Slide 143 text

Service A Service B Error Circuit Breaker Status: -> open Error rate: > threshold

Slide 144

Slide 144 text

Service A Service B Circuit Breaker Status: -> open Error rate: > threshold

Slide 145

Slide 145 text

Service A Service B Error Circuit Breaker Status: -> open Error rate: > threshold Test if still failing

Slide 146

Slide 146 text

Service A Service B 200 OK Circuit Breaker Status: -> close Error rate: 0 Test if still failing

Slide 147

Slide 147 text

https://github.com/Netflix/Hystrix

Slide 148

Slide 148 text

https://github.com/odesk/phystrix

Slide 149

Slide 149 text

Gracefully handling exceptions

Slide 150

Slide 150 text

Component based fronted

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

No content

Slide 153

Slide 153 text

No content

Slide 154

Slide 154 text

No content

Slide 155

Slide 155 text

No content

Slide 156

Slide 156 text

No content

Slide 157

Slide 157 text

No content

Slide 158

Slide 158 text

Degrading Functionality

Slide 159

Slide 159 text

Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution

Slide 160

Slide 160 text

Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu EXCEPTION Institution

Slide 161

Slide 161 text

Test it

Slide 162

Slide 162 text

http://techblog.netflix.com/2014/09/introducing-chaos-engineering.html

Slide 163

Slide 163 text

Scalability

Slide 164

Slide 164 text

How do I handle traffic spikes?

Slide 165

Slide 165 text

Elasticity

Slide 166

Slide 166 text

Service A Service B 200 OK Circuit Breaker

Slide 167

Slide 167 text

Service A Service B Circuit Breaker Service C Circuit Breaker

Slide 168

Slide 168 text

Throttling

Slide 169

Slide 169 text

Service A Service B Circuit Breaker Service C Circuit Breaker Only allow xx% of calls

Slide 170

Slide 170 text

No content

Slide 171

Slide 171 text

Priority

Slide 172

Slide 172 text

Service A Service B Circuit Breaker Service C Circuit Breaker 100% of calls 10% of calls

Slide 173

Slide 173 text

Service A Service B Circuit Breaker Service C Circuit Breaker 100% of calls wait until everything is ok

Slide 174

Slide 174 text

Elasticity

Slide 175

Slide 175 text

Service A Service B Circuit Breaker Service C Circuit Breaker Service B

Slide 176

Slide 176 text

Complete Solutions

Slide 177

Slide 177 text

No content

Slide 178

Slide 178 text

https://mesosphere.github.io/marathon/

Slide 179

Slide 179 text

https://www.flickr.com/photos/darkdwarf/19701555974/

Slide 180

Slide 180 text

http://twitter.com/BastianHofmann http://lanyrd.com/people/BastianHofmann http://speakerdeck.com/u/bastianhofmann [email protected]