Four times Microservices: REST, Kubernetes, UI Integration, Async - - PowerPoint PPT Presentation

four times microservices rest kubernetes ui integration
SMART_READER_LITE
LIVE PREVIEW

Four times Microservices: REST, Kubernetes, UI Integration, Async - - PowerPoint PPT Presentation

Four times Microservices: REST, Kubernetes, UI Integration, Async Eberhard Wolff @ewolff http://ewolff.com Fellow http://continuous-delivery-buch.de/ http://continuous-delivery-book.com/ http://microservices-buch.de/


slide-1
SLIDE 1

Four times Microservices: REST, Kubernetes, UI Integration, Async

Eberhard Wolff @ewolff http://ewolff.com Fellow

slide-2
SLIDE 2

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

slide-3
SLIDE 3

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

slide-4
SLIDE 4

http://microservices-book.com/ primer.html http://microservices-buch.de/ ueberblick.html

FREE!!!!

slide-5
SLIDE 5

What are Microservices?

> Modules providing interfaces > Processes, Containers, virtual machines

slide-6
SLIDE 6

What are Microservices?

> Independent Continuous Delivery Pipeline including tests > Standardized Operations (configuration, log analysis, tracing, monitoring, deployment) > Resilient (compensate failure, crashes …) therefore separate processes, VM, Docker containers

slide-7
SLIDE 7

Microservices = Extreme Decoupling

slide-8
SLIDE 8

Operational Complexity Extreme Decoupling

slide-9
SLIDE 9

Micro Service Micro Service Link Sync Async

slide-10
SLIDE 10

Synchronous REST Microservices

slide-11
SLIDE 11

Customer Order Catalog REST internal HTTP external

slide-12
SLIDE 12

Synchronous Microservices

> Service Discovery: IP / port? > Load Balancing: Resilience and independent scaling > Routing: Route external request to microservices > Resilience

slide-13
SLIDE 13

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

slide-14
SLIDE 14

https://github.com/ ewolff/microservice

slide-15
SLIDE 15

Service Discovery Eureka

slide-16
SLIDE 16

Why Eureka for Service Discovery?

> REST based service registry > Supports replication > Caches on the client > Resilient > Fast > Foundation for other services

slide-17
SLIDE 17

Eureka Client

> @EnableDiscoveryClient: generic > @EnableEurekaClient: specific > Dependency on spring-cloud-starter-eureka > Automatically registers application

slide-18
SLIDE 18

Eureka Server

@EnableEurekaServer @EnableAutoConfiguration public class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); } }

Add dependency to spring-cloud-starter-eureka-server

slide-19
SLIDE 19
slide-20
SLIDE 20

Load Balancing Ribbon

slide-21
SLIDE 21

Client

Ribbon: Client Side Load Balancing

> Decentralized Load Balancing > No bottle neck > Resilient

Load Balancer Server

slide-22
SLIDE 22

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

slide-23
SLIDE 23

Resilience

slide-24
SLIDE 24

Timeout

> Do call in other thread pool > Won’t block request handler > Can implement timeout

slide-25
SLIDE 25

Circuit Breaker

> Called system fails -> open > Open -> do not forward call > Forward calls after a time window

slide-26
SLIDE 26

Hystrix & Spring Cloud

> Annotation based approach > Annotations of javanica libraries > Simplifies Hystrix > No commands

slide-27
SLIDE 27

@SpringBootApplication @EnableDiscoveryClient @EnableCircuitBreaker public public class class OrderApp OrderApp { public public static static void void main(String[] main(String[] args args) { ) { SpringApplication.run(OrderApp.class class, , args args); ); } }

Enable Hystrix Need spring-cloud-starter-hystrix

slide-28
SLIDE 28

@HystrixCommand(fallbackMethod = "getItemsCache", commandProperties = { @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "2") } ) public public Collection<Item> Collection<Item> findAll findAll() { () { … this this.itemsCache itemsCache = = pagedResources pagedResources.getContent .getContent(); (); return return itemsCache itemsCache; } private private Collection<Item> Collection<Item> getItemsCache getItemsCache() { () { return return itemsCache itemsCache; }

Fallback

slide-29
SLIDE 29

Zuul Routing

slide-30
SLIDE 30

Routing

> One URL to the outside > Internal: Many Microservices > REST > Or HTML GUI > Hides internal structure (sort of) > Might add filters

slide-31
SLIDE 31

Customer Order Catalog Zuul Proxy

Automatically maps route to server registered on Eureka i.e. /customer/** to CUSTOMER No configuration

slide-32
SLIDE 32

Netflix Stack

> Service Discovery: Eureka > Load Balancing: Ribbon > Routing: Zuul > Resilience: Hystrix > Non-Java microservice: specific clients or sidecar

slide-33
SLIDE 33

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

slide-34
SLIDE 34

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

slide-35
SLIDE 35

Kubernetes

slide-36
SLIDE 36

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

slide-37
SLIDE 37

Kubernetes

> Docker container on a single machine: Not resilient enough > Kubernetes: Run Docker container in cluster > …and much more!

slide-38
SLIDE 38

Pods

> Kubernetes runs Pods > Pods = 1..n Docker containers > Shared volumes > …and ports

slide-39
SLIDE 39

Replica Sets

> Deployment creates replica set > Replica sets ensure that a certain number of Pods run > ...for load balancing / fail over

slide-40
SLIDE 40

Services

> Services ensure access to the Pods > DNS entry > Cluster-wide unique IP address for internal access > Node port … > … or external load balancer for external access

slide-41
SLIDE 41

Replica Set Pod Pod Service

starts DNS Cluster IP address Load Balancer

Deployment

creates

slide-42
SLIDE 42

Load Balancer

Kubernetes Cluster Server Service 1 Service 2 Kubernetes Cluster Server Service 1 Service 2

Service adds a load balancer

Load Balancer (e.g. Amazon Elastic Load Balancer)

slide-43
SLIDE 43

Kubernetes

> Service Discovery: DNS > Load Balancing: IP > Routing: Load Balancer or Node Port > Resilience: Hystrix? envoy proxy? > Can use any language

slide-44
SLIDE 44

No code dependencies on Kubernetes!

slide-45
SLIDE 45

UI Integration

slide-46
SLIDE 46

UI Integration

> Very powerful > Often overlooked > UI should be part of a microservices > Self-contained System emphasize UI > http://scs-architecture.org/

slide-47
SLIDE 47

Hyperlinks to navigate between systems. System 1 System 2

slide-48
SLIDE 48

Transclusion of content served by another application System 1 System 2

slide-49
SLIDE 49

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

slide-50
SLIDE 50

UI Integration

> Extremely decoupled > Here is a link: http://ewolff.com > No need to know anything else about the system > What about more complex transclusion?

slide-51
SLIDE 51

Server-side integration

Browser UI 1 UI 2 Frontend Server Backend 1 Backend 2

slide-52
SLIDE 52

Server-side Integration: Technologies

> ESI (Edge Side Include) > E.g. Varnish cache > SSI (Server Side Include) > E.g. Apache httpd, Nginx

slide-53
SLIDE 53

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>

slide-54
SLIDE 54

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

slide-55
SLIDE 55

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

slide-56
SLIDE 56

Client-side integration

Browser UI 1 UI 2 Backend 1 Backend 2

slide-57
SLIDE 57

Client-side Integration: Code

$("a.embeddable").each(fun functi tion(i, link) { $("<div />").load(link.href, fun functi tion(data, status, xhr) { $(link).replaceWith(thi this); }); }); Replace <a href= " " class= "embeddable"> with content of document in a <div> (jQuery)

slide-58
SLIDE 58

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

slide-59
SLIDE 59

https://github.com/ ewolff/crimson- insurance-demo

slide-60
SLIDE 60

Asynchronous Microservices

slide-61
SLIDE 61

Asynchronous

> Do not talk to other microservices > ...and wait for a reply > …while processing a request. > Either don‘t wait for a reply > ...or don‘t communicate while processing a request.

slide-62
SLIDE 62

Asynchronous: Benefits

> Deals with unreliable systems > Can guarantee delivery > Good fit for events > …and Bounded Context / DDD

slide-63
SLIDE 63

Order Invoice Delivery

slide-64
SLIDE 64

Kafka

slide-65
SLIDE 65

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

slide-66
SLIDE 66

Kafka API

> Producer API > Consumer API > Streams API (transformation)

slide-67
SLIDE 67

Kafka Records

> Key > Value > Timestamp > No headers > Stored forever (!)

Record Key Value Timestamp

slide-68
SLIDE 68

Kafka Topics

> Named > Topics have partitions > Order guaranteed per partition > Consumer commits offset per partition > Consumer group: One consumer per partition

Topic Partition Record Record Record

slide-69
SLIDE 69

Topic Partition Record Record Record Producer Offset

Offset committed per consumer

Offset Partition Record Record Record Partition Record Record Record

slide-70
SLIDE 70

Log Compaction

> Remove all but the latest record with a given key > Idea: Old events not relevant > …if new events override > Efficient storage in the long run

Partition Record id=42 Record id=23 Record id=42

slide-71
SLIDE 71

Kafka Replication

> N Replicas (configurable) > In-sync replicas (configurable): write successful if all written

slide-72
SLIDE 72

Asynchronous Microservices

> Service Discovery: via topic > Load Balancing: via partitions / consumer groups > Routing: ./. > Resilience service fails – latency increases

slide-73
SLIDE 73

Kafka Conclusion

> Provides access to old events > Guaranteed order per key > (Log compaction also per key) > Consumer groups send records to one consumer > Additional (complex) infrastructure

slide-74
SLIDE 74

REST & ATOM

slide-75
SLIDE 75

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

slide-76
SLIDE 76

Atom

> Data format > …for feeds, blogs, podcasts etc > Access through HTTP > Idea: Provide a feeds of events / orders

slide-77
SLIDE 77

<feed xmlns="http://www.w3.org/2005/Atom"> <title>Order</title> <link rel="self" href="http://localhost:8080/feed" /> <author><name>Big Money Inc.</name> </author> <subtitle>List of all orders</subtitle> <id>https://github.com/ewolff/microservice- atom/order</id> <updated>2017-04-20T15:28:50Z</updated> <entry> ... </entry> </feed>

slide-78
SLIDE 78

<entry> <title>Order 1</title> <id>https://github.com/ewolff/microservice- atom/order/1</id> <updated>2017-04-20T15:27:58Z</updated> <content type="application/json“ src="http://localhost:8080/order/1" /> <summary>This is the order 1</summary> </entry>

slide-79
SLIDE 79

Atom Feed

> Some unneeded information > …but not a lot > Mostly links to details > ...and timestamps > Can use content negotiation to provide different data formats or details

slide-80
SLIDE 80

Subscribing to Feed

> Poll the feed (HTTP GET) > Client decides when to process new events > …but very inefficient > Lots of unchanged data

slide-81
SLIDE 81

HTTP Caching

> Client GETs feed > Server send data > + Last-Modified header > Client sends get > + If-Modified-Since header > Server: 304 (Not modified) > …or new data

slide-82
SLIDE 82

REST can be asynchronous.

slide-83
SLIDE 83

Atom

> Service Discovery: REST > Load Balancing: REST > Routing: ./. > Resilience failures just increase latency

slide-84
SLIDE 84

Atom Conclusion

> Can provides access to old events if they are stored anyway. > One consumer: idempotency > No additional infrastructure

slide-85
SLIDE 85

Conclusion

slide-86
SLIDE 86

Operational Complexity Extreme Decoupling

slide-87
SLIDE 87

Conclusion: Communication

> Netflix: Java focus, code dependencies > Kubernetes: No code dependencies > UI Integration: more decoupling > Asynchronous deals with challenges in distributed systems

slide-88
SLIDE 88

Links

> List of microservices demos (sync, async, UI): http://ewolff.com/microservices-demos.html > REST vs. Messaging for Microservices https://www.slideshare.net/ewolff/rest-vs- messaging-for-microservices

slide-89
SLIDE 89

EMail bedcon2017@ewolff.com to get: Slides + Microservices Primer + Sample Microservices Book + Sample of Continuous Delivery Book Powered by Amazon Lambda & Microservices