Communication in a microservice architecture
Irina Scurtu
• Romania Based
• Software Architect @Endava
• Organizer of DotNet Iasi user group
• I teach .Net
@irina_scurtu
Agenda
▪ Monoliths& Microservices
▪ HTTP calls – sync & async
▪ RPC
▪ Messaging
▪ Queues
▪ Message Brokers
▪ Actor Model
MONOLITH
MONOLITH
▪ Self-contained
▪ Single codebase
▪ Single deploy unit
▪ Easy life for developers
▪ Dependencies are in your code
▪ Single technology stack
MONOLITH
▪ All or nothing deploys
▪ Downtimes
▪ Long build times
▪ ~ 0 continuous delivery
▪ Hard to test
Scaling the MONOLITH
Scale up
2
1 5
3
monolith syndrome?
MICROSERVICE?
▪ it’s that thing that is not a monolith
▪ With it’s own database
▪ Easy to deploy
▪ Standalone
▪ Easy to maintain
Is it?
MICROSERVICES?
▪ Introduces complexity
▪ Cascading effects in case of failure
▪ Need to monitor them closely
Principles of microservices
▪ Modeled around business concepts
▪ Culture of automation
▪ Independently deployable
▪ Isolate failure
2
1 5
3
Independent
units
Now we have
▪ Loosely coupled components
▪ Small codebases
▪ Easy to deploy and scale
▪ Reusable components
▪ Multiple databases
2
1 5
3
Do you know?
▪ Amazon calls 150 APIs to Build a Page
▪ Netflix services about 5 billions API calls/day
▪ 99.7% are internal
HTTP API CALLS
HTTP CALLS
S
Response
H
HTTP CALLS
S H
HTTP CALLS
“It’s perfectly
fine to use sync
HTTP Calls”
•Timeouts
•Availability
•Going back to coupling?
•You can loose requests
•Need to have a retry
mechanism
“It’s perfectly fine to use async HTTP Calls”
▪ You’ll have exactly the same issues as with sync calls
▪ Distribute load?!
▪ You can serve more request
▪ You can serve the requests faster
HTTP General Notes
▪ Sync by nature
▪ Make a TCP connection for each request
▪ No retry out of the box
▪ No delivery guarantees
▪ No routing without a Service Discovery or configuration
▪ Good for public facing APIs
▪ Familiar
▪ Easy to debug
Challenges
▪Service Discovery
▪Retry policies
▪Circuit breakers
▪Timeouts
▪Routing
▪Tracing
RPC
RPC
▪A kind of API call
▪Done through a message broker
▪Ties systems together but preserves their
encapsulations
RPC
S H
Queues
Request
RPC
S
Queues
Response
Request
H
Gain vs Loss
• You don’t lose the requests
• You can add more handler instances
• You can ‘apparently’ spread the load
• You can process more requests
▪ Need to match the request
to the response
▪ You wait for a response =>
sync
Messaging
Messaging
▪Gives you loosely coupled integration
▪Doesn’t require both systems to be up
▪Messages ca be transformed in transit
▪Messaging systems trade consistency for availability
▪You don’t loose messages
Messaging
ASYNC Queue Processing
S H
Queues
RequestRequest
Queue
S
Queues
Response
Request
Request
Request
H
Queue
Response
Response
With a DB
S
Queues
Response
Request
Request
Request
H
Storage
With a DB
s
Queues
Response
Request
Request
Request
H
Storage
Gains
• Is a reaction to the problems
of distributed sys
• Process more requests
• Process request faster
• Don’t lose requests
▪ You move the potential
issues to another
subsystem (DB in our case)
▪ Eventual consistency
remains a problem
Loss
Gain vs Loss
▪ Connection is scarce
▪ Batch process the message
▪ Use a semaphore to process them in batches
WHY USE A MESSAGE BROKER with MSA ?
Agility
❑Faster development
❑No integration process
❑Teams have ownership and full understanding of the
codebase
❑You can switch technologies if needed
Resiliency
❑You don’t have a single point of failure
Scalability
Scale up
Scale out
Performance
Increased Throughput
38 267 vs 3500
ElasticityScale down to
reduce costs
A lot of ‘ilities’
❑Reliability
❑Flexibility
❑Distribution
❑Increased Throughput
❑Scalability
❑Elasticity
❑Performance
❑Agility
Tools/Frameworks/Systems
Data Types
Queues
Actor Model
Message Brokers
What options do I have?
plenty
Many more
Queues
• Useful for point to point communication
• Messages are ordered and timestamped
• Pull-mode
Actor model
▪Actors are processes that encapsulate behaviour
▪Actors are more than message consumers
▪Can delegate and create new actors
▪Can supervise children
▪At most once delivery
Message Brokers
▪One process sends a message to a named queue or topic
▪One or many consumers
▪Handles connections and disconnections very well
▪One-way data flow or request/response model –”ReplyTo”
▪Dead-letter queue concept
Message Brokers
▪Lightweight
▪Queues are FIFO
▪Supports AMPQ protocol
▪Easy to use, fast
▪At-least-once delivery
AMPQ General Notes
▪ Async by nature
▪ Guaranteed message delivery
▪ At-least once, exactly once, at most once delivery
▪ No DNS resolve
▪ Programmatic routing
▪ Retries out-of-the box
▪ Ack, Nack out of the box
▪ Concept of “channel”
Topic Exchange
References
In Summary
Messages are great
show them some
THANK YOU
@irina_scurtu
Q&A

Rigadevdays - Communication in a microservice architecture