SlideShare a Scribd company logo
1 of 15
Firmansyah.profess@gmail.com
2018
Eclipse Vert.x
Chapter 05
Service Discovery, Resilience
and Stability Patterns
01. Service Discovery
a. Microservices need Service Discovery pattern to achieve:
1. Location Transparency
The microservice consumer may call different instances of the
microservice producer using a round-robin strategy, and between
two invocations the microservice producer may have been moved,
updated, removed (shrinking), or newly created (growth).
2. Mobility
The microservice consumer needs to be able to communicate with
a microservice producer without knowing its exact location in
advance, especially since this location may change (Event Bus
Address, URLs, Ports, Paths, etc) over time.
b. Service Registry
Each microservice should announce how it can be invoked and its
characteristics, including its location, other metadata such as security
policies or versions, the arrivals and departures of services. These
announcements are stored in the service discovery infrastructure which
is generally a service registry.
01. Service Discovery
c. Service Discovery pattern type:
1. Client-Side Service Discovery
• The consumer looks for a producer based on its name and
metadata in the service registry, selects a matching service, and
uses it.
• The reference retrieved from the service registry contains a
direct link to a microservice.
• The service registry can take various forms such as a distributed
data structure, a dedicated infrastructure such as Consul, or be
stored in an inventory service such as Apache Zookeeper or
Redis.
2. Server-Side Service Discovery
• Load Balancer/Router/Proxy/API gateway manage the
discovery.
• The consumer still looks for a producer based on its name and
metadata but retrieves a virtual address.
• When the consumer invokes the producer, the request is
routed to the actual implementation.
• Use this mechanism on Kubernetes or when using AWS
Elastic Load Balancer.
01. Service Discovery
d. Service Discovery pattern type diagram:
1. Client-Side Service Discovery
2. Server-Side Service Discovery
01. Service Discovery
e. Vert.x Service Discovery:
1. Vert.x provides an extensible service discovery mechanism.
2. Provide client-side or server-side service discovery using the same
API.
3. Provide import or export services from many types of service
discovery infrastructures such as Consul, Zookeeper or
Kubernetes.
4. Provide internal service discovery infrastructure. It uses a
distributed data structure shared on the Vert.x cluster.
02. Service Discovery Demo
a. Create a directory called “chapter05”
b. Generate the project structure using maven
inside chapter05 folder:
mvn io.fabric8:vertx-maven-plugin:1.0.5:setup 
-DprojectGroupId=io.vertx.chapter05 
-DprojectArtifactId=http-micro01-vertx-app 
-Dverticle=io.vertx.chapter05.HttpMicro01 
-Ddependencies=vertx-service-discovery,web,rx,
vertx-hazelcast
c. Modify io.vertx.chapter05.HttpMicro01 java file
d. Run HttpMicro01 application
mvn compile vertx:run 
-Dvertx.runArgs="-cluster -
Djava.net.preferIPv4Stack=true"
02. Service Discovery Demo
e. Create a directory called “consumer” inside
“chapter05” folder
f. Generate the project structure using maven
inside consumer folder:
mvn io.fabric8:vertx-maven-plugin:1.0.5:setup 
-DprojectGroupId=io.vertx.chapter05 
-DprojectArtifactId=http-micro02-vertx-app 
-Dverticle=io.vertx.chapter05.HttpMicro02 
-Ddependencies=vertx-service-discovery,web,rx,
vertx-hazelcast,web-client
g. Modify io.vertx.chapter05.HttpMicro02 java file
h. Run HttpMicro02 application
mvn compile vertx:run 
-Dvertx.runArgs="-cluster -
Djava.net.preferIPv4Stack=true"
03. Resilience and Stability
a. Managing Failures Pattern:
1. Every interaction between microservices will eventually fail in some
way, and you need to be prepared for that failure. Failure can take
different forms, ranging from various network errors to semantic
errors. Reactive microservices are responsible for managing
failures locally and must avoid propagating the failure to another
microservice.
2. The Vert.x Failures Handlers:
a) Callback Model: Use AsyncResult object
client.get("/").as(BodyCodec.jsonObject())
.send(ar -> {
if (ar.failed()) {
Throwable cause = ar.cause();
// You need to manage the failure.
} else {
// It's a success
JsonObject json = ar.result().body();
}
});
03. Resilience and Stability
b) RxJava Model: Use subscribe() method:
client.get("/").as(BodyCodec.jsonObject())
.rxSend()
.map(HttpResponse::body)
.subscribe(
json -> { /* success */ },
err -> { /* failure */ }
);
c) RxJava Model: Use onErrorReturn() method:
client.get("/").as(BodyCodec.jsonObject())
.rxSend()
.map(HttpResponse::body)
.onErrorReturn(t -> {
// Called if rxSend produces a failure
// We can return a default value
return new JsonObject();
})
.subscribe(
json -> {
// Always called, either with the actual
//result or with the default value.
}
);
03. Resilience and Stability
b. Timeout and Retry Pattern:
1. A timeout is a simple mechanism that allows you to stop waiting for a
response once you think it will not come. Well-placed timeouts provide
failure isolation, ensuring the failure is limited to the microservice it
affects and allowing you to handle the timeout and continue your
execution in a degraded mode.
2. Timeouts are often used together with retries. When a timeout occurs,
we can try again. Immediately retrying an operation after a failure has a
number of effects
3. Three types of failure could have occurred:
a) The message between A and B has been lost—the operation is not
executed.
b) The operation in B failed—the operation has not completed its
execution.
c) The response message between B and A has been lost, the
operation has been executed successfully, but A didn’t get the
response.
4. This last case is often ignored and can be harmful. In this case,
combining the timeout with a retry can break the integrity of
the system. Retries can only be used with idempotent
operations, i.e., with operations you can invoke multiple times
without changing the result beyond the initial call.
03. Resilience and Stability
c. Circuit Breakers:
1. A circuit breaker is a pattern used to deal with repetitive failures. It
protects a microservice from calling a failing service again and again.
2. Circuit breaker states:
a) Closed: It starts in a closed state in which the circuit breaker
executes operations as usual. If the interaction succeeds, nothing
happens. If it fails, however, the circuit breaker makes a note of the
failure.
b) Open: Once the number of failures (or frequency of failures, in
more sophisticated cases) exceeds a threshold, the circuit breaker
switches to an open state. In this state, calls to the circuit breaker
fail immediately without any attempt to execute the underlying
interaction. Instead of executing the operation, the circuit breaker
may execute a fallback, providing a default result.
c) Half-Open: After a configured amount of time, the circuit breaker
decides that the operation has a chance of succeeding, so it goes
into a half-open state. In this state, the next call to the circuit
breaker executes the underlying interaction. Depending on
the outcome of this call, the circuit breaker resets and
returns to the closed state, or returns to the open state
until another timeout elapses.
03. Resilience and Stability
c. Circuit Breakers:
3. A Circuit Breaker diagram:
4. A circuit breaker switching to an open state needs to be
monitored by your operations team. Both Hystrix and
the Vert.x circuit breaker have monitoring capabilities.
03. Resilience and Stability
d. Health Checks and Failovers:
1. A health check is an API provided by a microservice indicating its state.
It tells the caller whether or not the service is healthy (die, crash, etc.).
2. Note that calling a healthy microservice does not guarantee a success
either. A health check merely indicates that the microservice is running,
not that it will accurately handle your request or that the network will
deliver its answer.
3. Different levels of Health Checks:
a) Readiness Check: Used at deployment time to determine when the
microservice is ready to serve requests (when everything has been
initialized correctly).
b) Liveness Checks: Used to detect misbehaviors and indicate
whether the microservice is able to handle requests successfully.
When a liveness check cannot be executed because the targeted
microservice does not respond, the microservice has probably
crashed.
4. Failover Strategy: Vert.x offers a built-in failover, which is triggered when
a node from the cluster dies and don’t need a custom health check
as the Vert.x cluster pings nodes periodically. When Vert.x loses
track of a node, Vert.x chooses a healthy node of the cluster and
redeploys the dead part.
Thank You!
Any questions? You can find me at
firmansyah.profess@gmail.com
Credits
PPT: ALLPPT.com
Music: https://www.bensound.com
Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patterns

More Related Content

What's hot

Kubernetes deep dive - - Huawei 2015-10
Kubernetes deep dive - - Huawei 2015-10Kubernetes deep dive - - Huawei 2015-10
Kubernetes deep dive - - Huawei 2015-10Vishnu Kannan
 
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome Massimiliano Dessì
 
Creating Kubernetes multi clusters with ClusterAPI @ Stuttgart Kubernetes Meetup
Creating Kubernetes multi clusters with ClusterAPI @ Stuttgart Kubernetes MeetupCreating Kubernetes multi clusters with ClusterAPI @ Stuttgart Kubernetes Meetup
Creating Kubernetes multi clusters with ClusterAPI @ Stuttgart Kubernetes MeetupTobias Schneck
 
Modern Web Apps Development 101
Modern Web Apps Development 101Modern Web Apps Development 101
Modern Web Apps Development 101Stanimir Todorov
 
Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkDmytro Chyzhykov
 
Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015
Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015
Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015Codemotion
 

What's hot (9)

Kubernetes
KubernetesKubernetes
Kubernetes
 
Kubernetes deep dive - - Huawei 2015-10
Kubernetes deep dive - - Huawei 2015-10Kubernetes deep dive - - Huawei 2015-10
Kubernetes deep dive - - Huawei 2015-10
 
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
 
Creating Kubernetes multi clusters with ClusterAPI @ Stuttgart Kubernetes Meetup
Creating Kubernetes multi clusters with ClusterAPI @ Stuttgart Kubernetes MeetupCreating Kubernetes multi clusters with ClusterAPI @ Stuttgart Kubernetes Meetup
Creating Kubernetes multi clusters with ClusterAPI @ Stuttgart Kubernetes Meetup
 
C#on linux
C#on linuxC#on linux
C#on linux
 
Modern Web Apps Development 101
Modern Web Apps Development 101Modern Web Apps Development 101
Modern Web Apps Development 101
 
Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring Framework
 
Wcat
WcatWcat
Wcat
 
Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015
Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015
Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015
 

Similar to Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patterns

Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017Idit Levine
 
Microservices - Event-driven & the hidden landmines
Microservices - Event-driven & the hidden landminesMicroservices - Event-driven & the hidden landmines
Microservices - Event-driven & the hidden landminesVijay Redkar
 
remote method invocation
remote method invocationremote method invocation
remote method invocationArun Nair
 
Istio Triangle Kubernetes Meetup Aug 2019
Istio Triangle Kubernetes Meetup Aug 2019Istio Triangle Kubernetes Meetup Aug 2019
Istio Triangle Kubernetes Meetup Aug 2019Ram Vennam
 
End-to-End Security in Mobile-Cloud Computing
End-to-End Security in Mobile-Cloud ComputingEnd-to-End Security in Mobile-Cloud Computing
End-to-End Security in Mobile-Cloud ComputingDr Sukhpal Singh Gill
 
Windows Communication Foundation Extensions
Windows Communication Foundation ExtensionsWindows Communication Foundation Extensions
Windows Communication Foundation Extensionsgabrielcerutti
 
Microservices With Istio Service Mesh
Microservices With Istio Service MeshMicroservices With Istio Service Mesh
Microservices With Istio Service MeshNatanael Fonseca
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfKAI CHU CHUNG
 
Resilient microservices
Resilient microservicesResilient microservices
Resilient microservicesMaxim Shelest
 
Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3Ilio Catallo
 
Configuring CQ Security
Configuring CQ SecurityConfiguring CQ Security
Configuring CQ Securityconnectwebex
 
Watch How The Giants Fall: Learning from Bug Bounty Results
Watch How The Giants Fall: Learning from Bug Bounty ResultsWatch How The Giants Fall: Learning from Bug Bounty Results
Watch How The Giants Fall: Learning from Bug Bounty Resultsjtmelton
 
Event driven architecure
Event driven architecureEvent driven architecure
Event driven architecureTouraj Ebrahimi
 
Multi-Cloud Micro-Services with CloudFoundry
Multi-Cloud Micro-Services with CloudFoundryMulti-Cloud Micro-Services with CloudFoundry
Multi-Cloud Micro-Services with CloudFoundrygeekclub888
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testabilitydrewz lin
 
Spring Cloud and Netflix Components
Spring Cloud and Netflix ComponentsSpring Cloud and Netflix Components
Spring Cloud and Netflix ComponentsDharshan Sastry B N
 

Similar to Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patterns (20)

Chapter 04: Eclipse Vert.x - Message Based Microservices
Chapter 04: Eclipse Vert.x - Message Based MicroservicesChapter 04: Eclipse Vert.x - Message Based Microservices
Chapter 04: Eclipse Vert.x - Message Based Microservices
 
Microservices with Spring
Microservices with SpringMicroservices with Spring
Microservices with Spring
 
Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017Debugging Microservices - QCON 2017
Debugging Microservices - QCON 2017
 
Microservices - Event-driven & the hidden landmines
Microservices - Event-driven & the hidden landminesMicroservices - Event-driven & the hidden landmines
Microservices - Event-driven & the hidden landmines
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
 
Istio Triangle Kubernetes Meetup Aug 2019
Istio Triangle Kubernetes Meetup Aug 2019Istio Triangle Kubernetes Meetup Aug 2019
Istio Triangle Kubernetes Meetup Aug 2019
 
Istio presentation jhug
Istio presentation jhugIstio presentation jhug
Istio presentation jhug
 
End-to-End Security in Mobile-Cloud Computing
End-to-End Security in Mobile-Cloud ComputingEnd-to-End Security in Mobile-Cloud Computing
End-to-End Security in Mobile-Cloud Computing
 
Windows Communication Foundation Extensions
Windows Communication Foundation ExtensionsWindows Communication Foundation Extensions
Windows Communication Foundation Extensions
 
Microservices With Istio Service Mesh
Microservices With Istio Service MeshMicroservices With Istio Service Mesh
Microservices With Istio Service Mesh
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
 
Resilient microservices
Resilient microservicesResilient microservices
Resilient microservices
 
Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3
 
Configuring CQ Security
Configuring CQ SecurityConfiguring CQ Security
Configuring CQ Security
 
Watch How The Giants Fall: Learning from Bug Bounty Results
Watch How The Giants Fall: Learning from Bug Bounty ResultsWatch How The Giants Fall: Learning from Bug Bounty Results
Watch How The Giants Fall: Learning from Bug Bounty Results
 
Event driven architecure
Event driven architecureEvent driven architecure
Event driven architecure
 
Multi-Cloud Micro-Services with CloudFoundry
Multi-Cloud Micro-Services with CloudFoundryMulti-Cloud Micro-Services with CloudFoundry
Multi-Cloud Micro-Services with CloudFoundry
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
 
Spring Cloud and Netflix Components
Spring Cloud and Netflix ComponentsSpring Cloud and Netflix Components
Spring Cloud and Netflix Components
 

More from Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH

More from Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH (10)

Microservices Decomposition Patterns.v1.0.20191009
Microservices Decomposition Patterns.v1.0.20191009Microservices Decomposition Patterns.v1.0.20191009
Microservices Decomposition Patterns.v1.0.20191009
 
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK.v1.0.20191009
 
Microservices Decomposition Patterns
Microservices Decomposition PatternsMicroservices Decomposition Patterns
Microservices Decomposition Patterns
 
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDKComparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK
Comparison between Oracle JDK, Oracle OpenJDK, and Red Hat OpenJDK
 
Chapter 03: Eclipse Vert.x - HTTP Based Microservices
Chapter 03: Eclipse Vert.x - HTTP Based MicroservicesChapter 03: Eclipse Vert.x - HTTP Based Microservices
Chapter 03: Eclipse Vert.x - HTTP Based Microservices
 
Chapter 02: Eclipse Vert.x - Java First Verticle
Chapter 02: Eclipse Vert.x - Java First VerticleChapter 02: Eclipse Vert.x - Java First Verticle
Chapter 02: Eclipse Vert.x - Java First Verticle
 
Liferay Platform Overview
Liferay Platform OverviewLiferay Platform Overview
Liferay Platform Overview
 
Solution Architecture Framework
Solution Architecture FrameworkSolution Architecture Framework
Solution Architecture Framework
 
Solution Architecture Definition
Solution Architecture DefinitionSolution Architecture Definition
Solution Architecture Definition
 
Mobile Application Development Platform 2017
Mobile Application Development Platform 2017Mobile Application Development Platform 2017
Mobile Application Development Platform 2017
 

Recently uploaded

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 

Recently uploaded (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 

Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patterns

  • 1. Firmansyah.profess@gmail.com 2018 Eclipse Vert.x Chapter 05 Service Discovery, Resilience and Stability Patterns
  • 2. 01. Service Discovery a. Microservices need Service Discovery pattern to achieve: 1. Location Transparency The microservice consumer may call different instances of the microservice producer using a round-robin strategy, and between two invocations the microservice producer may have been moved, updated, removed (shrinking), or newly created (growth). 2. Mobility The microservice consumer needs to be able to communicate with a microservice producer without knowing its exact location in advance, especially since this location may change (Event Bus Address, URLs, Ports, Paths, etc) over time. b. Service Registry Each microservice should announce how it can be invoked and its characteristics, including its location, other metadata such as security policies or versions, the arrivals and departures of services. These announcements are stored in the service discovery infrastructure which is generally a service registry.
  • 3. 01. Service Discovery c. Service Discovery pattern type: 1. Client-Side Service Discovery • The consumer looks for a producer based on its name and metadata in the service registry, selects a matching service, and uses it. • The reference retrieved from the service registry contains a direct link to a microservice. • The service registry can take various forms such as a distributed data structure, a dedicated infrastructure such as Consul, or be stored in an inventory service such as Apache Zookeeper or Redis. 2. Server-Side Service Discovery • Load Balancer/Router/Proxy/API gateway manage the discovery. • The consumer still looks for a producer based on its name and metadata but retrieves a virtual address. • When the consumer invokes the producer, the request is routed to the actual implementation. • Use this mechanism on Kubernetes or when using AWS Elastic Load Balancer.
  • 4. 01. Service Discovery d. Service Discovery pattern type diagram: 1. Client-Side Service Discovery 2. Server-Side Service Discovery
  • 5. 01. Service Discovery e. Vert.x Service Discovery: 1. Vert.x provides an extensible service discovery mechanism. 2. Provide client-side or server-side service discovery using the same API. 3. Provide import or export services from many types of service discovery infrastructures such as Consul, Zookeeper or Kubernetes. 4. Provide internal service discovery infrastructure. It uses a distributed data structure shared on the Vert.x cluster.
  • 6. 02. Service Discovery Demo a. Create a directory called “chapter05” b. Generate the project structure using maven inside chapter05 folder: mvn io.fabric8:vertx-maven-plugin:1.0.5:setup -DprojectGroupId=io.vertx.chapter05 -DprojectArtifactId=http-micro01-vertx-app -Dverticle=io.vertx.chapter05.HttpMicro01 -Ddependencies=vertx-service-discovery,web,rx, vertx-hazelcast c. Modify io.vertx.chapter05.HttpMicro01 java file d. Run HttpMicro01 application mvn compile vertx:run -Dvertx.runArgs="-cluster - Djava.net.preferIPv4Stack=true"
  • 7. 02. Service Discovery Demo e. Create a directory called “consumer” inside “chapter05” folder f. Generate the project structure using maven inside consumer folder: mvn io.fabric8:vertx-maven-plugin:1.0.5:setup -DprojectGroupId=io.vertx.chapter05 -DprojectArtifactId=http-micro02-vertx-app -Dverticle=io.vertx.chapter05.HttpMicro02 -Ddependencies=vertx-service-discovery,web,rx, vertx-hazelcast,web-client g. Modify io.vertx.chapter05.HttpMicro02 java file h. Run HttpMicro02 application mvn compile vertx:run -Dvertx.runArgs="-cluster - Djava.net.preferIPv4Stack=true"
  • 8. 03. Resilience and Stability a. Managing Failures Pattern: 1. Every interaction between microservices will eventually fail in some way, and you need to be prepared for that failure. Failure can take different forms, ranging from various network errors to semantic errors. Reactive microservices are responsible for managing failures locally and must avoid propagating the failure to another microservice. 2. The Vert.x Failures Handlers: a) Callback Model: Use AsyncResult object client.get("/").as(BodyCodec.jsonObject()) .send(ar -> { if (ar.failed()) { Throwable cause = ar.cause(); // You need to manage the failure. } else { // It's a success JsonObject json = ar.result().body(); } });
  • 9. 03. Resilience and Stability b) RxJava Model: Use subscribe() method: client.get("/").as(BodyCodec.jsonObject()) .rxSend() .map(HttpResponse::body) .subscribe( json -> { /* success */ }, err -> { /* failure */ } ); c) RxJava Model: Use onErrorReturn() method: client.get("/").as(BodyCodec.jsonObject()) .rxSend() .map(HttpResponse::body) .onErrorReturn(t -> { // Called if rxSend produces a failure // We can return a default value return new JsonObject(); }) .subscribe( json -> { // Always called, either with the actual //result or with the default value. } );
  • 10. 03. Resilience and Stability b. Timeout and Retry Pattern: 1. A timeout is a simple mechanism that allows you to stop waiting for a response once you think it will not come. Well-placed timeouts provide failure isolation, ensuring the failure is limited to the microservice it affects and allowing you to handle the timeout and continue your execution in a degraded mode. 2. Timeouts are often used together with retries. When a timeout occurs, we can try again. Immediately retrying an operation after a failure has a number of effects 3. Three types of failure could have occurred: a) The message between A and B has been lost—the operation is not executed. b) The operation in B failed—the operation has not completed its execution. c) The response message between B and A has been lost, the operation has been executed successfully, but A didn’t get the response. 4. This last case is often ignored and can be harmful. In this case, combining the timeout with a retry can break the integrity of the system. Retries can only be used with idempotent operations, i.e., with operations you can invoke multiple times without changing the result beyond the initial call.
  • 11. 03. Resilience and Stability c. Circuit Breakers: 1. A circuit breaker is a pattern used to deal with repetitive failures. It protects a microservice from calling a failing service again and again. 2. Circuit breaker states: a) Closed: It starts in a closed state in which the circuit breaker executes operations as usual. If the interaction succeeds, nothing happens. If it fails, however, the circuit breaker makes a note of the failure. b) Open: Once the number of failures (or frequency of failures, in more sophisticated cases) exceeds a threshold, the circuit breaker switches to an open state. In this state, calls to the circuit breaker fail immediately without any attempt to execute the underlying interaction. Instead of executing the operation, the circuit breaker may execute a fallback, providing a default result. c) Half-Open: After a configured amount of time, the circuit breaker decides that the operation has a chance of succeeding, so it goes into a half-open state. In this state, the next call to the circuit breaker executes the underlying interaction. Depending on the outcome of this call, the circuit breaker resets and returns to the closed state, or returns to the open state until another timeout elapses.
  • 12. 03. Resilience and Stability c. Circuit Breakers: 3. A Circuit Breaker diagram: 4. A circuit breaker switching to an open state needs to be monitored by your operations team. Both Hystrix and the Vert.x circuit breaker have monitoring capabilities.
  • 13. 03. Resilience and Stability d. Health Checks and Failovers: 1. A health check is an API provided by a microservice indicating its state. It tells the caller whether or not the service is healthy (die, crash, etc.). 2. Note that calling a healthy microservice does not guarantee a success either. A health check merely indicates that the microservice is running, not that it will accurately handle your request or that the network will deliver its answer. 3. Different levels of Health Checks: a) Readiness Check: Used at deployment time to determine when the microservice is ready to serve requests (when everything has been initialized correctly). b) Liveness Checks: Used to detect misbehaviors and indicate whether the microservice is able to handle requests successfully. When a liveness check cannot be executed because the targeted microservice does not respond, the microservice has probably crashed. 4. Failover Strategy: Vert.x offers a built-in failover, which is triggered when a node from the cluster dies and don’t need a custom health check as the Vert.x cluster pings nodes periodically. When Vert.x loses track of a node, Vert.x chooses a healthy node of the cluster and redeploys the dead part.
  • 14. Thank You! Any questions? You can find me at firmansyah.profess@gmail.com Credits PPT: ALLPPT.com Music: https://www.bensound.com