Slide 1

Slide 1 text

Four times Microservices: REST, Kubernetes, UI Integration, Async Eberhard Wolff @ewolff http://ewolff.com Fellow

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

What are Microservices? > Modules providing interfaces > Processes, Containers, virtual machines

Slide 6

Slide 6 text

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 text

Microservices = Extreme Decoupling

Slide 8

Slide 8 text

Operational Complexity Extreme Decoupling

Slide 9

Slide 9 text

Micro Service Micro Service Link Sync Async

Slide 10

Slide 10 text

Synchronous REST Microservices

Slide 11

Slide 11 text

Customer Order Catalog REST internal HTTP external

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

https://github.com/ ewolff/microservice

Slide 15

Slide 15 text

Service Discovery Eureka

Slide 16

Slide 16 text

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 text

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

Slide 18

Slide 18 text

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 text

No content

Slide 20

Slide 20 text

Load Balancing Ribbon

Slide 21

Slide 21 text

Client Ribbon: Client Side Load Balancing > Decentralized Load Balancing > No bottle neck > Resilient Load Balancer Server

Slide 22

Slide 22 text

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 text

Resilience

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

@SpringBootApplication @EnableDiscoveryClient @EnableCircuitBreaker public class OrderApp { public static void main(String[] args) { SpringApplication.run(OrderApp.class, args); } } Enable Hystrix Need spring-cloud-starter-hystrix

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Zuul Routing

Slide 30

Slide 30 text

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 text

Customer Order Catalog Zuul Proxy Automatically maps route to server registered on Eureka i.e. /customer/** to CUSTOMER No configuration

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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 text

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

Slide 35

Slide 35 text

Kubernetes

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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 text

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 text

Replica Set Pod Pod Service starts DNS Cluster IP address Load Balancer Deployment creates

Slide 42

Slide 42 text

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 text

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 text

No code dependencies on Kubernetes!

Slide 45

Slide 45 text

UI Integration

Slide 46

Slide 46 text

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 text

Hyperlinks to navigate between systems. System 1 System 2

Slide 48

Slide 48 text

Transclusion of content served by another application System 1 System 2

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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 text

Server-side integration Browser UI 1 UI 2 Frontend Server Backend 1 Backend 2

Slide 52

Slide 52 text

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 text

ESI (Edge Side Includes) ... ... Logged in as: Ada Lovelace ... ...
... a lot of static content and images ...
...
some dynamic content

Slide 54

Slide 54 text

ESI (Edge Side Includes) ... ...
... a lot of static content and images ...
... http://www.w3.org/TR/esi-lang

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

Client-side integration Browser UI 1 UI 2 Backend 1 Backend 2

Slide 57

Slide 57 text

Client-side Integration: Code $("a.embeddable").each(function(i, link) { $("
").load(link.href, function(data, status, xhr) { $(link).replaceWith(this); }); }); Replace with content of document in a
(jQuery)

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

Asynchronous Microservices

Slide 61

Slide 61 text

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 text

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

Slide 63

Slide 63 text

Order Invoice Delivery

Slide 64

Slide 64 text

Kafka

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

Kafka Records > Key > Value > Timestamp > No headers > Stored forever (!) Record Key Value Timestamp

Slide 68

Slide 68 text

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 text

Topic Partition Record Record Record Producer Offset Offset committed per consumer Offset Partition Record Record Record Partition Record Record Record

Slide 70

Slide 70 text

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 text

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

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

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 text

REST & ATOM

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

Order Big Money Inc. List of all orders https://github.com/ewolff/microservice- atom/order 2017-04-20T15:28:50Z ...

Slide 78

Slide 78 text

Order 1 https://github.com/ewolff/microservice- atom/order/1 2017-04-20T15:27:58Z This is the order 1

Slide 79

Slide 79 text

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 text

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 text

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 text

REST can be asynchronous.

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

Conclusion

Slide 86

Slide 86 text

Operational Complexity Extreme Decoupling

Slide 87

Slide 87 text

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 text

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 text

EMail [email protected] to get: Slides + Microservices Primer + Sample Microservices Book + Sample of Continuous Delivery Book Powered by Amazon Lambda & Microservices