Microservices – Implementations not only with Java · Microservices – Implementations not only...

65
Microservices – Implementations not only with Java Eberhard Wolff http://ewolff.com @ewolff Fellow

Transcript of Microservices – Implementations not only with Java · Microservices – Implementations not only...

Page 1: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Microservices –Implementations not

only with JavaEberhard Wolff

http://ewolff.com@ewolffFellow

Page 2: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

http://continuous-delivery-buch.de/ http://continuous-delivery-book.com/

Page 3: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

http://microservices-buch.de/ http://microservices-book.com/

Page 4: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

http://microservices-book.com/primer.html

http://microservices-buch.de/ueberblick.html

FREE!!!!

Page 5: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

What are Microservices?

> Modules providing interfaces

> Processes, Containers, virtual machines

> Standardized communication:Synchronous, asynchronous, or UI integration

> Macro- and Micro-Architecturei.e. clearly defined common, and specific decisions

Page 6: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

What are Microservices?

> Independent Continuous Delivery Pipeline including tests

> Standardized Operations(configuration, log analysis, tracing, monitoring, deployment)

> Standards on the interface levele.g. not a specific log library

> Resilient (compensate failure, crashes …)therefore separate processes, VM, Docker containers

Page 7: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Microservices =Extreme Decoupling

Page 8: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Operational Complexity

Extreme Decoupling

Page 9: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

MicroService

MicroService

Link

SyncAsync

Page 10: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Synchronous REST Microservices

Page 11: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Customer Order Catalog

RESTinternal

HTTPexternal

Page 12: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Synchronous Microservices

> Service Discovery:IP / port?

> Load Balancing:Resilience and independent scaling

> Routing:Route external request to microservices

> Resilience

Page 13: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Synchronous Microservices with Java, Spring Boot / Cloud & the Netflix

Stack

Page 14: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

https://github.com/ewolff/microservice

Page 15: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Service DiscoveryEureka

Page 16: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Why Eureka for Service Discovery?

> REST based service registry

> Supports replication

> Caches on the client

> Resilient

> Fast

> Foundation for other services

Page 17: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Eureka Client> @EnableDiscoveryClient:

generic

> @EnableEurekaClient:specific

> Dependency onspring-cloud-starter-eureka

> Automatically registers application

Page 18: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Eureka Server@EnableEurekaServer

@EnableAutoConfiguration

public class EurekaApplication {

public static void main(String[] args) {

SpringApplication.run(EurekaApplication.class, args);

}

}

Add dependency tospring-cloud-starter-eureka-server

Page 19: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow
Page 20: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Load BalancingRibbon

Page 21: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Client

Ribbon: Client Side Load Balancing

> Decentralized Load Balancing

> No bottle neck

> Resilient

LoadBalancer

Server

Page 22: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Ribbon Exampleprivate LoadBalancerClient loadBalancer;

ServiceInstance instance = loadBalancer.choose("CATALOG");

String url = "http://" + instance.getHost() + ":”

+ instance.getPort() + "/catalog/";

Via Dependency Injection

Eureka name

Need dependency to spring-cloud-starter-ribbon

Page 23: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Resilience

Page 24: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Timeout

> Do call in other thread pool

> Won’t block request handler

> Can implement timeout

Page 25: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Circuit Breaker

> Called system fails -> open

> Open -> do not forward call

> Forward calls after a time window

Page 26: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Hystrix Configuration

> Failure Percentage

> Time window until open configurable

> Time window to reject requests

> …

> https://github.com/Netflix/Hystrix/wiki/Configuration

Page 27: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Hystrix &Spring Cloud

> Annotation based approach

> Annotations of javanica libraries

> Simplifies Hystrix

> No commands

Page 28: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

@SpringBootApplication

@EnableDiscoveryClient

@EnableCircuitBreaker

public class OrderApp {

public static void main(String[] args) {

SpringApplication.run(OrderApp.class, args);

}

}

Enable Hystrix

Need spring-cloud-starter-hystrix

Page 29: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

@HystrixCommand(fallbackMethod = "getItemsCache",

commandProperties = { @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "2") } )

public Collection<Item> findAll() {

this.itemsCache = pagedResources.getContent();

return itemsCache;

}

private Collection<Item> getItemsCache() {

return itemsCache;

}

Fallback

Page 30: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

ZuulRouting

Page 31: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Routing> One URL to the outside

> Internal: Many Microservices

> REST

> Or HTML GUI

> Hides internal structure (sort of)

> Might add filters

Page 32: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Customer Order Catalog

ZuulProxy

Automatically maps route to server registered on Eurekai.e. /customer/**

to CUSTOMERNo configuration

Page 33: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Netflix Stack

> Service Discovery: Eureka

> Load Balancing: Ribbon

> Routing: Zuul

> Resilience: Hystrix

> Non-Java microservice:specific clients or sidecar

Page 34: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Consul> Service Discovery by Hashicorp

> DNS interface

> Platform independent

> Consul Template can fill out config file templates

> e.g. for load balancer

> …unaware of service discovery

Page 35: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

https://github.com/ewolff/microservice-consul

Page 36: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Kubernetes

Page 37: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

https://github.com/ewolff/microservice-

kubernetes

Page 38: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Kubernetes

> Docker container on a single machine:Not resilient enough

> Kubernetes: Run Docker container in cluster

> …and much more!

Page 39: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Pods

> Kubernetes runs Pods

> Pods = 1..n Docker containers

> Shared volumes

> …and ports

Page 40: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Replica Sets

> Deployment creates replica set

> Replica sets ensure that a certain number of Pods run

> ...for load balancing / fail over

Page 41: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Services

> Services ensure access to the Pods

> DNS entry

> Cluster-wide unique IP address for internal access

> External load balancer for external access

Page 42: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Replica Set

Pod

Pod

Service

starts

DNS

Cluster IPaddress

Load BalancerDeployment

creates

Page 43: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Load Balancer

Kubernetes Cluster Server

Service 1

Service 2

Kubernetes Cluster Server

Service 1

Service 2Serviceadds a load

balancer

Load Balancer(e.g. Amazon

ElasticLoad Balancer)

Page 44: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Kubernetes

> Service Discovery: DNS

> Load Balancing: IP

> Routing: Load Balancer or Node Port

> Resilience: Hystrix? envoy proxy?

> Can use any language

Page 45: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

No code dependencies on

Kubernetes!

Page 46: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

UI Integration

Page 47: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

UI Integration

> Very powerful

> Often overlooked

> UI should be part of a microservices

> Self-contained System emphasize UI

> http://scs-architecture.org/

Page 48: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Hyperlinks to navigate between systems.

System 1 System 2

Page 49: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Transclusion of content served by another application

System 1 System 2

Page 50: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

https://www.innoq.com/en/blog/transclusion/

Page 51: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Server-side integration

> Centralized aggregation

> Bottleneck (runtime/development time)

Browser

UI 1

UI 2

FrontendServer

Backend 1

Backend 2

Page 52: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Server-side Integration: Technologies

> ESI (Edge Side Include)

> E.g. Varnish cache

> SSI (Server Side Include)

> E.g. Apache httpd, Nginx

Page 53: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

ESI (Edge Side Includes)

...<header>... Logged in as: Ada Lovelace ...</header>...<div>

... a lot of static content and images ...</div>...<div>

some dynamic content</div>

Page 54: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

ESI (Edge Side Includes)

...

<esi:include src="http://example.com/header" />

...<div>

... a lot of static content and images ...</div>...

<esi:include src="http://example.com/dynamic" />

http://www.w3.org/TR/esi-lang

Page 55: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

https://github.com/ewolff/SCS-ESI

Page 56: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Client-side integration

Browser

UI 1

UI 2

Backend 1

Backend 2

Page 57: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Client-side Integration: Code

$("a.embeddable").each(function(i, link) {

$("<div />").load(link.href, function(data, status, xhr) {

$(link).replaceWith(this);

});

});

Replace <a href= " " class= "embeddable"> with content of document in a <div> (jQuery)

Page 58: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Transclusion

> Tighter coupling than links

> …but still very loose

> Common CSS

> (Avoid) common JavaScript

> Layout

> Look & Feel

Page 59: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

https://github.com/ewolff/SCS-jQuery

Page 60: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

https://github.com/ewolff/

crimson-assurance-demo

Page 61: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Conclusion

Page 62: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Operational Complexity

Extreme Decoupling

Page 63: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Conclusion: Communication

> Netflix: Java focus, code dependencies

> Kubernetes: No code dependencies

> UI Integration more decoupling

Page 64: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

Links

> List of microservices demos (sync, async, UI):http://ewolff.com/microservices-demos.html

> REST vs. Messaging for Microserviceshttps://www.slideshare.net/ewolff/rest-vs-messaging-for-microservices

Page 65: Microservices – Implementations not only with Java · Microservices – Implementations not only with Java Eberhard Wolff  @ewolff Fellow

EMail [email protected] to get:

Slides+ Microservices Primer+ Sample Microservices Book+ Sample of Continuous Delivery Book

Powered by Amazon Lambda & Microservices