SlideShare a Scribd company logo
1 of 20
Download to read offline
Event Sourcing(ES)
&
Command Query Responsibility
Segregation(CQRS)
Zeldal Ozdemir
Lead Software Architect
https://www.linkedin.com/in/zeldalozdemir
@zeldalozdemir
DevOps & MicroServices
Consultancy
We consult you move towards Containerization, Automated
Provisioning, Deployment/Release Automation, Test Automation,
Performance Tuning and moving to Cloud …
kloia.co.uk kloia.com
blog.kloia.com
@kloia_com
microservices.kloia.com
daas.kloia.com testautomation.kloia.com
MicroServices
● Multidimensional scaling
● Improves fault isolation
● Eliminates long-term commitment to a single
technology stack
● Independent deployments
● Technology diversity
https://cdn.wp.nginx.com/wp-content/uploads/2015/05/intro-microservices.png
MicroService Challenges
● Operational Complexity
● Distribution
● Consistency/Eventual Consistency
*https://cdn.wp.nginx.com/wp-content/uploads/2016/04/Richardson-microservices-part1-2_microservices-architecture.png
Consistency
● Problem: Decentralized Data Management
● No silver bullet
● 2PC is not a good solution for Microservices
● Need consistent(Eventual) operations between Multiple Microservices over different resources
○ Ex: Order/Payment/Mail/Shipment etc
M1 M2 M2 M3 M4 M5
Ext
ServiceRDBMS NoSQL Graph
Operation
Entity A Version2 Entity B Version2 External Version2Entity C Version1
Normal Coding ...
Event Driven Design
● Create and publish event whenever data change happens
● Endpoints can be triggered via rest or Events
● Event Channel to make communication between microservices
Event Channel
Order
Microservice
Payment
Microservice
Shipment
Microservice
Mail
Microservice
OrderCreated
OrderProcessed
OrderProcessed
PaymentProcessed PaymentProcessed
Entities vs Events
Account 1, +50
Account 1, +150
Account 2, +300
Account 1, -100
Account
Number
Balance Description
1 100 Bank A
2 500 Bank B
….
Table: Account
Events: Account
….
Account 2, +200
….
Event Sourcing
● No single entity record
● Entity consist of or calculated with Events
● It's like Audit log
● Easily negate failed commands for operations
Stock
Microservice
Stock1 Created 10 items
Stock1 Sold 2 item
Stock1 Sold 5 item
Stock2 Created 100 items
StockCreatedRecord
Events together = Stock1 3 Items
Event Channel
StockCreatedEvent
ItemSoldRecord
OrderEvents
Stock Command
Stock1 Sold 5 item
Event Sourcing (Missing)
● How to Update Data (Events?)
● How to Query Data
○ Do we need Entity or View?
Stock1 Sold 2 item
Stock1 Sold 5 item
Stock2 Created 100 items
Calculations….
Stock1 Created 10 items
Stock1 Sold 2 item
Stock2 Created 100 items
Stock1 Sold 5 item
Stock1 Sold 5 item
Microservice
Command Query Responsibility Segregation(CQRS)
● Different sides for Read/Write
● Commands side is based
Aggregates/Aggregate Roots
● Aggregate is bounded concept of
Business value (may span multiple
microservice)
Store
Command Model
Query Model
Applied: Event Sourcing
● Cassandra: as Event DB
○ Collect Events to describe Entities
● Kafka: Event Channel
○ Publish Consume events
● For Events between microservices we'll use Event
publish/subscribe
Order1 Shipped
Order2 Created
Event Records for Order1= EntityOrder1
Order1 Created
Order1 Processed
Order
Microservice
Payment
Microservice
Event ChannelEvent
Channel
Microservice
Applied: CQRS
● Command Side: Commands are described state change for Entity
● Query Side: Calculates result of recorded events for each entity record when queried.
● Snapshot: Reduces number of events applied in Query
Cassandra
or RDBMS
(Events,
Snapshots)
Store Events
Command 1
Command 2
Command 2
Query
Query Events
Calculate States
Commands
Queries
Snapshots (CQRS/ES)
● Reduce events calculated in Query Side
● All Finished(means Completed in time, Finished Aggregates etc) will be calculated and stored
Stock1 Created 10 items
Stock1 Sold 2 item
Stock1 Sold 5 item
Stock1 Sold 3 items
Stock1 Added 15 item
Events together = Stock1 15 Items
Snapshot Table
Event
Channel
Stock1 Entity Stock
Microservice
Listen
DEMO
● Order Service - Payment Service - Stock Service
○ Order Create
○ Order Process
■ Reduce Stock
■ Issue Payment
● See Evented DB
● See Command and Query
● See Operation Store (Other examples besides happy path will be added)
● https://github.com/kloiasoft/eventapis -> api and samples
CreateStockCommandDto
StockCreatedEvent
/stock/v1/create
CreateOrderCommandDto
OrderCreatedEvent
/order/v1/create
Stock Service
Order Service
DEMO
ProcessOrderCommandDto
ReserveStockEvent
/order/v1/process
ReserveStockEvent
StockReservedEvent
StockReservedEvent
PaymentProcessEvent
PaymentProcessEvent
PaymentSuccessEvent
PaymentSuccessEvent
OrderPaidEvent
Order Service
Stock Service
Order Service
Payment Service Order Service
References
● https://martinfowler.com/articles/microservice-trade-offs.html
● http://microservices.io/patterns/data/event-sourcing.html
● https://blog.sebastian-daschner.com/entries/event_sourcing_cqrs_video_course
Questions?
Zeldal Ozdemir
Lead Software Architect
https://www.linkedin.com/in/zeldalozdemir
@zeldalozdemir
http://microservices.kloia.com
https://github.com/kloiasoft/eventapis

More Related Content

What's hot

Running a Massively Parallel Self-serve Distributed Data System At Scale
Running a Massively Parallel Self-serve Distributed Data System At ScaleRunning a Massively Parallel Self-serve Distributed Data System At Scale
Running a Massively Parallel Self-serve Distributed Data System At Scale
Zhenzhong Xu
 

What's hot (20)

SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
 
Cloud Native Patterns Using AWS
Cloud Native Patterns Using AWSCloud Native Patterns Using AWS
Cloud Native Patterns Using AWS
 
CICD Azure DevOps
CICD Azure DevOpsCICD Azure DevOps
CICD Azure DevOps
 
OpenWhisk: Where Did My Servers Go?
OpenWhisk: Where Did My Servers Go?OpenWhisk: Where Did My Servers Go?
OpenWhisk: Where Did My Servers Go?
 
Microservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got HereMicroservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got Here
 
Live Event Debugging With ksqlDB at Reddit | Hannah Hagen and Paul Kiernan, R...
Live Event Debugging With ksqlDB at Reddit | Hannah Hagen and Paul Kiernan, R...Live Event Debugging With ksqlDB at Reddit | Hannah Hagen and Paul Kiernan, R...
Live Event Debugging With ksqlDB at Reddit | Hannah Hagen and Paul Kiernan, R...
 
Developing reliable applications with .net core and AKS
Developing reliable applications with .net core and AKSDeveloping reliable applications with .net core and AKS
Developing reliable applications with .net core and AKS
 
Live Event Debugging With ksqlDB at Reddit | Hannah Hagen and Paul Kiernan, R...
Live Event Debugging With ksqlDB at Reddit | Hannah Hagen and Paul Kiernan, R...Live Event Debugging With ksqlDB at Reddit | Hannah Hagen and Paul Kiernan, R...
Live Event Debugging With ksqlDB at Reddit | Hannah Hagen and Paul Kiernan, R...
 
Cncf event driven autoscaling with keda
Cncf   event driven autoscaling with kedaCncf   event driven autoscaling with keda
Cncf event driven autoscaling with keda
 
Managing add-ons across clusters
Managing add-ons across clustersManaging add-ons across clusters
Managing add-ons across clusters
 
Detecting Real-Time Financial Fraud with Cloudflow on Kubernetes
Detecting Real-Time Financial Fraud with Cloudflow on KubernetesDetecting Real-Time Financial Fraud with Cloudflow on Kubernetes
Detecting Real-Time Financial Fraud with Cloudflow on Kubernetes
 
Microservices
MicroservicesMicroservices
Microservices
 
Microservices - Event-driven & the hidden landmines
Microservices - Event-driven & the hidden landminesMicroservices - Event-driven & the hidden landmines
Microservices - Event-driven & the hidden landmines
 
What's new in Web Development with ASP.NET Core 2.1
What's new in Web Development with ASP.NET Core 2.1What's new in Web Development with ASP.NET Core 2.1
What's new in Web Development with ASP.NET Core 2.1
 
Application Autoscaling Made Easy with Kubernetes Event-Driven Autoscaling (K...
Application Autoscaling Made Easy with Kubernetes Event-Driven Autoscaling (K...Application Autoscaling Made Easy with Kubernetes Event-Driven Autoscaling (K...
Application Autoscaling Made Easy with Kubernetes Event-Driven Autoscaling (K...
 
Recap: OSCON 2015
Recap: OSCON 2015Recap: OSCON 2015
Recap: OSCON 2015
 
Running a Massively Parallel Self-serve Distributed Data System At Scale
Running a Massively Parallel Self-serve Distributed Data System At ScaleRunning a Massively Parallel Self-serve Distributed Data System At Scale
Running a Massively Parallel Self-serve Distributed Data System At Scale
 
20160317 lagom sf scala
20160317 lagom sf scala20160317 lagom sf scala
20160317 lagom sf scala
 
Real World Event Sourcing and CQRS
Real World Event Sourcing and CQRSReal World Event Sourcing and CQRS
Real World Event Sourcing and CQRS
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDD
 

Similar to ES and CQRS workshop

Similar to ES and CQRS workshop (20)

Advance Microservice Patterns - Event Souring , CQRS
Advance Microservice Patterns - Event Souring , CQRSAdvance Microservice Patterns - Event Souring , CQRS
Advance Microservice Patterns - Event Souring , CQRS
 
SRV409 Deep Dive on Microservices and Docker
SRV409 Deep Dive on Microservices and DockerSRV409 Deep Dive on Microservices and Docker
SRV409 Deep Dive on Microservices and Docker
 
Challenges In Modern Application
Challenges In Modern ApplicationChallenges In Modern Application
Challenges In Modern Application
 
Microservice
MicroserviceMicroservice
Microservice
 
Enterprise Cloud Security
Enterprise Cloud SecurityEnterprise Cloud Security
Enterprise Cloud Security
 
Microservices + Events + Docker = A Perfect Trio by Docker Captain Chris Rich...
Microservices + Events + Docker = A Perfect Trio by Docker Captain Chris Rich...Microservices + Events + Docker = A Perfect Trio by Docker Captain Chris Rich...
Microservices + Events + Docker = A Perfect Trio by Docker Captain Chris Rich...
 
Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)
 
DevOps, Microservices and Serverless Architecture
DevOps, Microservices and Serverless ArchitectureDevOps, Microservices and Serverless Architecture
DevOps, Microservices and Serverless Architecture
 
Ultimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on KubernetesUltimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on Kubernetes
 
Enabling Microservices Frameworks to Solve Business Problems
Enabling Microservices Frameworks to Solve  Business ProblemsEnabling Microservices Frameworks to Solve  Business Problems
Enabling Microservices Frameworks to Solve Business Problems
 
Service Fabric – building tomorrows applications today
Service Fabric – building tomorrows applications todayService Fabric – building tomorrows applications today
Service Fabric – building tomorrows applications today
 
Shaping serverless architecture with domain driven design patterns
Shaping serverless architecture with domain driven design patternsShaping serverless architecture with domain driven design patterns
Shaping serverless architecture with domain driven design patterns
 
Shaping serverless architecture with domain driven design patterns
Shaping serverless architecture with domain driven design patternsShaping serverless architecture with domain driven design patterns
Shaping serverless architecture with domain driven design patterns
 
Deconstructing Monoliths with Domain Driven Design
Deconstructing Monoliths with Domain Driven DesignDeconstructing Monoliths with Domain Driven Design
Deconstructing Monoliths with Domain Driven Design
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
Designing CloudStack Clouds
Designing CloudStack CloudsDesigning CloudStack Clouds
Designing CloudStack Clouds
 
Microservices Architecture - Cloud Native Apps
Microservices Architecture - Cloud Native AppsMicroservices Architecture - Cloud Native Apps
Microservices Architecture - Cloud Native Apps
 
Shaping serverless architecture with domain driven design patterns - py web-il
Shaping serverless architecture with domain driven design patterns - py web-ilShaping serverless architecture with domain driven design patterns - py web-il
Shaping serverless architecture with domain driven design patterns - py web-il
 
XebiCon'17 : AxonFramework @ SGCIB (our experience) : (CQRS, Eventsourcing, A...
XebiCon'17 : AxonFramework @ SGCIB (our experience) : (CQRS, Eventsourcing, A...XebiCon'17 : AxonFramework @ SGCIB (our experience) : (CQRS, Eventsourcing, A...
XebiCon'17 : AxonFramework @ SGCIB (our experience) : (CQRS, Eventsourcing, A...
 
Silicon Valley CloudStack User Group - Designing CloudStack Clouds
Silicon Valley CloudStack User Group - Designing CloudStack CloudsSilicon Valley CloudStack User Group - Designing CloudStack Clouds
Silicon Valley CloudStack User Group - Designing CloudStack Clouds
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

ES and CQRS workshop