SlideShare a Scribd company logo
1 of 29
Patterns & Practices for Implementing
Event-driven Microservices
Nikhil Barthwal
@nikhilbarthwal
nikhilbarthwal@hotmail.com
www.nikhilbarthwal.com
Agenda (1/2)
• Motivations to move from Monolithic to Microservices
• Understanding the Distributed Data in Microservices
• Using Domain Driven Design for partitioning data
• Problems with Distributed Data
• Event Driven Microservices
2
Agenda (2/2)
• Communication Patterns for Microservices
• Event Sourcing
• Command Query Responsibility Segregation
• Introducing Sagas
• Resources for further reading
3
Monolithic: The old school approach …
• Large code base → Slower development
• More time to test & deploy
• Too much team interdependency
Database
Web Service
Easy to Develop, Test and Deploy …
But doesn’t scale!
4
Microservices: The Brave new world ...
• Smaller code base to understand & change
• Autonomous teams
• Faster testing & deployment
Assembly of Loosely
coupled services!
Image Source: https://www.slideshare.net/JontheBeach/distributed-sagas-a-protocol-for-coordinating-microservices
5
Loose Coupling → Distributed Data
Database per Service!
Faster Innovation!
Loosely coupled services
Reduces team interdependencies
Image Source: http://microservices.io/patterns/microservices.html
6
How to create service boundaries?
An approach to software development for complex needs
by connecting the implementation to an evolving model.
• Entities
• Value Objects
• Bounded Context
• Aggregates
Infrastructure Layer
Domain Layer
Application Layer
User Interface
Use Domain Driven Design (DDD)!
7
DDD: Aggregates
• Cluster of domain objects that
can be treated as a single unit
• One of its component is root
• All outside reference would
only go to the aggregate root
Domain Model
=
Collection of Aggregates
8
Data Partition Strategies: Use DDD
Aggregates
provide
boundaries
for
partition
9
Problems with Distributed Data
• How do we keep data consistent?
• How do we query scattered data?
10
Cannot use ACID Transactions
BEGIN TRANSACTION
SELECT ADDRESS FROM CUSTOMERS WHERE CUSTOMER_ID = XXX
SELECT PRICE FROM PRODUCTS WHERE CUSTOMER_ID = YYY
INSERT INTO ORDERS ...
COMMIT TRANSACTION
Private to Customer service
Private to Product service
11
Cannot use 2-Phase Commit
• Coordinator is a single point of failure
• Very chatty, with O(4n) messages, O(n2) with retries
• Locks would decrease throughputs
• Impacts availability (CAP theorem limitations)
Guarantees consistency, but …
12
Consistency Eventual Consistency
Availability
Partition (Network)
Eventual Consistency
Use Event Driven Microservice Architecture!
13
Event Driven Architecture
• Event occurs when a change happens in system
• All listeners get notified of the event, may take action
• Highly distributed/loosely coupled architecture
• Often used for asynchronous flows of information
14
Communication: Direct Messaging
Benefits:
• Easier implementation
• Better Error control
Drawbacks:
• Increased coupling
• Difficult to scale
Order Service
Product
Service
Customer
Service
Fulfillment
Service
Payment
Service
Shipping
Service
15
Communication: Via Message broker
Benefits:
• More scalable
• Increased Decoupling
Drawbacks:
• Requires Broker as Highly
Available component
Order Service
Product
Service
Customer
Service
Fulfillment
Service
Payment
Service
Shipping
Service
Message Broker
16
Communication Patterns
Request/Response
(synchronous)
Event-Driven
(asynchronous)
Tier-3: Little to No impact for Customer
Tier-2: Impacting Customers indirectly
Tier-1: Directly Customer facing
17
Event Sourcing: Introduction
• Modeling state changes as sequence of events
• Storing the event that could trigger the state change
• Enables rolling back to particular time in history
Examples:
18
Event Sourcing: Snapshots
Alternative to playing events: Snapshots
19
Event Sourcing: Multiple views
Image Source: https://www.confluent.io/wp-content/uploads/2016/09/Event-sourced-based-architecture.jpeg
Adding applications that process event …
but create a different view!
20
Event Sourcing: Benefits & Drawbacks
Benefits:
• 100% accurate audit logging
• Easy temporal queries
• Applications can process
same events but create views
Drawbacks:
• Adds Complexity
• No Strict Consistency
• Longer bootup times
(Snapshots can help)
21
Command Query Responsibility
Segregation
CQRS Pattern
Must for Event Sourcing!
Read
Write
Image Source: https://martinfowler.com/bliki/CQRS.html
22
CQRS: Benefits & Drawbacks
Benefits:
• Needed for Event Sourcing
• Improved separation of
concerns
• Supports scalable multiple
denormalized views
Drawbacks:
• Increased complexity
• Potential code duplication
• Replication lag as No Strict
Consistency
23
Sagas: Introduction
• Based on a 1987 paper
• Initially for a single database running
on one node
• Now adapted for distributed systems
with asynchrony and partial failure
24
Transaction & Rollback Transaction
• Every Transaction has a Rollback transaction
• This logic must be included in the service
T1 T2 T3
R1 R2 R3
Transactions →
Rollback Transactions →
25
Sagas: Example
This action initiates the saga
Check Credit Service Withdrawal Service Deposit Service
Deposit Check
Long running transactions …
use compensating actions to handle failures!
Does Sender have
enough money in his
account?
Withdraw the money
(unless it is on hold)?
Deposit the money
(unless account is
deactivated)?
26
Resources
• Using DDD to develop Microservices: https://www.infoq.com/news/2016/02/ddd-
microservices
• Overview of Saga Pattern: http://microservices.io/patterns/data/saga.html
• Distributed Sagas: https://www.slideshare.net/JontheBeach/distributed-sagas-a-
protocol-for-coordinating-microservices
27
Summary
• Microservices enable faster innovation
• DDD can used to define service boundaries
• Data is distributed which create challenges
• Use Event Driven Architecture for eventual consistency
• Understand Event Sourcing & CQRS
• Use Sagas to maintain data consistency across services
28
Thank you!
29
Nikhil Barthwal
Questions?
@nikhilbarthwal
nikhilbarthwal@hotmail.com
www.nikhilbarthwal.com

More Related Content

What's hot

What's hot (20)

Apigee Products Overview
Apigee Products OverviewApigee Products Overview
Apigee Products Overview
 
Microservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, KanbanMicroservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, Kanban
 
Your Journey to Cloud-Native Begins with DevOps, Microservices, and Containers
Your Journey to Cloud-Native Begins with DevOps, Microservices, and ContainersYour Journey to Cloud-Native Begins with DevOps, Microservices, and Containers
Your Journey to Cloud-Native Begins with DevOps, Microservices, and Containers
 
Why Microservices
Why MicroservicesWhy Microservices
Why Microservices
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
I Love APIs 2015: Microservices at Amazon
I Love APIs 2015: Microservices at AmazonI Love APIs 2015: Microservices at Amazon
I Love APIs 2015: Microservices at Amazon
 
Event driven architecture
Event driven architectureEvent driven architecture
Event driven architecture
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Microservices
MicroservicesMicroservices
Microservices
 
Microservices Decomposition Patterns
Microservices Decomposition PatternsMicroservices Decomposition Patterns
Microservices Decomposition Patterns
 
Why Microservice
Why Microservice Why Microservice
Why Microservice
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
 
Microservices With Istio Service Mesh
Microservices With Istio Service MeshMicroservices With Istio Service Mesh
Microservices With Istio Service Mesh
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services Architecture
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
DevOps-as-a-Service: Towards Automating the Automation
DevOps-as-a-Service: Towards Automating the AutomationDevOps-as-a-Service: Towards Automating the Automation
DevOps-as-a-Service: Towards Automating the Automation
 
Cloud Migration Strategy and Best Practices
Cloud Migration Strategy and Best PracticesCloud Migration Strategy and Best Practices
Cloud Migration Strategy and Best Practices
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
 

Similar to Event Driven Microservices architecture

Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)
Rick Hightower
 

Similar to Event Driven Microservices architecture (20)

Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)
 
Iot cloud service v2.0
Iot cloud service v2.0Iot cloud service v2.0
Iot cloud service v2.0
 
Microservices in Action
Microservices in ActionMicroservices in Action
Microservices in Action
 
Get the Message Across: Seamlessly Transport Data to Apps, Anywhere
Get the Message Across: Seamlessly Transport Data to Apps, AnywhereGet the Message Across: Seamlessly Transport Data to Apps, Anywhere
Get the Message Across: Seamlessly Transport Data to Apps, Anywhere
 
Concurrency at Scale: Evolution to Micro-Services
Concurrency at Scale:  Evolution to Micro-ServicesConcurrency at Scale:  Evolution to Micro-Services
Concurrency at Scale: Evolution to Micro-Services
 
The Need of Cloud-Native Application
The Need of Cloud-Native ApplicationThe Need of Cloud-Native Application
The Need of Cloud-Native Application
 
Do I Need A Service Mesh.pptx
Do I Need A Service Mesh.pptxDo I Need A Service Mesh.pptx
Do I Need A Service Mesh.pptx
 
Service Mesh Talk for CTO Forum
Service Mesh Talk for CTO ForumService Mesh Talk for CTO Forum
Service Mesh Talk for CTO Forum
 
Microservices session 1
Microservices session 1Microservices session 1
Microservices session 1
 
Redis and Kafka - Simplifying Advanced Design Patterns within Microservices A...
Redis and Kafka - Simplifying Advanced Design Patterns within Microservices A...Redis and Kafka - Simplifying Advanced Design Patterns within Microservices A...
Redis and Kafka - Simplifying Advanced Design Patterns within Microservices A...
 
Redis and Kafka - Advanced Microservices Design Patterns Simplified
Redis and Kafka - Advanced Microservices Design Patterns SimplifiedRedis and Kafka - Advanced Microservices Design Patterns Simplified
Redis and Kafka - Advanced Microservices Design Patterns Simplified
 
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
 
Patterns of Distributed Application Design
Patterns of Distributed Application DesignPatterns of Distributed Application Design
Patterns of Distributed Application Design
 
Cloud Application architecture styles
Cloud Application architecture styles Cloud Application architecture styles
Cloud Application architecture styles
 
Building data-driven microservices
Building data-driven microservicesBuilding data-driven microservices
Building data-driven microservices
 
Microservice intro
Microservice introMicroservice intro
Microservice intro
 
Tokyo Azure Meetup #5 - Microservices and Azure Service Fabric
Tokyo Azure Meetup #5 - Microservices and Azure Service FabricTokyo Azure Meetup #5 - Microservices and Azure Service Fabric
Tokyo Azure Meetup #5 - Microservices and Azure Service Fabric
 
Alex Thissen (Xpirit) - Een verschuiving in architectuur: op weg naar microse...
Alex Thissen (Xpirit) - Een verschuiving in architectuur: op weg naar microse...Alex Thissen (Xpirit) - Een verschuiving in architectuur: op weg naar microse...
Alex Thissen (Xpirit) - Een verschuiving in architectuur: op weg naar microse...
 
Database@Home : Data Driven Apps - Data-driven Microservices Architecture wit...
Database@Home : Data Driven Apps - Data-driven Microservices Architecture wit...Database@Home : Data Driven Apps - Data-driven Microservices Architecture wit...
Database@Home : Data Driven Apps - Data-driven Microservices Architecture wit...
 
BlockChain-1.pptx
BlockChain-1.pptxBlockChain-1.pptx
BlockChain-1.pptx
 

Recently uploaded

Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Recently uploaded (20)

Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 

Event Driven Microservices architecture

  • 1. Patterns & Practices for Implementing Event-driven Microservices Nikhil Barthwal @nikhilbarthwal nikhilbarthwal@hotmail.com www.nikhilbarthwal.com
  • 2. Agenda (1/2) • Motivations to move from Monolithic to Microservices • Understanding the Distributed Data in Microservices • Using Domain Driven Design for partitioning data • Problems with Distributed Data • Event Driven Microservices 2
  • 3. Agenda (2/2) • Communication Patterns for Microservices • Event Sourcing • Command Query Responsibility Segregation • Introducing Sagas • Resources for further reading 3
  • 4. Monolithic: The old school approach … • Large code base → Slower development • More time to test & deploy • Too much team interdependency Database Web Service Easy to Develop, Test and Deploy … But doesn’t scale! 4
  • 5. Microservices: The Brave new world ... • Smaller code base to understand & change • Autonomous teams • Faster testing & deployment Assembly of Loosely coupled services! Image Source: https://www.slideshare.net/JontheBeach/distributed-sagas-a-protocol-for-coordinating-microservices 5
  • 6. Loose Coupling → Distributed Data Database per Service! Faster Innovation! Loosely coupled services Reduces team interdependencies Image Source: http://microservices.io/patterns/microservices.html 6
  • 7. How to create service boundaries? An approach to software development for complex needs by connecting the implementation to an evolving model. • Entities • Value Objects • Bounded Context • Aggregates Infrastructure Layer Domain Layer Application Layer User Interface Use Domain Driven Design (DDD)! 7
  • 8. DDD: Aggregates • Cluster of domain objects that can be treated as a single unit • One of its component is root • All outside reference would only go to the aggregate root Domain Model = Collection of Aggregates 8
  • 9. Data Partition Strategies: Use DDD Aggregates provide boundaries for partition 9
  • 10. Problems with Distributed Data • How do we keep data consistent? • How do we query scattered data? 10
  • 11. Cannot use ACID Transactions BEGIN TRANSACTION SELECT ADDRESS FROM CUSTOMERS WHERE CUSTOMER_ID = XXX SELECT PRICE FROM PRODUCTS WHERE CUSTOMER_ID = YYY INSERT INTO ORDERS ... COMMIT TRANSACTION Private to Customer service Private to Product service 11
  • 12. Cannot use 2-Phase Commit • Coordinator is a single point of failure • Very chatty, with O(4n) messages, O(n2) with retries • Locks would decrease throughputs • Impacts availability (CAP theorem limitations) Guarantees consistency, but … 12
  • 13. Consistency Eventual Consistency Availability Partition (Network) Eventual Consistency Use Event Driven Microservice Architecture! 13
  • 14. Event Driven Architecture • Event occurs when a change happens in system • All listeners get notified of the event, may take action • Highly distributed/loosely coupled architecture • Often used for asynchronous flows of information 14
  • 15. Communication: Direct Messaging Benefits: • Easier implementation • Better Error control Drawbacks: • Increased coupling • Difficult to scale Order Service Product Service Customer Service Fulfillment Service Payment Service Shipping Service 15
  • 16. Communication: Via Message broker Benefits: • More scalable • Increased Decoupling Drawbacks: • Requires Broker as Highly Available component Order Service Product Service Customer Service Fulfillment Service Payment Service Shipping Service Message Broker 16
  • 17. Communication Patterns Request/Response (synchronous) Event-Driven (asynchronous) Tier-3: Little to No impact for Customer Tier-2: Impacting Customers indirectly Tier-1: Directly Customer facing 17
  • 18. Event Sourcing: Introduction • Modeling state changes as sequence of events • Storing the event that could trigger the state change • Enables rolling back to particular time in history Examples: 18
  • 19. Event Sourcing: Snapshots Alternative to playing events: Snapshots 19
  • 20. Event Sourcing: Multiple views Image Source: https://www.confluent.io/wp-content/uploads/2016/09/Event-sourced-based-architecture.jpeg Adding applications that process event … but create a different view! 20
  • 21. Event Sourcing: Benefits & Drawbacks Benefits: • 100% accurate audit logging • Easy temporal queries • Applications can process same events but create views Drawbacks: • Adds Complexity • No Strict Consistency • Longer bootup times (Snapshots can help) 21
  • 22. Command Query Responsibility Segregation CQRS Pattern Must for Event Sourcing! Read Write Image Source: https://martinfowler.com/bliki/CQRS.html 22
  • 23. CQRS: Benefits & Drawbacks Benefits: • Needed for Event Sourcing • Improved separation of concerns • Supports scalable multiple denormalized views Drawbacks: • Increased complexity • Potential code duplication • Replication lag as No Strict Consistency 23
  • 24. Sagas: Introduction • Based on a 1987 paper • Initially for a single database running on one node • Now adapted for distributed systems with asynchrony and partial failure 24
  • 25. Transaction & Rollback Transaction • Every Transaction has a Rollback transaction • This logic must be included in the service T1 T2 T3 R1 R2 R3 Transactions → Rollback Transactions → 25
  • 26. Sagas: Example This action initiates the saga Check Credit Service Withdrawal Service Deposit Service Deposit Check Long running transactions … use compensating actions to handle failures! Does Sender have enough money in his account? Withdraw the money (unless it is on hold)? Deposit the money (unless account is deactivated)? 26
  • 27. Resources • Using DDD to develop Microservices: https://www.infoq.com/news/2016/02/ddd- microservices • Overview of Saga Pattern: http://microservices.io/patterns/data/saga.html • Distributed Sagas: https://www.slideshare.net/JontheBeach/distributed-sagas-a- protocol-for-coordinating-microservices 27
  • 28. Summary • Microservices enable faster innovation • DDD can used to define service boundaries • Data is distributed which create challenges • Use Event Driven Architecture for eventual consistency • Understand Event Sourcing & CQRS • Use Sagas to maintain data consistency across services 28