Communication in a
Microservice Architecture
Per Bernhardt, Staff Software Engineer
December 4th 2019
2
@perprogramming
3
4
Basics
Synchronous vs. Asynchronous Integration
Distributed Transactions vs. Eventual Consistency
Service Routing
Organisational Considerations
Q & A
Agenda
5
Basics
6
Basics – Leaving the Process
User Content
Search Sales
Suggestions Images
User Content
Search Sales
Suggestions Images
7
Basics – Fallacies of distributed computing
The network is reliable
Latency is zero
Bandwidth is infinite
The network is secure
Topology doesn't change
There is one administrator
Transport cost is zero
The network is homogeneous
8
Basics – Types of communication
Synchronous protocol
Sender Receiver
Request
Response
Asynchronous protocol
Sender Receiver
Request
9
Basics – Types of communication
Single Receiver
Multiple Receiver
Sender Receiver
Sender
Receiver
Receiver
Receiver
10
Basics – Types of communication
Orchestration
Choreography
Customer
Service
Loyality
Service
Post
Service
Email
Service
“Customer Created”
Customer
Service
Loyality
Service
Post
Service
Email
Service
“Create Points Balance!”
“Send Welcome Email”
“Send Welcome Pack”
11
Basics – Recommended Readings
https://docs.microsoft.com/de-
de/dotnet/architecture/microservices/architect-
microservice-container-applications/
12
Synchronous vs. Asynchronous
Integration
13
Synchronous vs. Asynchronous Integration
User
Content
Sales …
Suggestions Images
Frontend API New Frontend
Synchronous
14
Synchronous vs. Asynchronous Integration
User
Content
Sales …
Suggestions Images
Frontend API New Frontend
Content Images
Suggestions Sales
Synchronous
Asynchronous
15
Synchronous vs. Asynchronous Integration
User
Content
Sales …
Suggestions Images
Frontend API New Frontend
Content Images
Suggestions Sales
Asynchronous
Content ImagesContentImages
16
Synchronous vs. Asynchronous Integration
“The one-hop rule: A service should not
call other services to respond to a request.”
https://messente.com/blog/most-recent/5-mistakes-transition-to-microservices
17
Synchronous vs. Asynchronous Integration
“Simply put, without decoupling the data,
the architecture is not microservices.”
https://martinfowler.com/articles/break-monolith-into-microservices.html
18
Synchronous vs. Asynchronous Integration
“So what about authentication??”
Some random developer
19
Distributed Transactions
vs.
Eventual Consistency
20
Distributed Transactions vs. Eventual Consistency -
Transactions are technically hard…
21
Distributed Transactions vs. Eventual Consistency –
The Two Phase Commit (2PC)
22
Distributed Transactions vs. Eventual Consistency –
Eventual Consistency is conceptually hard…
23
Distributed Transactions vs. Eventual Consistency –
Eventual Consistency
Content Service Search Service
Updates content Searches content
Eventually consistent
24
• Search Service has a daily cronjob
• Fetches all content via REST API
• Search Index is eventually consistent “the next day”
 Synchronous protocol + Orchestration
Distributed Transactions vs. Eventual Consistency –
Eventual Consistency done “simple”
25
Distributed Transactions vs. Eventual Consistency –
Eventual Consistency done “hard”
• Content Service pushes update events to message queue
• Search Service subscribed to content update events
• Search Index is eventually consistent “every few seconds”
 Asynchronous protocol + Choreography
26
Distributed Transactions vs. Eventual Consistency –
Eventual Consistency done “hard”
• Guaranteed Delivery
• Idempotent Receiver
• …
27
Service Routing
28
Service Routing – Just a mess
29
Service Routing – Just a mess
Service
A
Service
B
http://10.0.1.78
30
Service Routing – Container orchestration
Service
A
Service
B
http://10.0.1.78
kube-dns
10.0.1.78service-b
ingress
cluster
https://service-b.leanix.net
31
Service Routing – Container orchestration
• Local Service Routing
• Ingress Routing
• Ingress HTTPs Encryption
32
Service Routing – Router Model
Service
A
Service
B
cluster-westeurope cluster-eastus
Router
https://service-b.leanix.net
33
Service Routing – Router Model
• Global Service Routing
• Rate Limiting
• Caching
• Generic Error Pages
34
Service Routing – Service Mesh
Service
A
Service
B
cluster-westeurope cluster-eastus
proxy proxy
Gateway
Control
Plane
35
Service Routing – Service Mesh
• Ingress & Egress Encryption
• Traffic Optimisation
• Metrics
• Tracing
• Circuit Breaker
36
Organisational Considerations
37
“Speech is silver, silence is golden.”
Don Quijote
Organisational Considerations – Rule of Thumb
38
“Organizations which design systems [...]
produce designs which are copies of the
communication structures of these organizations.”
M. Conway
Organisational Considerations – Conway’s Law
39
Organisational Considerations – DDD
40
Organisational Considerations
41
Q & A

Communication in a Microservice Architecture