Microservices Webinar Series – Part 1 of 4
Communication Between
Loosely Coupled
Microservices
@berndruecker
bernd.ruecker@camunda.com
@berndruecker
http://berndruecker.io/
Bernd Ruecker
Co-founder and
Chief Technologist of
Camunda
Service
A
Microservices
@berndruecker
Monolith
Service
B
Service
C
C
B
A
D
Service
A
Autonomous Microservices
@berndruecker
Service
B
Service
C
Photo by born1945, available under Creative Commons BY 2.0 license.
Service
A
Business capabilities require services to interact
@berndruecker
Service
B
Service
C
Microservices Webinar Series
What When
Communication Between Microservices Today
Benefits of Long-Running Microservices Q2/2021
Business Transactions And Consistency Q3/2021
Accelerate Via Cloud-Native Q4/2021
Let‘s talk about food
How does ordering Pizza works?
Pizza
Place
You
Phone Call
Synchronous blocking communication
Feedback loop (ack, confirmation or rejection)
Temporal coupling (e.g. busy, not answering)
Pizza
Place
You
Email
Asynchronous non-blocking communication
No temporal coupling
Pizza
Place
You
A feedback loop might make sense
(ack, confirmation or rejection)
Email
Confirmation Email
Feedback loop != result
Pizza
Place
You
Email
Confirmation Email
Pizza Delivery
Feedback (ACK, confirmation, rejection)
Result
Synchronous blocking behavior for the result?
Bad user experience
Does not scale well
Scalable Coffee Making
https://www.enterpriseintegrationpatterns.com/ramblings/18_starbucks.html
Photo by John Ingle
@berndruecker
Scalable Pizza baking
La Pizza Cresci Cannes
https://www.maison-cresci.com/
from http://www.travellingsnail.com/content/la-pizza-cresci-cannes
PUT/order
Synchronous results?
Pizza
Place
You
Pizza Delivery
HTTP 200
The task of
Pizza making is
long running
Only the first communication step is synchronous
Pizza
Place
You
PUT/order
HTTP 200
Pizza Delivery
The task of
Pizza making is
long running
Only the first communication step is synchronous
Pizza
Place
You
PUT/order
HTTP 200
Pizza Delivery
The task of
Pizza making is
long running
Command vs. event-based communication
Pizza
Place
You
I order this pizza
OK – got it
Command = Intent
Cannot be ignored
Independant of communication channel
Pizza
Place
You
„Hey – I am hungry!“
Event = Fact
Sender can't control what happens
Events vs. Commands
„Pizza Salmon
is ready!“
I baked this for my friend Andrea.
Please package it immediately and
deliver it over while it‘s hot!
Definitions
Event = Something happened in the past. It is a fact.
Sender does not know who picks up the event.
Command = Sender wants s.th. to happen. It has an intent.
Recipient does not know who issued the command.
Does this scale?
Hey – somebody
ordered
Hey – Pizza is
ready
Orchestrator
Command
Definition
Orchestration = command-driven communication
Choreography = event-driven communication
Let‘s switch examples: Order fulfillment
Checkout
Payment
Inventory
Shipment
Order
placed
Payment
received
Goods
shipped
Goods
fetched
@berndruecker
Event chains
Checkout
Payment
Inventory
Shipment
Order
placed
Payment
received
Goods
shipped
Goods
fetched
@berndruecker
Phil Calcado at QCon NYC 2019
Order
Fulfillment
Orchestration and Choreography
Checkout
Payment
Inventory
Shipment
Payment
received
Order
placed
Retrieve
payment
@berndruecker
This is
choreography
This is
orchestration
Order
Fulfillment
Collaboration style is independant of communication style
Checkout
Payment
Inventory
Shipment
Payment
received
Order
placed
Retrieve
payment
@berndruecker
Choreography
Orchestration
Asynchronous
non-blocking
Asynchronous
non-blocking
Synchronous
blocking
Want to learn more about choreography vs. orchestration?
https://learning.oreilly.com/library/view/practical-process-automation/9781492061441/
30 days trial: https://learning.oreilly.com/get-learning/?code=PPAER20
Recording from QCon: https://drive.google.com/file/d/1IRWoQCX-gTPs7RVP5VrXaF1JozYWVbJv/view?usp=sharing
Slides: https://www.slideshare.net/BerndRuecker/gotopia-2020-balancing-choreography-and-orchestration
Communication Options – Quick Summary
Communication
Style
Synchronous
Blocking
Asynchronous
Non-Blocking
Collaboration
Style
Command-Driven Event-Driven
Example REST
Messaging
(Queues)
Messaging
(Topics)
Feedback Loop
HTTP
Response
Response
Message
-
Pizza Ordering via Phone Call E-Mail Twitter
This is not the
same!
Coupling
Types of Coupling
Type of coupling Description Example Recommendation
Implementation Coupling Service knows internals of
other services
Joined database Avoid
Types of Coupling
Type of coupling Description Example Recommendation
Implementation Coupling Service knows internals of
other services
Joined database Avoid
Types of Coupling
Type of coupling Description Example Recommendation
Implementation Coupling Service knows internals of
other services
Joined database Avoid
Temporal Coupling Service depends on
availability of other
services
Synchronous blocking
communication
Reduce or manage
Types of Coupling
Type of coupling Description Example Recommendation
Implementation Coupling Service knows internals of
other services
Joined database Avoid
Temporal Coupling Service depends on
availability of other
services
Synchronous blocking
communication
Reduce or manage
Types of Coupling
Type of coupling Description Example Recommendation
Implementation Coupling Service knows internals of
other services
Joined database Avoid
Temporal Coupling Service depends on
availability of other
services
Synchronous blocking
communication
Reduce or manage
Deployment Coupling Multiple services can only
be deployed together
Release train Typically avoid, but
depends
Types of Coupling
Type of coupling Description Example Recommendation
Implementation Coupling Service knows internals of
other services
Joined database Avoid
Temporal Coupling Service depends on
availability of other
services
Synchronous blocking
communication
Reduce or manage
Deployment Coupling Multiple services can only
be deployed together
Release train Typically avoid, but
depends
Types of Coupling
Type of coupling Description Example Recommendation
Implementation Coupling Service knows internals of
other services
Joined database Avoid
Temporal Coupling Service depends on
availability of other
services
Synchronous blocking
communication
Reduce or manage
Deployment Coupling Multiple services can only
be deployed together
Release train Typically avoid, but
depends
Domain Coupling Business capabilities
require multiple services
Order fulfillment requires
payment, inventory and
shipping
Unavoidable unless you
change business
requirements or service
boundaries
Types of Coupling
Type of coupling Description Example Recommendation
Implementation Coupling Service knows internals of
other services
Joined database Avoid
Temporal Coupling Service depends on
availability of other
services
Synchronous blocking
communication
Reduce or manage
Deployment Coupling Multiple services can only
be deployed together
Release train Typically avoid, but
depends
Domain Coupling Business capabilities
require multiple services
Order fulfillment requires
payment, inventory and
shipping
Unavoidable unless you
change business
requirements or service
boundaries
This is influenced with the communication
or collaboration style
Remote Communication
Patterns To Survive Remote Communication
Service
Consumer
Pattern/Concept Use With
Service
Provider
X Service Discovery Sync (X)
X Circuit Breaker Sync
X Bulkhead Sync
(X) Load Balancing Sync X
X Retry Sync / Async
X Idempotency Sync / Async X
De-duplication Async X
(X) Back Pressure & Rate Limiting Sync / (Async) X
X Await feedback Async
X Sagas Sync / Async (X) …
Patterns To Survive Remote Communication
Service
Consumer
Pattern/Concept Use With
Service
Provider
X Service Discovery Sync (X)
X Circuit Breaker Sync
X Bulkhead Sync
(X) Load Balancing Sync X
X Retry Sync / Async
X Idempotency Sync / Async X
De-duplication Async X
(X) Back Pressure & Rate Limiting Sync / (Async) X
X Await feedback Async
X Sagas Sync / Async (X) …
Circuit
Breaker
Photo by CITYEDV, available under Creative Commons CC0 1.0 license.
Circuit Breaker
Webshop
You
PUT/order Address
Check
Payment
from https://martinfowler.com/bliki/CircuitBreaker.html
Circuit Breaker
Webshop
You
PUT/order Address
Check
Payment
@CircuitBreaker(name = BACKEND, fallbackMethod =
"fallback")
public boolean addressValid(Address a) {
return httpEndpoint.GET(...);
}
private boolean fallback(Address a) {
return true;
}
e.g. Resilience4J:
resilience4j.circuitbreaker:
instances:
BACKEND:
registerHealthIndicator: true
slidingWindowSize: 100
permittedNumberOfCallsInHalfOpenState: 3
minimumNumberOfCalls: 20
waitDurationInOpenState: 50s
failureRateThreshold: 50
Circuit Breaker
Webshop
You
PUT/order Address
Check
Payment
@CircuitBreaker(name = BACKEND)
public void retrievePayment(...) {
return httpEndpoint.PUT(...);
}
e.g. Resilience4J:
Bulkhead
Webshop
You
PUT/order Address
Check
Payment
„Only 10 threads are allowed to wait
for payment handling“
Retry
Webshop
You
PUT/order Address
Check
Payment
e.g. Resilience4J:
@Retry(name = BACKEND, fallbackMethod = "fallback")
public boolean addressValid(Address a) {
return httpEndpoint.GET(...);
}
private boolean fallback(Address a) {
return true;
}
RetryConfig config = RetryConfig.custom()
.maxAttempts(5)
.waitDuration(Duration.ofMillis(500))
.retryOnResult(r -> r.getStatus() == 500)
.retryOnException(e -> e instanceof WebServiceException
.retryExceptions(IOException.class, TimeoutException.cl
.ignoreExceptions(BusinessException.class)
.build();
Stateful retry
Webshop
You
PUT/order Address
Check
Payment
We wait at least
15 minutes
for the payment service
to become available.
Bank transfer can take
7 days.
Stateful retry
Webshop
You
PUT/order Address
Check
Payment
We wait at least
15 minutes
for the payment service
to become available.
Bank transfer can take
7 days.
Photo by pixabay, available under Creative Commons CC0 1.0 license.
Requirement: Idempotency of services!
Photo by pixabay, available under Creative Commons CC0 1.0 license.
Requirement: Idempotency of services!
Photo by Chr.Späth, available under Public Domain.
Make every service idempotent!
Credit
Card
Payment
Charge Credit Card
cardNumber
amount
Charge Credit Card
cardNumber
amount
transactionId
Not idempotent
Idempotent
charge
Generally: create Ids
as soon as possible
Awaiting feedback
from RabbitMQ manual
Awaiting feedback
from RabbitMQ manual
We wait at least
15 minutes
for the payment service
to become available.
Bank transfer can take
7 days.
Did you just say „long running“?
Patterns To Survive Remote Communication
Service
Consumer
Pattern/Concept
Service
Provider
X Service Discovery (X)
X Circuit Breaker
Bulkhead
(X) Load Balancing X
X Retry
X Idempotency X
De-duplication X
(X) Back Pressure & Rate Limiting X
X Await feedback
X Sagas (X)
Patterns For Remote Communication
Service
Consumer
Pattern/Concept
Service
Provider
X Service Discovery (X)
X Circuit Breaker
Bulkhead
(X) Load Balancing X
X Retry
X Idempotency X
De-duplication X
(X) Back Pressure & Rate Limiting X
X Await feedback
X Sagas (X)
A hard decision
Take Away
• Know
• communication styles (sync/async)
• collaboration styles (command/event)
• Patterns to survive
• You can get rid of temporal coupling with asynchronous communication
• Make sure you or your team can handle it
• You will need long running capabilities (you might need it anyway)
• Domain coupling does not go away!
Want to know more?
https://page.camunda.com/wp-ultimate-
guide-to-process-automation-and-
microservices
Thank you!
@berndruecker
mail@berndruecker.io
@berndruecker
https://berndruecker.io
https://medium.com/berndruecker
https://github.com/berndruecker
Contact:
Slides:
Blog:
Code:
https://learning.oreilly.com/library
/view/practical-process-
automation/9781492061441/
30 days trial:
https://learning.oreilly.com/get-
learning/?code=PPAER20

Webinar "Communication Between Loosely Coupled Microservices"