Microservices: from dream to reality in an forty five minutes

A presentation at Jfokus 2016 in February 2016 in Stockholm, Sweden by Holly Cummins

Slide 1

Slide 1

IBM _ Java EE Microservices by Example: from Raspberry Pis to the Cloud Holly Cummins September 2016 @holly_cummins 1

Slide 2

Slide 2

http://ibm.biz/bluemixgaragelondon http://ibm.biz/bluemixgaragelondon http://ibm.biz/bluemixgaragelondon @holly_cummins @holly_cummins

Slide 3

Slide 3

http://ibm.biz/bluemixgaragelondon http://ibm.biz/bluemixgaragelondon http://ibm.biz/bluemixgaragelondon @holly_cummins @holly_cummins

Slide 4

Slide 4

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 5

Slide 5

Microservices make your colleagues less annoying. Microservices are guaranteed bug-free. Microservices: Good design built-in! Kittens love microservices. Microservices vaporize unclean code. Microservices. The best thing since sliced bread. Every microservice comes with a free puppy. http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 6

Slide 6

Wait. What problem are we actually trying to solve? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 7

Slide 7

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 8

Slide 8

Monolithic Modularity http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 9

Slide 9

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 10

Slide 10

Monolithic Scaling http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 11

Slide 11

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 12

Slide 12

Monolithic Failing http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 13

Slide 13

Monolithic Failing http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 14

Slide 14

Monolithic Failing http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 15

Slide 15

Monolithic Failing http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 16

Slide 16

Monolithic Failure http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 17

Slide 17

Monolithic Update http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 18

Slide 18

Monolithic Update http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 19

Slide 19

Monolithic Update http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 20

Slide 20

Monolithic Update http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 21

Slide 21

Monolithic Update http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 22

Slide 22

Monolithic Update http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 23

Slide 23

Monolithic Update http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 24

Slide 24

Monolithic Redesign http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 25

Slide 25

Monolithic Redesign http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 26

Slide 26

Monolithic Redesign (Revolution required.) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 27

Slide 27

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 28

Slide 28

Microservice Modularity http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 29

Slide 29

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 30

Slide 30

Microservice Interactions http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 31

Slide 31

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 32

Slide 32

Microservices Scaled http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 33

Slide 33

Microservices Scaled http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 34

Slide 34

Microservices Scaled http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 35

Slide 35

Microservices Scaled http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 36

Slide 36

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 37

Slide 37

Microservices Redesign http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 38

Slide 38

Microservices Redesign (Evolution reduces risk.) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 39

Slide 39

All good demos involve cats. … http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 40

Slide 40

All good demos involve cats. http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 41

Slide 41

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 42

Slide 42

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 43

Slide 43

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 44

Slide 44

… All good demos involve cats and raspberry pis. http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 45

Slide 45

All good demos involve cats and raspberry pis. http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 46

Slide 46

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 47

Slide 47

Datacentre in a handbag http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 48

Slide 48

What, no Docker? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 49

Slide 49

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 50

Slide 50

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 51

Slide 51

Cat-astrophe http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 52

Slide 52

Powered by WebSphere Liberty … of course http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 53

Slide 53

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 54

Slide 54

http://raspberrypi.local:8080/ http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 55

Slide 55

What happens if things fail? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 56

Slide 56

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 57

Slide 57

Refactoring your way to the microservices dream http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 58

Slide 58

http://github.com/holly-cummins/catastrophe-microservices Slice it up! http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 59

Slide 59

http://github.com/holly-cummins/catastrophe-microservices Slice it up! http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 60

Slide 60

http://github.com/holly-cummins/catastrophe-microservices HTTP HTTP HT TP Slice it up! http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 61

Slide 61

http://github.com/holly-cummins/catastrophe-microservices HTTP HTTP HT TP Peel it off. http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 62

Slide 62

Should we decompose the front-end? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 63

Slide 63

• Probably not. Should we decompose the front-end? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 64

Slide 64

• Probably not. • Single Origin headaches Should we decompose the front-end? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 65

Slide 65

• Probably not. • Single Origin headaches • Page composition headaches Should we decompose the front-end? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 66

Slide 66

REST REST http://ibm.biz/bluemixgaragelondon RE ST @holly_cummins

Slide 67

Slide 67

Message REST http://ibm.biz/bluemixgaragelondon RE ST @holly_cummins

Slide 68

Slide 68

REST REST http://ibm.biz/bluemixgaragelondon RE ST @holly_cummins

Slide 69

Slide 69

• Synchronous is convenient • Asynchronous has scalability advantages • Consider reactive architectures REST != synchronous (well, not necessarily) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 70

Slide 70

How hard the refactoring is depends on where you started http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 71

Slide 71

@ApplicationScoped public class CatRepository { public Set<Cat> getAllCats() { Exposing a service in a monolith http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 72

Slide 72

@Path(“cat”) public class CatRepository { @Path(“allcats”) @Produces(MediaType.APPLICATION_JSON) @GET public Set<Cat> getAllCats() { … Exposing a microservice http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 73

Slide 73

@Path(“cat”) public class CatRepository { @Path(“allcats”) @Produces(MediaType.APPLICATION_JSON) @GET public Set<Cat> getAllCats() { … JAXRS=magic http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 74

Slide 74

@Path(“allcats”) @Asynchronous @GET public void getAllCats(@Suspended final AsyncResponse response) { // stuff response.resume(stuff) Go asynchronous for scalability http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 75

Slide 75

@Path(“allcats”) @Asynchronous @GET public void getAllCats(@Suspended final AsyncResponse response) { // stuff response.resume(stuff) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 76

Slide 76

@Inject CatRepository catRepo; … Set<Cat> cats = catRepo.getAllCats(); Consuming a service in a monolith http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 77

Slide 77

Client client = ClientBuilder.newClient(); WebTarget target = client.target(“http://localhost:9080”) .path(“/rest/cat/cats”); Set<Cat> cats = target.request(MediaType.APPLICATION_JSON) .get(new GenericType<>(Set.class)); Consuming a REST microservice http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 78

Slide 78

Don’t forget to slice up the database too http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 79

Slide 79

REST REST http://ibm.biz/bluemixgaragelondon RE ST @holly_cummins

Slide 80

Slide 80

REST REST http://ibm.biz/bluemixgaragelondon RE ST @holly_cummins

Slide 81

Slide 81

Are we done? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 82

Slide 82

Don’t forget to slice up the data model too http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 83

Slide 83

Don’t do what I did :) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 84

Slide 84

compile project(“:catastrophe-interfaces”) Don’t do what I did :) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 85

Slide 85

compile project(“:catastrophe-interfaces”) mymac:~ holly$ git submodule add ../catastrophe-interfaces Don’t do what I did :) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 86

Slide 86

An anti-pattern compile project(“:catastrophe-interfaces”) mymac:~ holly$ git submodule add ../catastrophe-interfaces Don’t do what I did :) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 87

Slide 87

An anti-pattern compile project(“:catastrophe-interfaces”) mymac:~ holly$ git submodule add ../catastrophe-interfaces Don’t do what I did :) http://ibm.biz/bluemixgaragelondon This is a code-layout description, not a functional one @holly_cummins

Slide 88

Slide 88

Duplication of code Decoupling The tradeoff http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 89

Slide 89

Duplication of code Compile-time independence The tradeoff http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 90

Slide 90

If this tradeoff is hurting, your domain model is too coupled. http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 91

Slide 91

If this tradeoff is hurting, your domain model is too coupled. Have your microservices got the right granularity? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 92

Slide 92

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 93

Slide 93

“Does this domain model make sense?” http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 94

Slide 94

“Does this domain model make sense?” “Not really.” http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 95

Slide 95

“Does this domain model make sense?” “Not really.” “Does decomposing a system of this size into microservices actually make sense?” http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 96

Slide 96

“Does this domain model make sense?” “Not really.” “Does decomposing a system of this size into microservices actually make sense?” “Well, no.” http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 97

Slide 97

“Does this domain model make sense?” “Not really.” “Does decomposing a system of this size into microservices actually make sense?” “Well, no.” The right granularity may be “monolith.” http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 98

Slide 98

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 99

Slide 99

HTTP HTTP http://ibm.biz/bluemixgaragelondon HT TP @holly_cummins

Slide 100

Slide 100

HTTP Remember the distributed computing fallacies. http://ibm.biz/bluemixgaragelondon HTTP HT TP @holly_cummins

Slide 101

Slide 101

HTTP Really Remember the distributed computing fallacies. http://ibm.biz/bluemixgaragelondon HTTP HT TP @holly_cummins

Slide 102

Slide 102

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 103

Slide 103

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 104

Slide 104

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 105

Slide 105

Complexity http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 106

Slide 106

WebTarget cat = client.target(“http://raspberrypiclearcase.local”); WebTarget auth = client.target(“http://raspberrypi2.local”); WebTarget scoring = client.target(“http://raspberrypiredcase.local”);

Slide 107

Slide 107

WebTarget cat = client.target(“http://raspberrypiclearcase.local”); WebTarget auth = client.target(“http://raspberrypi2.local”); WebTarget scoring = client.target(“http://raspberrypiredcase.local”); This is robust code, right?

Slide 108

Slide 108

ip add r ess: ? .?.?.? ip address: ?.?.?.? ip address: ?.?.?.? ip add r ess: ? .?.?.? ip address: ?.?.?.? Network topology http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 109

Slide 109

ip add r ess: s pecial ip address: bespoke ip address: precious ip add r ess: lo vely ip address: fave Network topology http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 110

Slide 110

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 111

Slide 111

Disposability http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 112

Slide 112

Disposability Say no to snowflake servers http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 113

Slide 113

Disposability Say no to snowflake servers http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 114

Slide 114

ip add r ess: s pecial ip address: bespoke ip address: precious ip add r ess: lo vely ip address: fave Scaling http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 115

Slide 115

ip add r ess: s pecial ip address: bespoke ip address: precious ip add r ess: lo vely ip address: fave Scaling http://ibm.biz/bluemixgaragelondon ip add r ess: lo nely @holly_cummins

Slide 116

Slide 116

ip add r ess: s pecial ip address: bespoke ip address: precious ip add r ess: lo vely ip address: fave Scaling http://ibm.biz/bluemixgaragelondon ip add r ess: lo nely @holly_cummins

Slide 117

Slide 117

• Kubernetes • Apache Zookeeper + Curator • Eureka • etcd • Consul • Bluemix Service Discovery Service discovery http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 118

Slide 118

• Docker Kubernetes • Apache Zookeeper + Curator • Eureka • etcd • Consul • Bluemix Service Discovery Service discovery http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 119

Slide 119

• Docker Kubernetes • Apache Zookeeper + Curator Java • Eureka • etcd • Consul • Bluemix Service Discovery Service discovery http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 120

Slide 120

• Docker Kubernetes • Apache Zookeeper + Curator Java • EurekaAWSSoftLayer • etcd • Consul • Bluemix Service Discovery Service discovery http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 121

Slide 121

• Docker Kubernetes • Apache Zookeeper + Curator Java • EurekaAWSSoftLayer • etcd CoreOS • Consul • Bluemix Service Discovery Service discovery http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 122

Slide 122

• Docker Kubernetes • Apache Zookeeper + Curator Java • EurekaAWSSoftLayer • etcd CoreOS • ConsulDNS HTTP Java • Bluemix Service Discovery Service discovery http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 123

Slide 123

• Docker Kubernetes • Apache Zookeeper + Curator Java • EurekaAWSSoftLayer • etcd CoreOS • ConsulDNS HTTP Java • Bluemix Service Discovery Bluemix :) Service discovery http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 124

Slide 124

Cat-astrophe http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 125

Slide 125

REST REST RE ST Cat-astrophe http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 126

Slide 126

Consul REST REST RE ST Cat-astrophe http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 127

Slide 127

Consul Discovery REST Dis cov Discovery REST ery RE ST Cat-astrophe http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 128

Slide 128

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 129

Slide 129

<featureManager> <feature>jaxrs-1.0</feature> http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 130

Slide 130

Server configuration <featureManager> <feature>jaxrs-1.0</feature> http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 131

Slide 131

Server configuration <featureManager> <feature>jaxrs-1.0</feature> <feature>usr:discovery</feature> … <consul server=”catastrophe.consul” /> http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 132

Slide 132

Server configuration <featureManager> <feature>jaxrs-1.0</feature> <feature>usr:discovery</feature> … Wouldn’t this be nice? <consul server=”catastrophe.consul” /> http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 133

Slide 133

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 134

Slide 134

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 135

Slide 135

Liberty extension (“user feature”) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 136

Slide 136

Liberty extension (“user feature”) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 137

Slide 137

Autopublishes REST endpoints Liberty extension (“user feature”) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 138

Slide 138

Autopublishes REST endpoints I WebSphere Liberty extensibility Liberty https://github.com/WASdev/sample.consulservicediscovery extension (“user feature”) http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 139

Slide 139

“Type a quote here.” –Johnny Appleseed Consul view of the Catastrophe services http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 140

Slide 140

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 141

Slide 141

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 142

Slide 142

You need DevOps http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 143

Slide 143

An SD card is not devops :) You need 100% automation http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 144

Slide 144

“Type a quote here.” –Johnny Appleseed http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 145

Slide 145

“Type a quote here.” –Johnny Appleseed http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 146

Slide 146

http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 147

Slide 147

http://catastrophe-web.mybluemix.net/

Slide 148

Slide 148

Who can draw the best cat? http://catastrophe-web.mybluemix.net/ (I have THINK hats for the highest scores!)

Slide 149

Slide 149

What if I want to run on both pis and the cloud?

Slide 150

Slide 150

What if I want to run on both pis and the cloud? You need Hybrid Cloud!

Slide 151

Slide 151

What if I want to run on both pis and the cloud? “Type a quote here.” –Johnny Appleseed You need Hybrid Cloud!

Slide 152

Slide 152

Slide 153

Slide 153

Slide 154

Slide 154

Are we done? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 155

Slide 155

Consul Discovery REST Dis cov Discovery REST ery RE ST Are we done? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 156

Slide 156

Have we tested it? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 157

Slide 157

How de we handle failures? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 158

Slide 158

Are we actually decoupled? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 159

Slide 159

Are we actually decoupled? http://ibm.biz/bluemixgaragelondon @holly_cummins

Slide 160

Slide 160

So remember… http://ibm.biz/bluemixgaragelondon • Decoupling is more than just HTTP communication • Some of your microservices will fail. Be resilient. • I ♥ WebSphere Liberty • JEE is great for microservices (especially with microprofile) • Hybrid cloud makes a lot of cool stuff possible @holly_cummins

Slide 161

Slide 161

IBM _ 74 Thank You! http://ibm.biz/bluemixgaragelondon http://github.com/holly-cummins/catastrophe-microservices Holly Cummins | @holly_cummins