Date post: | 20-Jan-2017 |
Category: |
Software |
Upload: | holly-cummins |
View: | 1,003 times |
Download: | 0 times |
IBM _ 1
Java EE Microservices by Example: from Raspberry Pis to the Cloud
Holly Cummins September 2016 @holly_cummins
@holly_cumminshttp://ibm.biz/bluemixgaragelondon @holly_cumminshttp://ibm.biz/bluemixgaragelondon
http://ibm.biz/bluemixgaragelondon
@holly_cumminshttp://ibm.biz/bluemixgaragelondon @holly_cumminshttp://ibm.biz/bluemixgaragelondon
http://ibm.biz/bluemixgaragelondon
Microservices. The best thing since sliced bread.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Microservices: Good design built-in!
Every microservice comes with a free puppy.
Kittens love microservices. Microservices vaporize
unclean code.
Microservices make your colleagues less annoying.
Microservices are guaranteed bug-free.
Wait. What problem are we actually trying to solve?
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Modularity
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Scaling
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Failing
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Failing
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Failing
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Failing
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Failure
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Update
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Update
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Update
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Update
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Update
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Update
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Update
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Redesign
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Redesign
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Monolithic Redesign
(Revolution required.)
Microservice Modularity
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Microservice Interactions
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Microservices Scaled
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Microservices Scaled
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Microservices Scaled
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Microservices Scaled
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Microservices Redesign
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Microservices Redesign
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
(Evolution reduces risk.)
All good demos involve cats.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
…
All good demos involve cats.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
All good demos involve cats and raspberry pis.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
…
All good demos involve cats and raspberry pis.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Datacentre in a handbag
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
What, no Docker?
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Powered by WebSphere Liberty …
of course
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
http://raspberrypi.local:8080/
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
What happens if things fail?
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Refactoring your way to the microservices dream
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Slice it up!
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
http://github.com/holly-cummins/catastrophe-microservices
Slice it up!
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
http://github.com/holly-cummins/catastrophe-microservices
Slice it up!
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
HTTP HTTP
HTTP
http://github.com/holly-cummins/catastrophe-microservices
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
HTTP HTTP
HTTP
Peel it off.
http://github.com/holly-cummins/catastrophe-microservices
Should we decompose the front-end?
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Should we decompose the front-end?
• Probably not.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Should we decompose the front-end?
• Probably not.
• Single Origin headaches
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Should we decompose the front-end?
• Probably not.
• Single Origin headaches
• Page composition headaches
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
REST REST
Message
REST != synchronous (well, not necessarily)
• Synchronous is convenient
• Asynchronous has scalability advantages
• Consider reactive architectures
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
How hard the refactoring is depends on where you started
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Exposing a service in a monolith
@ApplicationScopedpublic class CatRepository {
public Set<Cat> getAllCats() {
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Exposing a microservice
@Path("cat")public class CatRepository {
@Path("allcats")@Produces(MediaType.APPLICATION_JSON)@GETpublic Set<Cat> getAllCats() {
…
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
@Path("cat")public class CatRepository {
@Path("allcats")@Produces(MediaType.APPLICATION_JSON)@GETpublic Set<Cat> getAllCats() {
…
JAXRS=magic
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Go asynchronous for scalability
@Path("allcats")@Asynchronous@GETpublic void getAllCats(@Suspended final AsyncResponse response) {
// stuff response.resume(stuff)
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
@Path("allcats")@Asynchronous@GETpublic void getAllCats(@Suspended final AsyncResponse response) {
// stuff response.resume(stuff)
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Consuming a service in a monolith
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
@InjectCatRepository catRepo;
...
Set<Cat> cats = catRepo.getAllCats();
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
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Don’t forget to slice up the database too
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Don’t forget to slice up the data model too
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Don’t do what I did :)
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
compile project(":catastrophe-interfaces")
Don’t do what I did :)
mymac:~ holly$ git submodule add ../catastrophe-interfaces
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
compile project(":catastrophe-interfaces")
Don’t do what I did :)
mymac:~ holly$ git submodule add ../catastrophe-interfaces
An anti-pattern
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
compile project(":catastrophe-interfaces")
Don’t do what I did :)
mymac:~ holly$ git submodule add ../catastrophe-interfaces
An anti-pattern
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
This is a code-layout description, not a functional one
compile project(":catastrophe-interfaces")
Don’t do what I did :)
The tradeoff
Duplication of code
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Decoupling
The tradeoff
Duplication of code
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Compile-time independence
If this tradeoff is hurting, your domain model is too coupled.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
If this tradeoff is hurting, your domain model is too coupled.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Have your microservices got the right granularity?
“Does this domain model make sense?”
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
“Does this domain model make sense?”
“Not really.”
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
“Does this domain model make sense?”
“Not really.”
“Does decomposing a system of this size into microservices actually make sense?”
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
“Does this domain model make sense?”
“Not really.”
“Does decomposing a system of this size into microservices actually make sense?”
“Well, no.”
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
The right granularity may be “monolith.”
“Does this domain model make sense?”
“Not really.”
“Does decomposing a system of this size into microservices actually make sense?”
“Well, no.”
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Remember the distributed computing
fallacies.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
HTTP HTTP
HTTP
Remember the distributed computing
fallacies.
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
HTTP HTTP
HTTP
Really
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?
WebTarget cat = client.target(“http://raspberrypiclearcase.local”);WebTarget auth = client.target(“http://raspberrypi2.local”);WebTarget scoring = client.target(“http://raspberrypiredcase.local”);
Network topology
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
ip address: ?.?.?.?
ip address: ?.?.?.?
ip address: ?.?.?.?
ip address: ?.?.?.?
ip address: ?.?.?.?
ip address: special
ip address: precious
ip address: bespoke
ip address: lovely
ip address: fave
Network topology
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Disposability
Say no to snowflake servers
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Disposability
Say no to snowflake servers
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Scaling
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
ip address: special
ip address: precious
ip address: bespoke
ip address: fave
ip address: lovely
Scaling
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
ip address: special
ip address: precious
ip address: bespoke
ip address: fave
ip address: lovely
ip address: lonely
Scaling
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
ip address: special
ip address: precious
ip address: bespoke
ip address: fave
ip address: lovely
ip address: lonely
Service discovery
• Kubernetes
• Apache Zookeeper + Curator
• Eureka
• etcd
• Consul
• Bluemix Service Discovery
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Service discovery
• Kubernetes
• Apache Zookeeper + Curator
• Eureka
• etcd
• Consul
• Bluemix Service Discovery
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Docker
Service discovery
• Kubernetes
• Apache Zookeeper + Curator
• Eureka
• etcd
• Consul
• Bluemix Service Discovery
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Docker
Java
Service discovery
• Kubernetes
• Apache Zookeeper + Curator
• Eureka
• etcd
• Consul
• Bluemix Service Discovery
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
AWS
Docker
Java
SoftLayer
Service discovery
• Kubernetes
• Apache Zookeeper + Curator
• Eureka
• etcd
• Consul
• Bluemix Service Discovery
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
AWS
CoreOS
Docker
Java
SoftLayer
Service discovery
• Kubernetes
• Apache Zookeeper + Curator
• Eureka
• etcd
• Consul
• Bluemix Service Discovery
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
AWS
CoreOS
Docker
Java
DNS HTTP Java
SoftLayer
Service discovery
• Kubernetes
• Apache Zookeeper + Curator
• Eureka
• etcd
• Consul
• Bluemix Service Discovery
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
AWS
CoreOS
Docker
Java
DNS HTTP Java
SoftLayer
Bluemix :)
Cat-astrophe
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
REST REST
REST
Cat-astrophe
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Consul
REST REST
REST
Cat-astrophe
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Discovery
Discovery
Discovery
Consul
REST REST
REST
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
<featureManager> <feature>jaxrs-1.0</feature>
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
<featureManager> <feature>jaxrs-1.0</feature>
Server configuration
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
<featureManager> <feature>jaxrs-1.0</feature><feature>usr:discovery</feature>
…
<consul server="catastrophe.consul" />
Server configuration
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
<featureManager> <feature>jaxrs-1.0</feature><feature>usr:discovery</feature>
…
<consul server="catastrophe.consul" />
Wouldn’t this be nice?
Server configuration
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Liberty extension
(“user feature”)
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Liberty extension
(“user feature”)
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Auto-publishes
REST endpoints
Liberty extension
(“user feature”)
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Auto-publishes
REST endpoints
Liberty extension
(“user feature”)
I
WebSphere Liberty extensibilityhttps://github.com/WASdev/sample.consulservicediscovery
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
–Johnny Appleseed
“Type a quote here.”
Consul view of the Catastrophe services
You need 100% automation
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
An SD card is not devops :)
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
–Johnny Appleseed
“Type a quote here.”
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
–Johnny Appleseed
“Type a quote here.”
Who can draw the best cat? http://catastrophe-web.mybluemix.net/
(I have THINK hats for the highest scores!)
What if I want to run on both pis and the cloud?
What if I want to run on both pis and the cloud?
You need Hybrid Cloud!
What if I want to run on both pis and the cloud?
You need Hybrid Cloud!
–Johnny Appleseed
“Type a quote here.”
Are we done?
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Discovery
Discovery
Discovery
Consul
REST REST
REST
Have we tested it?
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
How de we handle failures?
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Are we actually decoupled?
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
Are we actually decoupled?
@holly_cumminshttp://ibm.biz/bluemixgaragelondon
So remember…
• 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_cumminshttp://ibm.biz/bluemixgaragelondon
IBM _ 74
Thank You!
http://ibm.biz/bluemixgaragelondon http://github.com/holly-cummins/catastrophe-microservices
Holly Cummins | @holly_cummins