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

No content

Slide 4

Slide 4 text

Microservices

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Service Oriented Architecture

Slide 7

Slide 7 text

Monolith

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Benefits

Slide 10

Slide 10 text

Problems

Slide 11

Slide 11 text

Problems

Slide 12

Slide 12 text

Challenges

Slide 13

Slide 13 text

Microservice

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Cloud Solutions

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Using the cloud is not always possible

Slide 18

Slide 18 text

… or even desirable

Slide 19

Slide 19 text

Doing it yourself creates challenges

Slide 20

Slide 20 text

Performance

Slide 21

Slide 21 text

Latency

Slide 22

Slide 22 text

Stability

Slide 23

Slide 23 text

Reliability

Slide 24

Slide 24 text

Transparency

Slide 25

Slide 25 text

Learning Curves

Slide 26

Slide 26 text

Code Reuse

Slide 27

Slide 27 text

Maintenance

Slide 28

Slide 28 text

Elastic Scaling?

Slide 29

Slide 29 text

How can we solve them

Slide 30

Slide 30 text

A lot of this is also useful for monoliths

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

•A big monolith •Multiple small to medium sized services •Lots of shared libraries •Tools and utilities •Hadoop jobs •Flink jobs •Server Provisioning

Slide 34

Slide 34 text

•PHP •Javascript •Java •Scala •Bash •Python •Puppet •Ruby •Go

Slide 35

Slide 35 text

•Nginx •PHP-FPM •Glassfish •Jetty •Dropwizard •haproxy •PostgreSQL •MongoDB •Memcached •Infinispan •Solr •Zookeeper •Elasticsearch •Logstash •Kibana •Graphite •StatsD •RabbitMQ •Hortonworks Data Platform •HBase •Hive •Consul •Vault •CheckMK •Azkaban •ActiveMQ •Apache HTTPD •Docker •Kafka

Slide 36

Slide 36 text

Several hundred servers

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Questions? Ask

Slide 39

Slide 39 text

http://speakerdeck.com/u/bastianhofmann

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

Deployment

Slide 42

Slide 42 text

How to get the services on our servers?

Slide 43

Slide 43 text

Diverse technology stacks

Slide 44

Slide 44 text

The same for every service

Slide 45

Slide 45 text

One Click Deployment

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Automation

Slide 48

Slide 48 text

Build/Test/Release pipeline

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

Base boxes

Slide 52

Slide 52 text

Services installed in a sandbox

Slide 53

Slide 53 text

https://www.docker.com/

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

Docker & PHP - development and deployment Szymon Skórczyński Thursday 16:00

Slide 56

Slide 56 text

Availability

Slide 57

Slide 57 text

Zero Downtime Deployments

Slide 58

Slide 58 text

Server Server Server Server

Slide 59

Slide 59 text

Stability

Slide 60

Slide 60 text

Canary environments

Slide 61

Slide 61 text

Server Server Server Server

Slide 62

Slide 62 text

Fast rollbacks

Slide 63

Slide 63 text

•Ansible •Capistrano •Saltstack •Custom •….

Slide 64

Slide 64 text

Running the service

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

Diverse technology stacks

Slide 67

Slide 67 text

The same for every service

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

Releases

Slide 70

Slide 70 text

How to synchronize changes over services?

Slide 71

Slide 71 text

API Versioning

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

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

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

Feature Flags

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

Shared database

Slide 81

Slide 81 text

Headers

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

Configuration Management

Slide 84

Slide 84 text

How do I synchronize configuration over services?

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

Config file on disk

Slide 87

Slide 87 text

Duplication

Slide 88

Slide 88 text

Inconsistencies

Slide 89

Slide 89 text

Consul https://www.consul.io/

Slide 90

Slide 90 text

•Consul •Zookeeper •etcd •…

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

Key/Value Store

Slide 94

Slide 94 text

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

Slide 95

Slide 95 text

Credentials

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

https://www.vaultproject.io/

Slide 98

Slide 98 text

Cycling of credentials

Slide 99

Slide 99 text

Service Discovery

Slide 100

Slide 100 text

How does one service know where another service is?

Slide 101

Slide 101 text

Hostname + Port

Slide 102

Slide 102 text

Server Service A Server Service B Service C Service C

Slide 103

Slide 103 text

Configuration

Slide 104

Slide 104 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 105

Slide 105 text

Consul https://www.consul.io/

Slide 106

Slide 106 text

Load balancing?

Slide 107

Slide 107 text

Round robin in the client

Slide 108

Slide 108 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 109

Slide 109 text

Service/Server down?

Slide 110

Slide 110 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 111

Slide 111 text

Health checks

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

Central load balancer

Slide 114

Slide 114 text

Server Service A Server Service B Service C Service C Load balancer

Slide 115

Slide 115 text

Scalability?

Slide 116

Slide 116 text

Elasticity?

Slide 117

Slide 117 text

Consul https://www.consul.io/

Slide 118

Slide 118 text

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

Slide 119

Slide 119 text

Consul for Service Discovery

Slide 120

Slide 120 text

Consul Agent Server Service A Registration Health check

Slide 121

Slide 121 text

Consul API

Slide 122

Slide 122 text

DNS

Slide 123

Slide 123 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 124

Slide 124 text

Consul-Template https://github.com/hashicorp/consul-template

Slide 125

Slide 125 text

Server Service A Server Service B Service C Service C Load balancer Consul Template

Slide 126

Slide 126 text

Single Point of Failure

Slide 127

Slide 127 text

Server Service A Server Service B Service C Service C Load balancer Consul Template Load balancer Consul Template

Slide 128

Slide 128 text

Monitoring

Slide 129

Slide 129 text

How are my services behaving?

Slide 130

Slide 130 text

Central Log Management

Slide 131

Slide 131 text

Elasticsearch
 Kibana Logstash

Slide 132

Slide 132 text

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

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

Tracing IDs

Slide 135

Slide 135 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 136

Slide 136 text

X-Trace-Id: bbr8ehb984tbab894

Slide 137

Slide 137 text

https://www.loggly.com/

Slide 138

Slide 138 text

https://getsentry.com/

Slide 139

Slide 139 text

Measure everything

Slide 140

Slide 140 text

Server metrics

Slide 141

Slide 141 text

Application metrics

Slide 142

Slide 142 text

StatsD + Graphite

Slide 143

Slide 143 text

webserver webserver webserver statsd statsd statsd graphite aggregated UPD message statsd

Slide 144

Slide 144 text

https://www.librato.com

Slide 145

Slide 145 text

http://www.soasta.com/

Slide 146

Slide 146 text

Profiling

Slide 147

Slide 147 text

XHProf

Slide 148

Slide 148 text

No content

Slide 149

Slide 149 text

No content

Slide 150

Slide 150 text

Use it in production for a subset of requests

Slide 151

Slide 151 text

newrelic.com

Slide 152

Slide 152 text

https://tidways.io/

Slide 153

Slide 153 text

https://blackfire.io/

Slide 154

Slide 154 text

Toolbars

Slide 155

Slide 155 text

No content

Slide 156

Slide 156 text

No content

Slide 157

Slide 157 text

Make it accessible

Slide 158

Slide 158 text

Aggregation

Slide 159

Slide 159 text

Handling failures

Slide 160

Slide 160 text

What do I do when something breaks?

Slide 161

Slide 161 text

Errors happen

Slide 162

Slide 162 text

Detecting regressions

Slide 163

Slide 163 text

Server outages

Slide 164

Slide 164 text

Database overloads

Slide 165

Slide 165 text

Bugs

Slide 166

Slide 166 text

Service A Service B 200 OK

Slide 167

Slide 167 text

Service A Service B 5xx

Slide 168

Slide 168 text

Service A Service B Timeout

Slide 169

Slide 169 text

Circuit Breakers

Slide 170

Slide 170 text

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

Slide 171

Slide 171 text

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

Slide 172

Slide 172 text

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

Slide 173

Slide 173 text

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

Slide 174

Slide 174 text

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

Slide 175

Slide 175 text

https://github.com/Netflix/Hystrix

Slide 176

Slide 176 text

https://github.com/odesk/phystrix

Slide 177

Slide 177 text

Phystrix does not scale well

Slide 178

Slide 178 text

Gracefully handling exceptions

Slide 179

Slide 179 text

Component based fronted

Slide 180

Slide 180 text

No content

Slide 181

Slide 181 text

No content

Slide 182

Slide 182 text

No content

Slide 183

Slide 183 text

No content

Slide 184

Slide 184 text

No content

Slide 185

Slide 185 text

No content

Slide 186

Slide 186 text

No content

Slide 187

Slide 187 text

Degrading Functionality

Slide 188

Slide 188 text

Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution

Slide 189

Slide 189 text

Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu EXCEPTION Institution

Slide 190

Slide 190 text

Test it

Slide 191

Slide 191 text

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

Slide 192

Slide 192 text

Scalability

Slide 193

Slide 193 text

How do I handle traffic spikes?

Slide 194

Slide 194 text

Elasticity

Slide 195

Slide 195 text

Service A Service B 200 OK Circuit Breaker

Slide 196

Slide 196 text

Service A Service B Circuit Breaker Service C Circuit Breaker

Slide 197

Slide 197 text

Throttling

Slide 198

Slide 198 text

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

Slide 199

Slide 199 text

No content

Slide 200

Slide 200 text

Priority

Slide 201

Slide 201 text

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

Slide 202

Slide 202 text

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

Slide 203

Slide 203 text

Elasticity

Slide 204

Slide 204 text

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

Slide 205

Slide 205 text

Development Environment

Slide 206

Slide 206 text

How do I enusre a productive dev environment?

Slide 207

Slide 207 text

Diverse technology stacks

Slide 208

Slide 208 text

Diverse environments

Slide 209

Slide 209 text

https://www.docker.com/

Slide 210

Slide 210 text

Central DEV Production Near Production Nightly DEV

Slide 211

Slide 211 text

Large scale refactorings

Slide 212

Slide 212 text

Monorepo

Slide 213

Slide 213 text

https://qafoo.com/talks/15_08_froscon_monorepos.pdf

Slide 214

Slide 214 text

Global Code Search

Slide 215

Slide 215 text

https://github.com/etsy/hound

Slide 216

Slide 216 text

Complete Solutions

Slide 217

Slide 217 text

No content

Slide 218

Slide 218 text

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

Slide 219

Slide 219 text

Kubernetes at the Home Office Billie Thompson Friday 11:30

Slide 220

Slide 220 text

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

Slide 221

Slide 221 text

https://joind.in/talk/38117

Slide 222

Slide 222 text

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