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

A pattern language for microservices - June 2021
A pattern language for microservices - June 2021 A pattern language for microservices - June 2021
A pattern language for microservices - June 2021 Chris Richardson
 
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREMicroservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREAraf Karsh Hamid
 
Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...
Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...
Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...Amazon Web Services
 
Domain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesDomain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesRadosław Maziarka
 
Agile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven DesignAgile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven DesignAraf Karsh Hamid
 
CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event SourcingMike Bild
 
The Architecture of an API Platform
The Architecture of an API PlatformThe Architecture of an API Platform
The Architecture of an API PlatformJohannes Ridderstedt
 
Microservices Architecture & Testing Strategies
Microservices Architecture & Testing StrategiesMicroservices Architecture & Testing Strategies
Microservices Architecture & Testing StrategiesAraf Karsh Hamid
 
From Monolithic to Microservices
From Monolithic to Microservices From Monolithic to Microservices
From Monolithic to Microservices Amazon Web Services
 
Melbourne Jan 2019 - Microservices adoption anti-patterns: Obstacles to decom...
Melbourne Jan 2019 - Microservices adoption anti-patterns: Obstacles to decom...Melbourne Jan 2019 - Microservices adoption anti-patterns: Obstacles to decom...
Melbourne Jan 2019 - Microservices adoption anti-patterns: Obstacles to decom...Chris Richardson
 
OReilly SACON London: Potholes in the road from monolithic hell: Microservice...
OReilly SACON London: Potholes in the road from monolithic hell: Microservice...OReilly SACON London: Potholes in the road from monolithic hell: Microservice...
OReilly SACON London: Potholes in the road from monolithic hell: Microservice...Chris Richardson
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservicesAnil Allewar
 
Microservices Technology Stack
Microservices Technology StackMicroservices Technology Stack
Microservices Technology StackEberhard Wolff
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQAraf Karsh Hamid
 
Kubernetes on AWS with Amazon EKS - MAD301 - New York AWS Summit
Kubernetes on AWS with Amazon EKS - MAD301 - New York AWS SummitKubernetes on AWS with Amazon EKS - MAD301 - New York AWS Summit
Kubernetes on AWS with Amazon EKS - MAD301 - New York AWS SummitAmazon Web Services
 

What's hot (20)

A pattern language for microservices - June 2021
A pattern language for microservices - June 2021 A pattern language for microservices - June 2021
A pattern language for microservices - June 2021
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
 
Guide to an API-first Strategy
Guide to an API-first StrategyGuide to an API-first Strategy
Guide to an API-first Strategy
 
App Modernization
App ModernizationApp Modernization
App Modernization
 
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREMicroservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SRE
 
Architecture for the API-enterprise
Architecture for the API-enterpriseArchitecture for the API-enterprise
Architecture for the API-enterprise
 
Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...
Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...
Introduction to the Well-Architected Framework and Tool - SVC208 - Anaheim AW...
 
Domain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesDomain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and Microservices
 
Agile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven DesignAgile, User Stories, Domain Driven Design
Agile, User Stories, Domain Driven Design
 
CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event Sourcing
 
The Architecture of an API Platform
The Architecture of an API PlatformThe Architecture of an API Platform
The Architecture of an API Platform
 
Microservices Architecture & Testing Strategies
Microservices Architecture & Testing StrategiesMicroservices Architecture & Testing Strategies
Microservices Architecture & Testing Strategies
 
From Monolithic to Microservices
From Monolithic to Microservices From Monolithic to Microservices
From Monolithic to Microservices
 
Cloud Migration: A How-To Guide
Cloud Migration: A How-To GuideCloud Migration: A How-To Guide
Cloud Migration: A How-To Guide
 
Melbourne Jan 2019 - Microservices adoption anti-patterns: Obstacles to decom...
Melbourne Jan 2019 - Microservices adoption anti-patterns: Obstacles to decom...Melbourne Jan 2019 - Microservices adoption anti-patterns: Obstacles to decom...
Melbourne Jan 2019 - Microservices adoption anti-patterns: Obstacles to decom...
 
OReilly SACON London: Potholes in the road from monolithic hell: Microservice...
OReilly SACON London: Potholes in the road from monolithic hell: Microservice...OReilly SACON London: Potholes in the road from monolithic hell: Microservice...
OReilly SACON London: Potholes in the road from monolithic hell: Microservice...
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
Microservices Technology Stack
Microservices Technology StackMicroservices Technology Stack
Microservices Technology Stack
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQ
 
Kubernetes on AWS with Amazon EKS - MAD301 - New York AWS Summit
Kubernetes on AWS with Amazon EKS - MAD301 - New York AWS SummitKubernetes on AWS with Amazon EKS - MAD301 - New York AWS Summit
Kubernetes on AWS with Amazon EKS - MAD301 - New York AWS Summit
 

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
 
Iot cloud service v2.0
Iot cloud service v2.0Iot cloud service v2.0
Iot cloud service v2.0Vinod Wilson
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to MicroservicesMahmoudZidan41
 
Microservices in Action
Microservices in ActionMicroservices in Action
Microservices in ActionBhagwat Kumar
 
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, AnywhereVMware Tanzu
 
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-ServicesRandy Shoup
 
The Need of Cloud-Native Application
The Need of Cloud-Native ApplicationThe Need of Cloud-Native Application
The Need of Cloud-Native ApplicationEmiliano Pecis
 
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.pptxPINGXIONG3
 
Service Mesh Talk for CTO Forum
Service Mesh Talk for CTO ForumService Mesh Talk for CTO Forum
Service Mesh Talk for CTO ForumRick Hightower
 
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 SimplifiedAllen Terleto
 
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...HostedbyConfluent
 
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...apidays
 
Patterns of Distributed Application Design
Patterns of Distributed Application DesignPatterns of Distributed Application Design
Patterns of Distributed Application DesignGlobalLogic Ukraine
 
Cloud Application architecture styles
Cloud Application architecture styles Cloud Application architecture styles
Cloud Application architecture styles Nilay Shrivastava
 
Building data-driven microservices
Building data-driven microservicesBuilding data-driven microservices
Building data-driven microservicesStreamlio
 
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 FabricTokyo Azure Meetup
 
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...AFAS Software
 
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...Tammy Bednar
 

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
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
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 - 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
 
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...
 
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...
 

Recently uploaded

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 

Recently uploaded (20)

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 

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