SlideShare a Scribd company logo
1 of 41
EVENT SOURCING, CQRS, AND
EVENT DRIVEN SYSTEMS
EVENT SOURCING AND CQRS: A PATTERN FOR MICROSERVICES
WHO AM I?
• Savvas Kleanthous
Head of Engineering @ ParcelVision Ltd
• Experience with DDD & ES & CQRS
• Twitter account: @skleanthous
INTRO TO EVENT SOURCING
INTRO TO EVENT SOURCING AND COMPARISON TO OTHER STORAGE FORMS
WHAT IS EVENT SOURCING
* Only simple to explain - a lot of hidden complexity in practice!
BANK ACCOUNT EXAMPLE
• Your bank account
• Classic example
• “Accountants don’t use pencils”
BATTLE OF THE STORE MECHANISMS
USING A NON-CONTRIVED EXAMPLE
RELATIONAL STORE 
NORMAL FORM
• The shipment is our entity
• Low duplication
• Joins are necessary
DOCUMENT STORE
• Loading means to deserialize
• Load by Id  better performance
• Context is lost since document form is a static model
• Complex versioning due to implicit schema
EVENT SOURCE
• Business logic creates contextful domain
events instead of editing state
• Loaded by id
• Cannot serve complex queries directly
INTRO TO CQRS
WHAT IS CQRS, AND ITS VARIATIONS
CQRS – WHAT IS IT AND WHY
• Command Query Responsibility Segregation
• Split paths for write and read (possibly separate stores)
• Often needed in order to support different use cases
EVENT DRIVEN SYSTEMS
WHAT ARE THEY?
• (Distributed) systems that communicate through events
• Reactive systems
• Easy to scale
• Lead to loosely coupled services
CQRSES a very good option for
implementing event driven systems
BENEFITS OF CQRSES
REASONS THAT SHOULD MAKE YOU CONSIDER CQRSES FOR YOUR NEXT SOLUTION
1. You have a built-in audit log
•The ultimate source of truth
2. Domain events speak the language of your
SME’s
•Analysis of domain events leads to breakthroughs
3. Much easier deploymentrollback
•No downtime deployments
4. Lowest possible latencies
5. Separation of responsibilities between
readwrite models
•Independent evolution of contract and domain
6. Temporal and Bitemporal queries not only
feasible, but actually easy too
7. Debugging live is very easy
•Easy as taking a snapshot and pushing command
in
And many more
DISADVANTAGES OF CQRSES
WHAT MAY BE THE PROBLEMS THAT YOU MAY BE FACING?
1. Unfamiliar way of thinking
2. Increased accidental complexity
3. In async the best consistency you can get:
•In theory eventual serializability
•In practice causal
4. No 2PC in async CQRS or across aggregate
boundaries
LESSONS FROM THE TRENCHES
SOME FIRST TIPS WHEN YOU START ON YOUR JOURNEY
1. INVOLVE YOUR SME’S EARLY AND A LOT
• Do event storming
• Let the SME’s do your work for you
• If you don’t, you will still learn the domain on your own but at a great
cost
2. MAKE EVENTS SPECIFIC AND CONTEXTFUL
• Rule of thumb: Fat enough so that consumers are consistent, but not
any more than that.
• Events should be specific about what happened (contextful)
• Events that are too fat or too thin may lead to duplication of logic
3. EVENT VERSIONING
1. When possible, you should rely on weak (de)serializationdynamic
nature of language
! Explicitly version your event regardless
2. Upconvert event inline when loading
3. Final option: event migration (although a nuclear one)
4. ADD METADATA TO YOUR MESSAGES
• Message id
• Correlation id
• Causation id
• Type – prefer a property even in OO
• Version
5. CQRS: START WITH SYNC WRITE AND READ
MODEL UPDATES
• Still decouple writes and reads by splitting the two paths
• This limits eventual consistency issues significantly – causal
consistency “built-in”
6. DISTINGUISH BETWEEN DOMAIN AND
PUBLIC EVENTS
DOMAIN
• Used for storage and domain
communication
• Meaningful internally to domain
• Needs to be fat enough to
guarantee consistency in domain
listeners
PUBLIC
• Used to inform public of a
change
• Meaningful as a contract – Can
change independently of
changes in domain
• Needs to be fat enough to
guarantee consistency of
external listeners
7. YOU DON’T NEED A CQRS OR ES
FRAMEWORK
• Current state is just a left-fold of events
• Just make sure you don’t have side-effects on load – only change
entity state when replaying events
8. DON’T BE AFRAID OF MULTIPLE DATA
STORES
• For example:
• ES domain entities
• Mongo Db for view models
• SQL db for BI and reporting
QA
I’LL BE AVAILABLE FOR A CHAT AFTERWARDS. PLEASE APPROACH ME AND LETS HAVE A CHAT.
COMMON QUESTIONSCOMMENTS
• “Unique emails for users in CQRS” – most asked question ever
• “How do you delete” – “How do you fix an error in an event”
• “Event sourcing is complex”
• “Testing is more complicated when doing ES””How do you test”
• “Event sourcing is slow”
• “Data must be huge”
THANK YOU!
Twitter account: @SKleanthous

More Related Content

What's hot

Building large scalable mission critical business applications on the web
Building large scalable mission critical business applications on the webBuilding large scalable mission critical business applications on the web
Building large scalable mission critical business applications on the webMaurice De Beijer [MVP]
 
EXTREME CHATOPS USING KUBERNETES AND WATSON
EXTREME CHATOPS USING KUBERNETES AND WATSONEXTREME CHATOPS USING KUBERNETES AND WATSON
EXTREME CHATOPS USING KUBERNETES AND WATSONJeff Sloyer
 
More Than Just URL Mappers - Proxies for Observation and Control
More Than Just URL Mappers - Proxies for Observation and ControlMore Than Just URL Mappers - Proxies for Observation and Control
More Than Just URL Mappers - Proxies for Observation and ControlMark McBride
 
A Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceA Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceValeri Karpov
 
Customer-centric Metrics
Customer-centric MetricsCustomer-centric Metrics
Customer-centric MetricsMark McBride
 
A idea of Powerful WooCmmerce Site
A idea of Powerful WooCmmerce SiteA idea of Powerful WooCmmerce Site
A idea of Powerful WooCmmerce Site秀高 岡本
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developersAidan Casey
 
Cloud fail scaling to infinity but not beyond
Cloud fail   scaling to infinity but not beyondCloud fail   scaling to infinity but not beyond
Cloud fail scaling to infinity but not beyondKunal Johar
 
Introduction to Django-Celery and Supervisor
Introduction to Django-Celery and SupervisorIntroduction to Django-Celery and Supervisor
Introduction to Django-Celery and SupervisorSuresh Kumar
 
Rendering Websites of the Future
Rendering Websites of the FutureRendering Websites of the Future
Rendering Websites of the FutureMoboom
 
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and Woe
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and WoeAltitude San Francisco 2018: HTTP/2 Tales: Discovery and Woe
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and WoeFastly
 
The 7 deadly sins of micro services
The 7 deadly sins of micro servicesThe 7 deadly sins of micro services
The 7 deadly sins of micro servicesAidan Casey
 
Journey towards serverless infrastructure
Journey towards serverless infrastructureJourney towards serverless infrastructure
Journey towards serverless infrastructureVille Seppänen
 
Journey to a multi-tenant e commerce solution in the cloud with Kubernetes - ...
Journey to a multi-tenant e commerce solution in the cloud with Kubernetes - ...Journey to a multi-tenant e commerce solution in the cloud with Kubernetes - ...
Journey to a multi-tenant e commerce solution in the cloud with Kubernetes - ...Vlad Stanescu
 
Kudu voodoo slideshare
Kudu voodoo   slideshareKudu voodoo   slideshare
Kudu voodoo slideshareAidan Casey
 
Engage 2019: Modernising Your Domino and XPages Applications
Engage 2019: Modernising Your Domino and XPages Applications Engage 2019: Modernising Your Domino and XPages Applications
Engage 2019: Modernising Your Domino and XPages Applications Paul Withers
 
An Ops Primer to Productionalizing Datameer
An Ops Primer to Productionalizing DatameerAn Ops Primer to Productionalizing Datameer
An Ops Primer to Productionalizing DatameerColin Brown
 
Performance: Key Elements to Consider in the Cloud - RightScale Compute 2013
Performance: Key Elements to Consider in the Cloud - RightScale Compute 2013Performance: Key Elements to Consider in the Cloud - RightScale Compute 2013
Performance: Key Elements to Consider in the Cloud - RightScale Compute 2013RightScale
 

What's hot (18)

Building large scalable mission critical business applications on the web
Building large scalable mission critical business applications on the webBuilding large scalable mission critical business applications on the web
Building large scalable mission critical business applications on the web
 
EXTREME CHATOPS USING KUBERNETES AND WATSON
EXTREME CHATOPS USING KUBERNETES AND WATSONEXTREME CHATOPS USING KUBERNETES AND WATSON
EXTREME CHATOPS USING KUBERNETES AND WATSON
 
More Than Just URL Mappers - Proxies for Observation and Control
More Than Just URL Mappers - Proxies for Observation and ControlMore Than Just URL Mappers - Proxies for Observation and Control
More Than Just URL Mappers - Proxies for Observation and Control
 
A Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceA Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-Service
 
Customer-centric Metrics
Customer-centric MetricsCustomer-centric Metrics
Customer-centric Metrics
 
A idea of Powerful WooCmmerce Site
A idea of Powerful WooCmmerce SiteA idea of Powerful WooCmmerce Site
A idea of Powerful WooCmmerce Site
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
 
Cloud fail scaling to infinity but not beyond
Cloud fail   scaling to infinity but not beyondCloud fail   scaling to infinity but not beyond
Cloud fail scaling to infinity but not beyond
 
Introduction to Django-Celery and Supervisor
Introduction to Django-Celery and SupervisorIntroduction to Django-Celery and Supervisor
Introduction to Django-Celery and Supervisor
 
Rendering Websites of the Future
Rendering Websites of the FutureRendering Websites of the Future
Rendering Websites of the Future
 
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and Woe
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and WoeAltitude San Francisco 2018: HTTP/2 Tales: Discovery and Woe
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and Woe
 
The 7 deadly sins of micro services
The 7 deadly sins of micro servicesThe 7 deadly sins of micro services
The 7 deadly sins of micro services
 
Journey towards serverless infrastructure
Journey towards serverless infrastructureJourney towards serverless infrastructure
Journey towards serverless infrastructure
 
Journey to a multi-tenant e commerce solution in the cloud with Kubernetes - ...
Journey to a multi-tenant e commerce solution in the cloud with Kubernetes - ...Journey to a multi-tenant e commerce solution in the cloud with Kubernetes - ...
Journey to a multi-tenant e commerce solution in the cloud with Kubernetes - ...
 
Kudu voodoo slideshare
Kudu voodoo   slideshareKudu voodoo   slideshare
Kudu voodoo slideshare
 
Engage 2019: Modernising Your Domino and XPages Applications
Engage 2019: Modernising Your Domino and XPages Applications Engage 2019: Modernising Your Domino and XPages Applications
Engage 2019: Modernising Your Domino and XPages Applications
 
An Ops Primer to Productionalizing Datameer
An Ops Primer to Productionalizing DatameerAn Ops Primer to Productionalizing Datameer
An Ops Primer to Productionalizing Datameer
 
Performance: Key Elements to Consider in the Cloud - RightScale Compute 2013
Performance: Key Elements to Consider in the Cloud - RightScale Compute 2013Performance: Key Elements to Consider in the Cloud - RightScale Compute 2013
Performance: Key Elements to Consider in the Cloud - RightScale Compute 2013
 

Similar to Intro to event sourcing and CQRS

Lessons learned from applying Event sourcing and CQRS
Lessons learned from applying Event sourcing and CQRSLessons learned from applying Event sourcing and CQRS
Lessons learned from applying Event sourcing and CQRSSavvas Kleanthous
 
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learnedRebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learnedKacper Gunia
 
When small problems become big problems
When small problems become big problemsWhen small problems become big problems
When small problems become big problemsAdrian Cole
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationAndrew Siemer
 
Top 10 DBA Mistakes on Microsoft SQL Server
Top 10 DBA Mistakes on Microsoft SQL ServerTop 10 DBA Mistakes on Microsoft SQL Server
Top 10 DBA Mistakes on Microsoft SQL ServerKevin Kline
 
Scaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHPScaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHP120bi
 
Scaling High Traffic Web Applications
Scaling High Traffic Web ApplicationsScaling High Traffic Web Applications
Scaling High Traffic Web ApplicationsAchievers Tech
 
SQL Server Wait Types Everyone Should Know
SQL Server Wait Types Everyone Should KnowSQL Server Wait Types Everyone Should Know
SQL Server Wait Types Everyone Should KnowDean Richards
 
Microservices - opportunities, dilemmas and problems
Microservices - opportunities, dilemmas and problemsMicroservices - opportunities, dilemmas and problems
Microservices - opportunities, dilemmas and problemsŁukasz Sowa
 
DevCon13 System Administration Basics
DevCon13 System Administration BasicsDevCon13 System Administration Basics
DevCon13 System Administration Basicssysnickm
 
Behavior-Driven Development (BDD) Testing with Apache Spark with Aaron Colcor...
Behavior-Driven Development (BDD) Testing with Apache Spark with Aaron Colcor...Behavior-Driven Development (BDD) Testing with Apache Spark with Aaron Colcor...
Behavior-Driven Development (BDD) Testing with Apache Spark with Aaron Colcor...Databricks
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureThomas Jaskula
 
Rigadevdays - Communication in a microservice architecture
Rigadevdays  - Communication in a microservice architectureRigadevdays  - Communication in a microservice architecture
Rigadevdays - Communication in a microservice architectureIrina Scurtu
 
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedRoman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedMSDEVMTL
 
Face Off Domino vs Exchange On Premises
Face Off Domino vs Exchange On PremisesFace Off Domino vs Exchange On Premises
Face Off Domino vs Exchange On PremisesGabriella Davis
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock Steve Barbour
 
Service Architectures at Scale
Service Architectures at ScaleService Architectures at Scale
Service Architectures at ScaleRandy Shoup
 
Observability – the good, the bad, and the ugly
Observability – the good, the bad, and the uglyObservability – the good, the bad, and the ugly
Observability – the good, the bad, and the uglyTimetrix
 
Microservices pros and cons - houston tech fest
Microservices pros and cons - houston tech festMicroservices pros and cons - houston tech fest
Microservices pros and cons - houston tech festAndrew Siemer
 
Relational data modeling trends for transactional applications
Relational data modeling trends for transactional applicationsRelational data modeling trends for transactional applications
Relational data modeling trends for transactional applicationsIke Ellis
 

Similar to Intro to event sourcing and CQRS (20)

Lessons learned from applying Event sourcing and CQRS
Lessons learned from applying Event sourcing and CQRSLessons learned from applying Event sourcing and CQRS
Lessons learned from applying Event sourcing and CQRS
 
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learnedRebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learned
 
When small problems become big problems
When small problems become big problemsWhen small problems become big problems
When small problems become big problems
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregation
 
Top 10 DBA Mistakes on Microsoft SQL Server
Top 10 DBA Mistakes on Microsoft SQL ServerTop 10 DBA Mistakes on Microsoft SQL Server
Top 10 DBA Mistakes on Microsoft SQL Server
 
Scaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHPScaling a High Traffic Web Application: Our Journey from Java to PHP
Scaling a High Traffic Web Application: Our Journey from Java to PHP
 
Scaling High Traffic Web Applications
Scaling High Traffic Web ApplicationsScaling High Traffic Web Applications
Scaling High Traffic Web Applications
 
SQL Server Wait Types Everyone Should Know
SQL Server Wait Types Everyone Should KnowSQL Server Wait Types Everyone Should Know
SQL Server Wait Types Everyone Should Know
 
Microservices - opportunities, dilemmas and problems
Microservices - opportunities, dilemmas and problemsMicroservices - opportunities, dilemmas and problems
Microservices - opportunities, dilemmas and problems
 
DevCon13 System Administration Basics
DevCon13 System Administration BasicsDevCon13 System Administration Basics
DevCon13 System Administration Basics
 
Behavior-Driven Development (BDD) Testing with Apache Spark with Aaron Colcor...
Behavior-Driven Development (BDD) Testing with Apache Spark with Aaron Colcor...Behavior-Driven Development (BDD) Testing with Apache Spark with Aaron Colcor...
Behavior-Driven Development (BDD) Testing with Apache Spark with Aaron Colcor...
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
Rigadevdays - Communication in a microservice architecture
Rigadevdays  - Communication in a microservice architectureRigadevdays  - Communication in a microservice architecture
Rigadevdays - Communication in a microservice architecture
 
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedRoman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
 
Face Off Domino vs Exchange On Premises
Face Off Domino vs Exchange On PremisesFace Off Domino vs Exchange On Premises
Face Off Domino vs Exchange On Premises
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock
 
Service Architectures at Scale
Service Architectures at ScaleService Architectures at Scale
Service Architectures at Scale
 
Observability – the good, the bad, and the ugly
Observability – the good, the bad, and the uglyObservability – the good, the bad, and the ugly
Observability – the good, the bad, and the ugly
 
Microservices pros and cons - houston tech fest
Microservices pros and cons - houston tech festMicroservices pros and cons - houston tech fest
Microservices pros and cons - houston tech fest
 
Relational data modeling trends for transactional applications
Relational data modeling trends for transactional applicationsRelational data modeling trends for transactional applications
Relational data modeling trends for transactional applications
 

Recently uploaded

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 

Recently uploaded (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 

Intro to event sourcing and CQRS

  • 1. EVENT SOURCING, CQRS, AND EVENT DRIVEN SYSTEMS EVENT SOURCING AND CQRS: A PATTERN FOR MICROSERVICES
  • 2. WHO AM I? • Savvas Kleanthous Head of Engineering @ ParcelVision Ltd • Experience with DDD & ES & CQRS • Twitter account: @skleanthous
  • 3. INTRO TO EVENT SOURCING INTRO TO EVENT SOURCING AND COMPARISON TO OTHER STORAGE FORMS
  • 4. WHAT IS EVENT SOURCING * Only simple to explain - a lot of hidden complexity in practice!
  • 5. BANK ACCOUNT EXAMPLE • Your bank account • Classic example • “Accountants don’t use pencils”
  • 6. BATTLE OF THE STORE MECHANISMS USING A NON-CONTRIVED EXAMPLE
  • 7. RELATIONAL STORE NORMAL FORM • The shipment is our entity • Low duplication • Joins are necessary
  • 8. DOCUMENT STORE • Loading means to deserialize • Load by Id  better performance • Context is lost since document form is a static model • Complex versioning due to implicit schema
  • 9. EVENT SOURCE • Business logic creates contextful domain events instead of editing state • Loaded by id • Cannot serve complex queries directly
  • 10. INTRO TO CQRS WHAT IS CQRS, AND ITS VARIATIONS
  • 11. CQRS – WHAT IS IT AND WHY • Command Query Responsibility Segregation • Split paths for write and read (possibly separate stores) • Often needed in order to support different use cases
  • 12.
  • 14. WHAT ARE THEY? • (Distributed) systems that communicate through events • Reactive systems • Easy to scale • Lead to loosely coupled services
  • 15. CQRSES a very good option for implementing event driven systems
  • 16. BENEFITS OF CQRSES REASONS THAT SHOULD MAKE YOU CONSIDER CQRSES FOR YOUR NEXT SOLUTION
  • 17. 1. You have a built-in audit log •The ultimate source of truth
  • 18. 2. Domain events speak the language of your SME’s •Analysis of domain events leads to breakthroughs
  • 19. 3. Much easier deploymentrollback •No downtime deployments
  • 20. 4. Lowest possible latencies
  • 21. 5. Separation of responsibilities between readwrite models •Independent evolution of contract and domain
  • 22. 6. Temporal and Bitemporal queries not only feasible, but actually easy too
  • 23. 7. Debugging live is very easy •Easy as taking a snapshot and pushing command in
  • 25. DISADVANTAGES OF CQRSES WHAT MAY BE THE PROBLEMS THAT YOU MAY BE FACING?
  • 26. 1. Unfamiliar way of thinking
  • 28. 3. In async the best consistency you can get: •In theory eventual serializability •In practice causal
  • 29. 4. No 2PC in async CQRS or across aggregate boundaries
  • 30. LESSONS FROM THE TRENCHES SOME FIRST TIPS WHEN YOU START ON YOUR JOURNEY
  • 31. 1. INVOLVE YOUR SME’S EARLY AND A LOT • Do event storming • Let the SME’s do your work for you • If you don’t, you will still learn the domain on your own but at a great cost
  • 32. 2. MAKE EVENTS SPECIFIC AND CONTEXTFUL • Rule of thumb: Fat enough so that consumers are consistent, but not any more than that. • Events should be specific about what happened (contextful) • Events that are too fat or too thin may lead to duplication of logic
  • 33. 3. EVENT VERSIONING 1. When possible, you should rely on weak (de)serializationdynamic nature of language ! Explicitly version your event regardless 2. Upconvert event inline when loading 3. Final option: event migration (although a nuclear one)
  • 34. 4. ADD METADATA TO YOUR MESSAGES • Message id • Correlation id • Causation id • Type – prefer a property even in OO • Version
  • 35. 5. CQRS: START WITH SYNC WRITE AND READ MODEL UPDATES • Still decouple writes and reads by splitting the two paths • This limits eventual consistency issues significantly – causal consistency “built-in”
  • 36. 6. DISTINGUISH BETWEEN DOMAIN AND PUBLIC EVENTS DOMAIN • Used for storage and domain communication • Meaningful internally to domain • Needs to be fat enough to guarantee consistency in domain listeners PUBLIC • Used to inform public of a change • Meaningful as a contract – Can change independently of changes in domain • Needs to be fat enough to guarantee consistency of external listeners
  • 37. 7. YOU DON’T NEED A CQRS OR ES FRAMEWORK • Current state is just a left-fold of events • Just make sure you don’t have side-effects on load – only change entity state when replaying events
  • 38. 8. DON’T BE AFRAID OF MULTIPLE DATA STORES • For example: • ES domain entities • Mongo Db for view models • SQL db for BI and reporting
  • 39. QA I’LL BE AVAILABLE FOR A CHAT AFTERWARDS. PLEASE APPROACH ME AND LETS HAVE A CHAT.
  • 40. COMMON QUESTIONSCOMMENTS • “Unique emails for users in CQRS” – most asked question ever • “How do you delete” – “How do you fix an error in an event” • “Event sourcing is complex” • “Testing is more complicated when doing ES””How do you test” • “Event sourcing is slow” • “Data must be huge”

Editor's Notes

  1. Still the easier way to explain. Open: set name, no initial value Deposit: add 5 Deposit add 10 AmountFromTransferReceived add 5 AmountWithdrawn subtract 15 ==> have 5
  2. And I haven’t event touched on legs.
  3. When doing a change, all context is lost. All you have is THIS IS THE STATE. Problem requirement: Find all shipments that are to be delivered to Manchester
  4. No info lost: From instrumentation around processing processing time = event timestamp – command timestamp Just reading names of event you can see what happened  you can react on changes
  5. There are many MANY ways to implement CQRS. Log shipping from db to another system that processes it asynchronously to create another projections _is_ a form of CQRS. Different use cases  needs of customers\users like need to query by destination with autocomplete of values Equivalent of CQS (method can either change state and return void or return value and not mutate object) on a larger scale Business logic\model and read projection generation separated Very simple architectural pattern to explain but it has hidden complexity Hitting read store should have no side effect
  6. Loosely coupled because of: reference autonomy, time autonomy Scaling: sharding based on events Inherently eventually consistent Reactive by nature “Tell don’t ask”
  7. Very high cohesion with ES and DDD Conceptually event driven systems are an extension of ES principles to systems Conceptual extension => In ES domain events encapsulate immutable facts and aggregates\observers react to it Events are central and highly important in both cases and all design and function is around them
  8. No information is lost ever A lot of info can also be picked up from metadata Causation analysis Correlation across external stimuli Security trail (who done it)
  9. You can easily validate your understanding of the domain by validating the events with your SME’s SME’s can be utilized to do analysis for you :) Event analysis often leads to breakthroughs Immutability of events are sometimes forced by domain Immutability of events are often in understanding of SME
  10. Separate read models and different db’s allows you to choose whichever db provides the best experience at the cost of eventual consistency
  11. Loosely coupled services Model-purpose mismatch
  12. Bitemporal queries answer: - Events that apply after a certain date. This is built-in! What was the state of X a month ago (with correction events) What did we know about X a month ago (without correction events)
  13. ES often implicitly required in some industries (usually for auditing purposes) Very low coupling of deployed services High synergy with stream processing. Same logic\process
  14. Mental shift is needed to start thinking of persistence in events Mental shift is needed to start considering split models, potentially multiple models for reading Both of these are a journey with multiple steps, but eventually surpass-able
  15. Read your own writes is doable but painful
  16. (you can cheat in some event stores, but that is violating the transactional guarantee of the aggregates)
  17. Event storming from Alberto Brandolini SME’s will do your work for you. SME’s can help you with scope of your aggregates. If events make sense for them they can tell you the info they need to contain If events don’t make sense to SME’s you’re potentially adding artificial complexity to your system. Also, you may be exposing implementation details to outside consumers increasing coupling Wrongly scoped events can lead to big problems. Wrong aggregate boundaries can lead to big problems. If SME’s aren’t directly involved at least make sure that events make sense to SME’s and\or Product owner If SME’s aren’t involved you end up with wrongly sized events and wrong aggregate boundaries. Both are huge technical debts that you need to avoid
  18. Fatter events  duplication of business logic to discover what happened and react on it Thinner events  duplication of state machine to discover when a certain transition actually happened When events are smaller they are far easier to maintain and version in the future When they are contectful it is easy to know how to apply them. Additional information is passed through the name Also think of this: if it makes sense for the domain expert, your domain model matches their mental model and this alignment is extremely valuable. Their type should be meaningful to the relevant domain expert or SME Prefer more granular events over “god” events Do not go overboard with granularity – consult your SME
  19. Additive changes to your events Load an event with it’s version, Translate it manually to new version and then apply it to entity Same as 2, but for all events in the stream before entity is loaded\hydrated. Usually done during deployments
  20. Message id is nothing special just an id that uniquely identifies message Correlation id gets assigned once and then any and all messages get their correlation id assigned from the message that caused it Causation id gets assigned from message id of previous message that caused it. Can trace everything that happened in the system Type: what command or event is this? PaymentMade, TransferAmount, UpdateFromNewScans etc. Version of current message-> useful during deserialization
  21. This is simpler to understand, debug and… … easier to start with and easy to migrate to async once needed If you have different stores for read & write eventual consistency will be there anyway but possibly very limited since read stores can be updated before publishing of event happens Since read stores get updated before event is published then you have causal consistency for sure Easy to understand since it’s a synchronous model without causal consistency or ordering issues. Decouple writes and reads so that you can scale reads independently and you have an easier path to asynd cqrs if you find out you need it further down the line
  22. This is mostly important for communication and service versioning. Consuming domain events in other microservices may result in coupling to another services internal implementations (since it’s used for persistence) Domain events should be fat  they contain all necessary info to change the aggregate state\be applied but also to update read model without the need to make remote calls Public events can be thinner if you’re concerned with versioning, but can be fat to achieve decoupling Idempotency important in both cases, maybe slightly more so in domain case to make denormalizers easier
  23. Projections can be as simple as mapping of events You can store events in any db Storing events in: SQL server: Id column should be Aggregate Id + Version (count of events) Document store: A document with a collection of events Event store -> easier option Kafka -> may not be the best default, but if it is there and works for your needs use it When loading only apply on state! You don’t want to re-send emails etc whenever you load entity
  24. It is fine to use any combination of SQL stores, document stores, graph dbs, in-memory caches etc. ALWAYS listen to your Domain experts and requirements. Meet the requirement first Almost always, a couple of ms of inconsistency between read-write models is perfectly fine Queries may need to be fast -> use document stores to load full view model by id Complex queries may be better suited with Graph db’s. Populate them asynchronously through events: still fast to process, querying won’t impact rest of the system SQL stores can have complex indexes useful for BI In memory caches also a good option to decrease latency
  25. Unique XXX -> Do you need immediate consistency? If yes: you don’t need to ES everything! Use SQL or whatever makes sense for your requirements. Also: you can synchronously hit the ES if you need\makes sense. Deleting is more convoluted. Use “reset events” that rest the state to start. Update – use correction event. You mustn’t really edit the stream directly. Event migration is a safer option Event sourcing is not more complex. CQRS may introduce a complexity but you could not use CQRS. Also it is a tradeoff (easier migrations etc) Testing is very simple: command in, events out. Events check both behaviour and persistence It is very fast for small number of events. Definitely faster than SQL with joins (so always) or graph dbs. As events grow you could use snapshotting Huge data? How many Gb per second are we speaking about here?