When you have a microservices architectural style, much of the communication between components is done over the network. In order to achieve what microservices promise, this communication must happen in a loosely coupled manner. In this session, we discuss some fundamental application integration patterns mostly based on messaging, and we connect them to real-world use cases in a microservices scenario. We also highlight the benefits that asynchronous messaging can have over REST APIs for communication between microservices.
6. Potential drawbacks of
synchronous systems
Synchronous systems are tightly
coupled
A problem in a synchronous
downstream dependency has
immediate impact on the upstream
callers
Retries from upstream callers can all
too easily fan out and amplify
problems
Photo: Dirk Fröhner
8. Message exchange
One way Request response
Message
channel
Receiver
No response expected
Synchronous vs. fire-and-forget
Response expected
Return address
Correlation ID
Sender
Message
channel
Responder
Requester
Message
channel
9. Message channels
Point-to-point (queue) Publish-subscribe (topic)
Consumed by one receiver
Easy to scale
Flatten peak loads
Consumed by all subscribers
Durable subscriber
Receivers
Sender
Queue
Subscribers
Publisher
Topic
10. Message channels
Point-to-point (queue) Publish-subscribe (topic)
AWS service for queue functionality:
Amazon Simple Queue Services (Amazon SQS)
Serverless & cloud-native
AWS service for topic functionality:
Amazon Simple Notification Service (Amazon SNS)
Serverless & cloud-native
Receivers
Sender
Subscribers
Publisher
Amazon SQS Amazon SNS
11. Message channels
Point-to-point (queue) Publish-subscribe (topic)
AWS service for queue functionality (nonserverless):
Amazon MQ (managed Apache Active MQ)
For applications constrained to protocols like JMS,
AMQP, etc.
AWS service for topic functionality (nonserverless):
Amazon MQ (managed Apache Active MQ)
For applications constrained to protocols like JMS,
AMQP, etc.
Receivers
Sender
Subscribers
Publisher
Amazon MQ Amazon MQ
15. Message channels
FIFO queue Message groups
Guaranteed ordering Messages grouped by discriminator attribute
Example: Amazon SQS with sender provided message
Group IDs: No further consumption as long as messages
with particular message group IDs are invisible
Queue
Receiver
Sender
Receivers
Sender
Queue
Order
16. Message channels
FIFO queue Message groups
Guaranteed ordering Messages grouped by discriminator attribute
Example: Amazon SQS with sender provided message
Group IDs: No further consumption as long as messages
with particular message group IDs are invisible
Queue
Receiver
Sender
Receivers
Sender
Queue
Order
17. Message channels
FIFO queue Message groups
Guaranteed ordering Messages grouped by discriminator attribute
Example: Amazon SQS with sender provided message
Group IDs: No further consumption as long as messages
with particular message group IDs are invisible
Queue
Receiver
Sender
Receivers
Sender
Queue
Order
18. Message channels
FIFO queue Message groups
Guaranteed ordering Messages grouped by discriminator attribute
Example: Amazon SQS with sender provided message
Group IDs: No further consumption as long as messages
with particular message group IDs are invisible
Queue
Receiver
Sender
Receivers
Sender
Queue
Order
19. Message channels
FIFO queue Message groups
Guaranteed ordering Messages grouped by discriminator attribute
Example: Amazon SQS with sender provided message
Group IDs: No further consumption as long as messages
with particular message group IDs are invisible
Queue
Receiver
Sender
Receivers
Sender
Queue
Order
20. Message channels
FIFO queue Message groups
Guaranteed ordering Messages grouped by discriminator attribute
Example: Amazon SQS with sender provided message
Group IDs: No further consumption as long as messages
with particular message group IDs are invisible
Queue
Receiver
Sender
Receivers
Sender
Queue
Order
21. Message channels
FIFO queue Message groups
Guaranteed ordering Messages grouped by discriminator attribute
Example: Amazon SQS with sender provided message
Group IDs: No further consumption as long as messages
with particular message group IDs are invisible
Queue
Receiver
Sender
Receivers
Sender
Queue
Order
22. Message channels
FIFO queue Message groups
Guaranteed ordering Messages grouped by discriminator attribute
Example: Amazon SQS with sender provided message
Group IDs: No further consumption as long as messages
with particular message group IDs are invisible
Queue
Receiver
Sender
Receivers
Sender
Queue
Order
23. Message channels
FIFO queue Message groups
Guaranteed ordering Messages grouped by discriminator attribute
Example: Amazon SQS with sender provided message
Group IDs: No further consumption as long as messages
with particular message group IDs are invisible
Queue
Receiver
Sender
Receivers
Sender
Queue
Order!
24. Message channels
Message delivery QoS
At least once
At most once
Exactly once
Queue
Receiver
Sender
Exactly once? Well!
How to deal with a situation where the message was
consumed but never acknowledged?
→ Your systems still have to be able to
handle duplicate messages
→ Messages should be processed in
an idempotent manner
Choose between at least once or at most once
25. Message routing
Message filter Recipient list
Receive only a relevant subset of messages
Controlled by subscriber
Publisher remains completely unaware
Send only a relevant subset of messages to a subscriber
Controlled by publisher or separate component
Potentially adds coupling
Subscribers
Publisher
Subscribers
Publisher
Topic
color = blue
color = yellow
Recipient
list
27. Message routing
Pipes and filters
Event triggers chain of processing steps (“filters”)
Knowledge of destination for next steps is wired into each filter
Event source Pipe Filter Filter
Pipe Pipe Result target
…
Filter
Step 1 Step 2 Step n
28. Message routing
Saga orchestration
Event triggers orchestrated workflow
Knowledge of workflow is externalized into orchestrator component, as well as for potential rollback
Workflow participants remain as loosely coupled as possible
Processor
Processor
Processor
Processor
Event source Orchestrator
…
Step 1
Step 2 Step n-1
Step n
Result target
29. Message routing
Saga orchestration
AWS service for saga orchestration (serverless):
AWS Step Functions
Processor
Processor
Processor
Processor
Event source Orchestrator
…
Step 1
Step 2 Step n-1
Step n
Result target
33. Use case: Submit a ride completion
AWS Cloud
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
Unicorn
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
management
service
34. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
Unicorn
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
management
service
35. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
Interested in rides with
fare >= x
distance >= y
Rides
store
Unicorn
Wild Rydes
unicorn app
https://...
submit-ride-completion
Unicorn
management
service
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
36. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
Unicorn
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
Management
Service
Interested in rides with
fare >= x
distance >= y
Integration via database?
37. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
Unicorn
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
Management
Service
Integration via database?
Oh my!
Interested in rides with
fare >= x
distance >= y
38. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
Unicorn
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
Management
Service
Integration via REST APIs?
Interested in rides with
fare >= x
distance >= y
39. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
Unicorn
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
Management
Service
Integration via REST APIs?
Absolutely, but …
Interested in rides with
fare >= x
distance >= y
40. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
https://...
https://...
https://...
https://...
https://...
Recipient list
Unicorn
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
management
service
41. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
https://...
https://...
https://...
https://...
https://...
Recipient list service
Unicorn
Request
distribution
service
https://...
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
management
service
42. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
https://...
https://...
https://...
https://...
https://...
Self-managed filtering
Unicorn
Request
distribution
service
https://...
Wild Rydes
Unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
management
service
Interested in rides with
fare >= x
distance >= y
43. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
https://...
https://...
https://...
https://...
https://...
Self-managed filtering
Unicorn
Request
Distribution
Service
https://...
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
Management
Service
Interested in rides with
fare >= x
distance >= y
Integration via messaging?
Absolutely!
44. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
Publish-subscribe (topic)
Unicorn
Ride
completion
topic
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
management
service
45. Use case: Submit a ride completion
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
SNS message filter:
fare >= x
distance >= y
Message filter
Unicorn
Ride
completion
topic
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
management
service
46. Use case: Submit a ride completion
Unicorn
AWS Cloud
Customer
notification
service
Customer
accounting
service
Customer
loyalty
service
Data lake
ingestion
service
Extraordinary
rides
service
{
"from": "...",
"to": "...",
"duration": "...",
"distance": "...",
"customer": "...",
"fare": "..."
}
Ride
completion
topic
Topic-queue-chaining
Wild Rydes
unicorn app
https://...
submit-ride-completion
201 Created
Location: ...
Content-Location: ...
{
<cmpl-ride-repr>
}
Rides
store
Unicorn
management
service
SNS message filter:
fare >= x
distance >= y
70. Resources
AWS blogs and other content on messaging and application integration
https://aws.amazon.com/messaging/
https://aws.amazon.com/event-driven-architecture/
https://aws.amazon.com/blogs/compute/category/messaging/
The German-language AWS-Podcast
Keep in mind
Loose coupling is always better than lousy coupling
bit.ly/aws-podcast
71. Vielen Dank für’s Zuschauen!
Dennis Traub, Developer Advocate, Amazon Web Services
Twitter: @dtraub
Podcast: bit.ly/aws-podcast