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

Stricter separation of concerns

Slide 11

Slide 11 text

Diverse technology stacks

Slide 12

Slide 12 text

Things that you don’t want to do in language X

Slide 13

Slide 13 text

Problems

Slide 14

Slide 14 text

Problems

Slide 15

Slide 15 text

Challenges

Slide 16

Slide 16 text

Performance

Slide 17

Slide 17 text

Latency

Slide 18

Slide 18 text

Stability

Slide 19

Slide 19 text

Reliability

Slide 20

Slide 20 text

Transparency

Slide 21

Slide 21 text

Monitoring

Slide 22

Slide 22 text

Learning Curves

Slide 23

Slide 23 text

Code Reuse

Slide 24

Slide 24 text

Maintenance

Slide 25

Slide 25 text

Elastic Scaling?

Slide 26

Slide 26 text

Cloud Solutions

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Using the cloud is not always possible

Slide 29

Slide 29 text

… or even desirable

Slide 30

Slide 30 text

Only solve some of the problems

Slide 31

Slide 31 text

How can we solve them

Slide 32

Slide 32 text

•Deploying •Running •Releasing •Configuring •Discovering •Monitoring •Error Handling •Scaling Agenda

Slide 33

Slide 33 text

A lot of this is also useful for monoliths

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Our use case

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Deployment

Slide 39

Slide 39 text

How to get the services on our servers?

Slide 40

Slide 40 text

Diverse technology stacks

Slide 41

Slide 41 text

The same for every service

Slide 42

Slide 42 text

One Click Deployment

Slide 43

Slide 43 text

•Ansible •Capistrano •Saltstack •Custom •….

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

CI

Slide 46

Slide 46 text

Automation

Slide 47

Slide 47 text

Build/Test/Release pipeline

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

Availability

Slide 50

Slide 50 text

Zero Downtime Deployments

Slide 51

Slide 51 text

Server Server Server Server

Slide 52

Slide 52 text

Server Server Server Server

Slide 53

Slide 53 text

Server Server Server Server

Slide 54

Slide 54 text

Server Server Server Server

Slide 55

Slide 55 text

Server Server Server Server

Slide 56

Slide 56 text

Server Server Server Server

Slide 57

Slide 57 text

Stability

Slide 58

Slide 58 text

Canary environments

Slide 59

Slide 59 text

Server Server Server Server

Slide 60

Slide 60 text

Server Server Server Server Test with low amount of traffic

Slide 61

Slide 61 text

Fast deployments

Slide 62

Slide 62 text

Fast rollbacks

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

Different libraries, packages, web servers, configurations, versions

Slide 65

Slide 65 text

Base boxes

Slide 66

Slide 66 text

Services installed in a sandbox

Slide 67

Slide 67 text

https://www.docker.com/

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

Running the service

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

Diverse technology stacks

Slide 72

Slide 72 text

The same for every service

Slide 73

Slide 73 text

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

Slide 74

Slide 74 text

Releases

Slide 75

Slide 75 text

How to synchronize changes over services?

Slide 76

Slide 76 text

APIs

Slide 77

Slide 77 text

API Versioning

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

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

Slide 80

Slide 80 text

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

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

No backwards compatibility breaks

Slide 83

Slide 83 text

Feature Flags

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

Every service has its own implementation

Slide 88

Slide 88 text

Shared database

Slide 89

Slide 89 text

Headers

Slide 90

Slide 90 text

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

Slide 91

Slide 91 text

Configuration Management

Slide 92

Slide 92 text

How do I synchronize configuration over services?

Slide 93

Slide 93 text

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

Slide 94

Slide 94 text

Config file on disk

Slide 95

Slide 95 text

Duplication

Slide 96

Slide 96 text

Inconsistencies

Slide 97

Slide 97 text

Consul https://www.consul.io/

Slide 98

Slide 98 text

•Consul •Zookeeper •etcd •…

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

Key/Value Store

Slide 101

Slide 101 text

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

Slide 102

Slide 102 text

Credentials

Slide 103

Slide 103 text

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

Slide 104

Slide 104 text

https://www.vaultproject.io/

Slide 105

Slide 105 text

Cycling of credentials

Slide 106

Slide 106 text

Service Discovery

Slide 107

Slide 107 text

How does one service know where another service is?

Slide 108

Slide 108 text

Hostname + Port

Slide 109

Slide 109 text

Server Service A Server Service B Service C Service C

Slide 110

Slide 110 text

Configuration

Slide 111

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

Slide 112 text

Consul https://www.consul.io/

Slide 113

Slide 113 text

Load balancing?

Slide 114

Slide 114 text

Round robin in the client

Slide 115

Slide 115 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 116

Slide 116 text

Service/Server down?

Slide 117

Slide 117 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 118

Slide 118 text

Health checks

Slide 119

Slide 119 text

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

Slide 120

Slide 120 text

Central load balancer

Slide 121

Slide 121 text

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

Slide 122

Slide 122 text

Scalability?

Slide 123

Slide 123 text

Load balancer

Slide 124

Slide 124 text

Elasticity?

Slide 125

Slide 125 text

Load balancer

Slide 126

Slide 126 text

Consul https://www.consul.io/

Slide 127

Slide 127 text

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

Slide 128

Slide 128 text

Consul for Service Discovery

Slide 129

Slide 129 text

Consul Agent Server Service A Registration Health check

Slide 130

Slide 130 text

Consul API

Slide 131

Slide 131 text

DNS

Slide 132

Slide 132 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 133

Slide 133 text

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

Slide 134

Slide 134 text

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

Slide 135

Slide 135 text

Single Point of Failure

Slide 136

Slide 136 text

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

Slide 137

Slide 137 text

Load balance directly in the client

Slide 138

Slide 138 text

https://github.com/eBay/fabio

Slide 139

Slide 139 text

Monitoring

Slide 140

Slide 140 text

How are my services behaving?

Slide 141

Slide 141 text

No content

Slide 142

Slide 142 text

Central Log Management

Slide 143

Slide 143 text

Elasticsearch
 Kibana Logstash

Slide 144

Slide 144 text

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

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

Tracing IDs

Slide 147

Slide 147 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 148

Slide 148 text

X-Trace-Id: bbr8ehb984tbab894

Slide 149

Slide 149 text

https://www.loggly.com/

Slide 150

Slide 150 text

https://getsentry.com/

Slide 151

Slide 151 text

Measure everything

Slide 152

Slide 152 text

Server metrics

Slide 153

Slide 153 text

Application metrics

Slide 154

Slide 154 text

StatsD + Graphite

Slide 155

Slide 155 text

webserver webserver webserver statsd statsd statsd graphite aggregated UPD message statsd

Slide 156

Slide 156 text

https://www.librato.com

Slide 157

Slide 157 text

http://www.soasta.com/

Slide 158

Slide 158 text

http://www.monitor.us/

Slide 159

Slide 159 text

Profiling

Slide 160

Slide 160 text

newrelic.com

Slide 161

Slide 161 text

Handling failures

Slide 162

Slide 162 text

What do I do when something breaks?

Slide 163

Slide 163 text

Errors happen

Slide 164

Slide 164 text

Detecting regressions

Slide 165

Slide 165 text

Server outages

Slide 166

Slide 166 text

Database overloads

Slide 167

Slide 167 text

Bugs

Slide 168

Slide 168 text

Service A Service B 200 OK

Slide 169

Slide 169 text

Service A Service B 5xx

Slide 170

Slide 170 text

Service A Service B Timeout

Slide 171

Slide 171 text

Circuit Breakers

Slide 172

Slide 172 text

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

Slide 173

Slide 173 text

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

Slide 174

Slide 174 text

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

Slide 175

Slide 175 text

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

Slide 176

Slide 176 text

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

Slide 177

Slide 177 text

https://github.com/Netflix/Hystrix

Slide 178

Slide 178 text

https://github.com/odesk/phystrix

Slide 179

Slide 179 text

Gracefully handling exceptions

Slide 180

Slide 180 text

Component based fronted

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

No content

Slide 188

Slide 188 text

Degrading Functionality

Slide 189

Slide 189 text

Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution

Slide 190

Slide 190 text

Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu EXCEPTION Institution

Slide 191

Slide 191 text

Profile Publications Publication Publication Publication LeftColumn Image Menu Institution

Slide 192

Slide 192 text

Test it

Slide 193

Slide 193 text

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

Slide 194

Slide 194 text

Scalability

Slide 195

Slide 195 text

How do I handle traffic spikes?

Slide 196

Slide 196 text

Elasticity

Slide 197

Slide 197 text

Service A Service B 200 OK Circuit Breaker

Slide 198

Slide 198 text

Service A Service B Circuit Breaker Service C Circuit Breaker Timeouts

Slide 199

Slide 199 text

Service A Service B Circuit Breaker Service C Circuit Breaker Timeouts

Slide 200

Slide 200 text

Throttling

Slide 201

Slide 201 text

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

Slide 202

Slide 202 text

No content

Slide 203

Slide 203 text

Priority

Slide 204

Slide 204 text

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

Slide 205

Slide 205 text

Elasticity

Slide 206

Slide 206 text

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

Slide 207

Slide 207 text

Complete Solutions

Slide 208

Slide 208 text

No content

Slide 209

Slide 209 text

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

Slide 210

Slide 210 text

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

Slide 211

Slide 211 text

http://speakerdeck.com/u/bastianhofmann

Slide 212

Slide 212 text

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