SlideShare a Scribd company logo
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

PPTX
Event-driven microservices
PPTX
Event driven architecture
PDF
Event-Driven Architecture (EDA)
PPTX
Microservices Architecture Part 2 Event Sourcing and Saga
KEY
Event Driven Architecture
PPTX
Azure Application Modernization
PPTX
Monoliths and Microservices
PPTX
Microservice vs. Monolithic Architecture
Event-driven microservices
Event driven architecture
Event-Driven Architecture (EDA)
Microservices Architecture Part 2 Event Sourcing and Saga
Event Driven Architecture
Azure Application Modernization
Monoliths and Microservices
Microservice vs. Monolithic Architecture

What's hot (20)

PDF
Introduction to Event-Driven Architecture
PPTX
Introduction to microservices
PDF
CQRS + Event Sourcing
PDF
Microservice Architecture
PPT
Domain Driven Design (DDD)
PPTX
Introduction to Microservices
PPTX
Introduction To Microservices
PPTX
Microservices Part 3 Service Mesh and Kafka
PDF
Introduction to Event Driven Architecture
PPTX
Introduction to Microservices Patterns
PPTX
Microservices
PDF
Event Driven-Architecture from a Scalability perspective
PPTX
Domain Driven Design
PDF
Design patterns for microservice architecture
PDF
Event Driven Architecture
PDF
APIs in a Microservice Architecture
PDF
App Modernization
PDF
Understanding MicroSERVICE Architecture with Java & Spring Boot
PDF
Microservices architecture
PPTX
Introduction to microservices
Introduction to Event-Driven Architecture
Introduction to microservices
CQRS + Event Sourcing
Microservice Architecture
Domain Driven Design (DDD)
Introduction to Microservices
Introduction To Microservices
Microservices Part 3 Service Mesh and Kafka
Introduction to Event Driven Architecture
Introduction to Microservices Patterns
Microservices
Event Driven-Architecture from a Scalability perspective
Domain Driven Design
Design patterns for microservice architecture
Event Driven Architecture
APIs in a Microservice Architecture
App Modernization
Understanding MicroSERVICE Architecture with Java & Spring Boot
Microservices architecture
Introduction to microservices
Ad

Similar to Event Driven Microservices architecture (20)

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

Recently uploaded (20)

PPTX
OOP with Java - Java Introduction (Basics)
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Construction Project Organization Group 2.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
OOP with Java - Java Introduction (Basics)
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
UNIT 4 Total Quality Management .pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Lecture Notes Electrical Wiring System Components
Structs to JSON How Go Powers REST APIs.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Foundation to blockchain - A guide to Blockchain Tech
additive manufacturing of ss316l using mig welding
Strings in CPP - Strings in C++ are sequences of characters used to store and...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Construction Project Organization Group 2.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Embodied AI: Ushering in the Next Era of Intelligent Systems
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx

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