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

Microservices - not just with Java

Embed Size (px)

Citation preview

Page 1: Microservices - not just with Java

Microservices –Implementations not

only with JavaEberhard Wolff

http://ewolff.com@ewolffFellow

Page 2: Microservices - not just with Java

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

Page 3: Microservices - not just with Java

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

Page 4: Microservices - not just with Java

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

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

FREE!!!!

Page 5: Microservices - not just with Java

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 - not just with Java

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 - not just with Java

Microservices =Extreme Decoupling

Page 8: Microservices - not just with Java

Operational Complexity

Extreme Decoupling

Page 9: Microservices - not just with Java

MicroService

MicroService

Link

Sync

Async

Page 10: Microservices - not just with Java

Synchronous REST Microservices

Page 11: Microservices - not just with Java

Customer Order Catalog

RESTinternal

HTTPexternal

Page 12: Microservices - not just with Java

Synchronous Microservices

> Service Discovery:IP / port?

> Load Balancing:Resilience and independent scaling

> Routing:Route external request to microservices

> Resilience

Page 13: Microservices - not just with Java

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

Stack

Page 14: Microservices - not just with Java

https://github.com/ewolff/microservice

Page 15: Microservices - not just with Java

Service DiscoveryEureka

Page 16: Microservices - not just with Java

Why Eureka for Service Discovery?

> REST based service registry

> Supports replication

> Caches on the client

> Resilient

> Fast

> Foundation for other services

Page 17: Microservices - not just with Java

Eureka Client> @EnableDiscoveryClient:

generic

> @EnableEurekaClient:specific

> Dependency onspring-cloud-starter-eureka

> Automatically registers application

Page 18: Microservices - not just with Java

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 - not just with Java
Page 20: Microservices - not just with Java

Load BalancingRibbon

Page 21: Microservices - not just with Java

Client

Ribbon: Client Side Load Balancing

> Decentralized Load Balancing

> No bottle neck

> Resilient

LoadBalancer

Server

Page 22: Microservices - not just with Java

Ribbon Example

private 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 - not just with Java

Resilience

Page 24: Microservices - not just with Java

Timeout

> Do call in other thread pool

> Won’t block request handler

> Can implement timeout

Page 25: Microservices - not just with Java

Circuit Breaker

> Called system fails -> open

> Open -> do not forward call

> Forward calls after a time window

Page 26: Microservices - not just with Java

Hystrix Configuration

> Failure Percentage

> Time window until open configurable

> Time window to reject requests

> …

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

Page 27: Microservices - not just with Java

Hystrix &Spring Cloud

> Annotation based approach

> Annotations of javanica libraries

> Simplifies Hystrix

> No commands

Page 28: Microservices - not just with Java

@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 - not just with Java

@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 - not just with Java

ZuulRouting

Page 31: Microservices - not just with Java

Routing> One URL to the outside

> Internal: Many Microservices

> REST

> Or HTML GUI

> Hides internal structure (sort of)

> Might add filters

Page 32: Microservices - not just with Java

Customer Order Catalog

ZuulProxy

Automatically maps route to server registered on Eureka

i.e. /customer/**to CUSTOMER

No configuration

Page 33: Microservices - not just with Java

Netflix Stack

> Service Discovery: Eureka

> Load Balancing: Ribbon

> Routing: Zuul

> Resilience: Hystrix

> Non-Java microservice:specific clients or sidecar

Page 34: Microservices - not just with Java

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 - not just with Java

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

Page 36: Microservices - not just with Java

Kubernetes

Page 37: Microservices - not just with Java

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

kubernetes

Page 38: Microservices - not just with Java

Kubernetes

> Docker container on a single machine:Not resilient enough

> Kubernetes: Run Docker container in cluster

> …and much more!

Page 39: Microservices - not just with Java

Pods

> Kubernetes runs Pods

> Pods = 1..n Docker containers

> Shared volumes

> …and ports

Page 40: Microservices - not just with Java

Replica Sets

> Deployment creates replica set

> Replica sets ensure that a certain number of Pods run

> ...for load balancing / fail over

Page 41: Microservices - not just with Java

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 - not just with Java

Replica Set

Pod

Pod

Service

starts

DNS

Cluster IPaddress

Load BalancerDeployment

creates

Page 43: Microservices - not just with Java

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 - not just with Java

Kubernetes

> Service Discovery: DNS

> Load Balancing: IP

> Routing: Load Balancer or Node Port

> Resilience: Hystrix? envoy proxy?

> Can use any language

Page 45: Microservices - not just with Java

No code dependencies on

Kubernetes!

Page 46: Microservices - not just with Java

UI Integration

Page 47: Microservices - not just with Java

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 - not just with Java

Hyperlinks to navigate between systems.

System 1 System 2

Page 49: Microservices - not just with Java

Transclusion of content served by another application

System 1 System 2

Page 50: Microservices - not just with Java

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

Page 51: Microservices - not just with Java

Server-side integration

> Centralized aggregation

> Bottleneck (runtime/development time)

Browser

UI 1

UI 2

FrontendServer

Backend 1

Backend 2

Page 52: Microservices - not just with Java

Server-side Integration: Technologies

> ESI (Edge Side Include)

> E.g. Varnish cache

> SSI (Server Side Include)

> E.g. Apache httpd, Nginx

Page 53: Microservices - not just with Java

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 - not just with Java

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 - not just with Java

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

Page 56: Microservices - not just with Java

Client-side integration

Browser

UI 1

UI 2

Backend 1

Backend 2

Page 57: Microservices - not just with Java

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 - not just with Java

Transclusion

> Tighter coupling than links

> …but still very loose

> Common CSS

> (Avoid) common JavaScript

> Layout

> Look & Feel

Page 59: Microservices - not just with Java

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

Page 60: Microservices - not just with Java

https://github.com/ewolff/

crimson-assurance-demo

Page 61: Microservices - not just with Java

Conclusion

Page 62: Microservices - not just with Java

Operational Complexity

Extreme Decoupling

Page 63: Microservices - not just with Java

Conclusion: Communication

> Netflix: Java focus, code dependencies

> Kubernetes: No code dependencies

> UI Integration more decoupling

Page 64: Microservices - not just with Java

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 - not just with Java

EMail [email protected] to get:

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

Powered by Amazon Lambda & Microservices