SlideShare a Scribd company logo
1 of 22
07 July 2018 | Dasith Wijes
Event Sourcing
Event sourcing workflow
> Audit trails, Sumerian clay tablets and Blockchain
> Advantages over storing state
> Simple form of CQRS, contrasting it to a monolith
> Command side and read side
> How event sourcing fits in
Command Query Responsibility Segregation
> Shopping catalogue example
What is Domain Driven Design?
“In order to create good software, you have to
know what that software is all about. You cannot
create a banking software system unless you have
a good understanding of what banking is all about,
one must understand the domain of banking”
– Eric Evans
What is Event Sourcing?
Use an append-only store to record the full
series of events that describe actions taken on
data in a domain, rather than storing just the
current state.
Event Sourcing Examples
Sumerian clay
tablets
Transactional systems (i.e. Stock)
Accounting ledger
Database transaction log
Source control systems
Blockchain = Event Sourcing + Public Store + Decentralized
Scenario
You are the team lead of a small team of developers at a
start-up company building an Amazon competitor. Your
product is gaining traction and you expect a lot more users
in the next few months.
• The customers are complaining of slow response times &
crashes during peak times.
• Come up with a plan to make your application more
performant.
• Think about your deployment and scaling strategy.
We Have a Monolith
A monolithic application has a single code
base and a single build system which
builds and deploys the entire application
(and dependencies). Modules may be
divided as business features or technical
features.
Scenario Continued
Monolithic Application
 Big and complex code base
 Hard onboarding process for new
developers
 Hidden coupling and complexity
 Single build pipeline
 Release cycle is long
 Scaling up is very expensive
 Performance issues
 Application is offline when
deploying new version
Symptoms A solution path
• CRM
• Online Store
• Supplier
• Stock
• Accounts
• Reports
 Identify which parts of the system
are used the most
 Logically separate those parts
 Deploying the separated parts
independently
 Scale the required parts
independently
Thought Experiment
You are managing a coffee shop and have 2
employees who work alternate shifts.
• Anna who is a great barista but is slow at
operating the cash register.
• Sam who doesn’t make great coffee but is fast at
operating the register.
• More people are coming to the store and you
want a strategy to reduce wait times for
customers.
CQRS to the Rescue
“CQRS stands for Command Query
Responsibility Segregation. At its heart is the
notion that you can use a different model to
update information than the model you use to
read information”
– Martin Fowler
Simple CQRS Solution
Without CQRS
ShoppingCatalogueService
+ AddItem(itemInfo): void
+ UpdateItem(item): void
+ RemoveItem(item): void
+ Search(criteria): Decimal
+ Browse(category): items[]
+ SetDiscount(item): void
With CQRS
ShoppingCatalogueReadService
+ Search(criteria): Decimal
+ Browse(category): items[]
ShoppingCatalogueWriteService
+ AddItem(itemInfo): void
+ UpdateItem(item): void
+ RemoveItem(item): void
+ SetDiscount(item): void
MonolithicApplication
Updated Scenario
You have successfully managed to logically separate your
Online-Store module to writes (commands) and reads
(queries).
• It’s become clear that “data models” used for write vs
read are different.
• Investigate whether it is possible to deploy those as
separate applications and have separate data models/
storage mechanisms.
CQRS Solution Evolved
What if we build and deploy them
independently?
ShoppingCatalogueReadService
+ Search(criteria): Decimal
+ Browse(category): items[]
ShoppingCatalogueWriteService
+ AddItem(itemInfo): void
+ UpdateItem(item): void
+ RemoveItem(item): void
+ SetDiscount(item): void
We get a solution that has…
 Independent scalability
 Manageable codebases
But what about…
 Shared storage?
 Transactions + Locks?
 Dependency availability?
CQRS Solution Using Event Sourcing
ShoppingCatalogueReadService
+ Search(criteria): Decimal
+ Browse(category): items[]
ShoppingCatalogueWriteService
+ AddItem(itemInfo): void
+ UpdateItem(item): void
+ RemoveItem(item): void
+ SetDiscount(item): void
Domain Events
Event Database
(Append Only)
Read Model Database
Subscribers
listening to events
Queue
Storing an event
publishes it to the
queue
Query
Command
Update Read
Model
A Bit More About
Event Sourcing And CQRS
 Event Sourcing is naturally CQRS
 But… not all CQRS solutions are event sourced
 CQRS is not an end goal
 Event Sourcing is a natural functional model
State GetNewState(State oldState, Event lastEvent) {
return (oldState + lastEvent);
}
Key Benefits of Event Sourcing
• Ability to track all changes done to the domain
 Rebuild your state to a point in time
• Less coupling between read and write sides
 Reduction of impedance mismatch
 Many world views
 Independent scalability
• Easier to debug
Some Pitfalls When Using Event Sourcing
• Unfamiliar concept to many
• External systems / dependencies
• Eventual consistency
• Event schema changes
What Did We Learn?
• Event Sourcing And Command Query
Responsibility Segregation
• What they are?
• When to apply them?
• Key advantages
• Disadvantages
• Basic event sourcing workflow
Want More?
• My blog: dasith.me
• ES ‘reference framework’ for .NET: NEventLite
(Search: NEventLite on NuGet or GitHub)
• Domain Driven Design – Eric Evans
• Greg Young on YouTube
• DDD/CQRS Google Group
• ES database: eventstore.org
Thank you!
@dasiths
dasith.me

More Related Content

What's hot

247 overviewmongodbevening-bangalore
247 overviewmongodbevening-bangalore247 overviewmongodbevening-bangalore
247 overviewmongodbevening-bangalore
MongoDB APAC
 

What's hot (15)

Solving Business Problems with Machine Learning in SAP Analytics Cloud
Solving Business Problems with Machine Learning in SAP Analytics CloudSolving Business Problems with Machine Learning in SAP Analytics Cloud
Solving Business Problems with Machine Learning in SAP Analytics Cloud
 
Open Blueprint for Real-Time Analytics with In-Stream Processing
Open Blueprint for Real-Time Analytics with In-Stream ProcessingOpen Blueprint for Real-Time Analytics with In-Stream Processing
Open Blueprint for Real-Time Analytics with In-Stream Processing
 
247 overviewmongodbevening-bangalore
247 overviewmongodbevening-bangalore247 overviewmongodbevening-bangalore
247 overviewmongodbevening-bangalore
 
Introduction to Big Data using AWS Services
Introduction to Big Data using AWS ServicesIntroduction to Big Data using AWS Services
Introduction to Big Data using AWS Services
 
Customer Event Hub – a modern Customer 360° view with DataStax Enterprise (DSE)
Customer Event Hub – a modern Customer 360° view with DataStax Enterprise (DSE) Customer Event Hub – a modern Customer 360° view with DataStax Enterprise (DSE)
Customer Event Hub – a modern Customer 360° view with DataStax Enterprise (DSE)
 
Workshop 2: Building a streaming data platform on AWS
Workshop 2: Building a streaming data platform on AWSWorkshop 2: Building a streaming data platform on AWS
Workshop 2: Building a streaming data platform on AWS
 
7 Benefits Of QuickBooks EnterPrise Hosting
7 Benefits Of QuickBooks EnterPrise Hosting7 Benefits Of QuickBooks EnterPrise Hosting
7 Benefits Of QuickBooks EnterPrise Hosting
 
How to get Real-Time Value from your IoT Data - Datastax
How to get Real-Time Value from your IoT Data - DatastaxHow to get Real-Time Value from your IoT Data - Datastax
How to get Real-Time Value from your IoT Data - Datastax
 
Managing Smart Meter with DataStax DSE
Managing Smart Meter with DataStax DSEManaging Smart Meter with DataStax DSE
Managing Smart Meter with DataStax DSE
 
Denodo DataFest 2017: Enabling Single View of Entities with Microservices
Denodo DataFest 2017: Enabling Single View of Entities with MicroservicesDenodo DataFest 2017: Enabling Single View of Entities with Microservices
Denodo DataFest 2017: Enabling Single View of Entities with Microservices
 
Kogo
KogoKogo
Kogo
 
Denodo DataFest 2017: Modern Data Architectures Need Real-time Data Delivery
Denodo DataFest 2017: Modern Data Architectures Need Real-time Data DeliveryDenodo DataFest 2017: Modern Data Architectures Need Real-time Data Delivery
Denodo DataFest 2017: Modern Data Architectures Need Real-time Data Delivery
 
Hybrid IT: Legg Mason
Hybrid IT: Legg MasonHybrid IT: Legg Mason
Hybrid IT: Legg Mason
 
WSO2Con USA 2017: Discover Data That Matters: Deep Dive into WSO2 Analytics
WSO2Con USA 2017: Discover Data That Matters: Deep Dive into WSO2 AnalyticsWSO2Con USA 2017: Discover Data That Matters: Deep Dive into WSO2 Analytics
WSO2Con USA 2017: Discover Data That Matters: Deep Dive into WSO2 Analytics
 
[WSO2Con EU 2017] Deriving Insights for Your Digital Business with Analytics
[WSO2Con EU 2017] Deriving Insights for Your Digital Business with Analytics[WSO2Con EU 2017] Deriving Insights for Your Digital Business with Analytics
[WSO2Con EU 2017] Deriving Insights for Your Digital Business with Analytics
 

Similar to LevelsConf 2018 Event Sourcing - Dasith Wijesiriwardena

Digital_IOT_(Microsoft_Solution).pdf
Digital_IOT_(Microsoft_Solution).pdfDigital_IOT_(Microsoft_Solution).pdf
Digital_IOT_(Microsoft_Solution).pdf
ssuserd23711
 
클라우드에서의 데이터 웨어하우징 & 비즈니스 인텔리전스
클라우드에서의 데이터 웨어하우징 & 비즈니스 인텔리전스클라우드에서의 데이터 웨어하우징 & 비즈니스 인텔리전스
클라우드에서의 데이터 웨어하우징 & 비즈니스 인텔리전스
Amazon Web Services Korea
 
Data Management & Warehousing (David Walker, ex-World Pay) 2019 Confluent Str...
Data Management & Warehousing (David Walker, ex-World Pay) 2019 Confluent Str...Data Management & Warehousing (David Walker, ex-World Pay) 2019 Confluent Str...
Data Management & Warehousing (David Walker, ex-World Pay) 2019 Confluent Str...
confluent
 
2016 DSG Webinar Azure HDInsight 2 V4
2016 DSG Webinar Azure HDInsight 2 V42016 DSG Webinar Azure HDInsight 2 V4
2016 DSG Webinar Azure HDInsight 2 V4
Janani Eshwaran
 
2016 DSG Webinar Azure HDInsight 2 V4
2016 DSG Webinar Azure HDInsight 2 V42016 DSG Webinar Azure HDInsight 2 V4
2016 DSG Webinar Azure HDInsight 2 V4
Janani Eshwaran
 
Platforming the Major Analytic Use Cases for Modern Engineering
Platforming the Major Analytic Use Cases for Modern EngineeringPlatforming the Major Analytic Use Cases for Modern Engineering
Platforming the Major Analytic Use Cases for Modern Engineering
DATAVERSITY
 
AWS December 2015 Webinar Series - Strategies to Quantify TCO & Optimize Cost...
AWS December 2015 Webinar Series - Strategies to Quantify TCO & Optimize Cost...AWS December 2015 Webinar Series - Strategies to Quantify TCO & Optimize Cost...
AWS December 2015 Webinar Series - Strategies to Quantify TCO & Optimize Cost...
Amazon Web Services
 

Similar to LevelsConf 2018 Event Sourcing - Dasith Wijesiriwardena (20)

Digital_IOT_(Microsoft_Solution).pdf
Digital_IOT_(Microsoft_Solution).pdfDigital_IOT_(Microsoft_Solution).pdf
Digital_IOT_(Microsoft_Solution).pdf
 
Web Analytics Wednesday Melbourne Meet Up
Web Analytics Wednesday Melbourne Meet UpWeb Analytics Wednesday Melbourne Meet Up
Web Analytics Wednesday Melbourne Meet Up
 
Levelling up your data infrastructure
Levelling up your data infrastructureLevelling up your data infrastructure
Levelling up your data infrastructure
 
클라우드에서의 데이터 웨어하우징 & 비즈니스 인텔리전스
클라우드에서의 데이터 웨어하우징 & 비즈니스 인텔리전스클라우드에서의 데이터 웨어하우징 & 비즈니스 인텔리전스
클라우드에서의 데이터 웨어하우징 & 비즈니스 인텔리전스
 
AWS Webcast - Sales Productivity Solutions with MicroStrategy and Redshift
AWS Webcast - Sales Productivity Solutions with MicroStrategy and RedshiftAWS Webcast - Sales Productivity Solutions with MicroStrategy and Redshift
AWS Webcast - Sales Productivity Solutions with MicroStrategy and Redshift
 
AWS Summit Seoul 2015 - AWS 최신 서비스 살펴보기 - Aurora, Lambda, EFS, Machine Learn...
AWS Summit Seoul 2015 -  AWS 최신 서비스 살펴보기 - Aurora, Lambda, EFS, Machine Learn...AWS Summit Seoul 2015 -  AWS 최신 서비스 살펴보기 - Aurora, Lambda, EFS, Machine Learn...
AWS Summit Seoul 2015 - AWS 최신 서비스 살펴보기 - Aurora, Lambda, EFS, Machine Learn...
 
AWS re:Invent 2016: How Fulfillment by Amazon (FBA) and Scopely Improved Resu...
AWS re:Invent 2016: How Fulfillment by Amazon (FBA) and Scopely Improved Resu...AWS re:Invent 2016: How Fulfillment by Amazon (FBA) and Scopely Improved Resu...
AWS re:Invent 2016: How Fulfillment by Amazon (FBA) and Scopely Improved Resu...
 
Moving To MicroServices
Moving To MicroServicesMoving To MicroServices
Moving To MicroServices
 
Data Management & Warehousing (David Walker, ex-World Pay) 2019 Confluent Str...
Data Management & Warehousing (David Walker, ex-World Pay) 2019 Confluent Str...Data Management & Warehousing (David Walker, ex-World Pay) 2019 Confluent Str...
Data Management & Warehousing (David Walker, ex-World Pay) 2019 Confluent Str...
 
WSO2Con USA 2015: The Needs of Next Generation Giants
WSO2Con USA 2015: The Needs of Next Generation GiantsWSO2Con USA 2015: The Needs of Next Generation Giants
WSO2Con USA 2015: The Needs of Next Generation Giants
 
2016 DSG Webinar Azure HDInsight 2 V4
2016 DSG Webinar Azure HDInsight 2 V42016 DSG Webinar Azure HDInsight 2 V4
2016 DSG Webinar Azure HDInsight 2 V4
 
2016 DSG Webinar Azure HDInsight 2 V4
2016 DSG Webinar Azure HDInsight 2 V42016 DSG Webinar Azure HDInsight 2 V4
2016 DSG Webinar Azure HDInsight 2 V4
 
Log insight 3.3 customer presentation
Log insight 3.3 customer presentationLog insight 3.3 customer presentation
Log insight 3.3 customer presentation
 
What is OLAP -Data Warehouse Concepts - IT Online Training @ Newyorksys
What is OLAP -Data Warehouse Concepts - IT Online Training @ NewyorksysWhat is OLAP -Data Warehouse Concepts - IT Online Training @ Newyorksys
What is OLAP -Data Warehouse Concepts - IT Online Training @ Newyorksys
 
VAS - VMware CMP
VAS - VMware CMPVAS - VMware CMP
VAS - VMware CMP
 
Platforming the Major Analytic Use Cases for Modern Engineering
Platforming the Major Analytic Use Cases for Modern EngineeringPlatforming the Major Analytic Use Cases for Modern Engineering
Platforming the Major Analytic Use Cases for Modern Engineering
 
Jazz for Service Management
Jazz for Service ManagementJazz for Service Management
Jazz for Service Management
 
AWS December 2015 Webinar Series - Strategies to Quantify TCO & Optimize Cost...
AWS December 2015 Webinar Series - Strategies to Quantify TCO & Optimize Cost...AWS December 2015 Webinar Series - Strategies to Quantify TCO & Optimize Cost...
AWS December 2015 Webinar Series - Strategies to Quantify TCO & Optimize Cost...
 
ADV Slides: Comparing the Enterprise Analytic Solutions
ADV Slides: Comparing the Enterprise Analytic SolutionsADV Slides: Comparing the Enterprise Analytic Solutions
ADV Slides: Comparing the Enterprise Analytic Solutions
 
Network Solution
Network SolutionNetwork Solution
Network Solution
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

LevelsConf 2018 Event Sourcing - Dasith Wijesiriwardena

  • 1. 07 July 2018 | Dasith Wijes
  • 2. Event Sourcing Event sourcing workflow > Audit trails, Sumerian clay tablets and Blockchain > Advantages over storing state > Simple form of CQRS, contrasting it to a monolith > Command side and read side > How event sourcing fits in Command Query Responsibility Segregation > Shopping catalogue example
  • 3. What is Domain Driven Design? “In order to create good software, you have to know what that software is all about. You cannot create a banking software system unless you have a good understanding of what banking is all about, one must understand the domain of banking” – Eric Evans
  • 4. What is Event Sourcing? Use an append-only store to record the full series of events that describe actions taken on data in a domain, rather than storing just the current state.
  • 5. Event Sourcing Examples Sumerian clay tablets Transactional systems (i.e. Stock) Accounting ledger Database transaction log Source control systems
  • 6. Blockchain = Event Sourcing + Public Store + Decentralized
  • 7. Scenario You are the team lead of a small team of developers at a start-up company building an Amazon competitor. Your product is gaining traction and you expect a lot more users in the next few months. • The customers are complaining of slow response times & crashes during peak times. • Come up with a plan to make your application more performant. • Think about your deployment and scaling strategy.
  • 8. We Have a Monolith A monolithic application has a single code base and a single build system which builds and deploys the entire application (and dependencies). Modules may be divided as business features or technical features.
  • 9. Scenario Continued Monolithic Application  Big and complex code base  Hard onboarding process for new developers  Hidden coupling and complexity  Single build pipeline  Release cycle is long  Scaling up is very expensive  Performance issues  Application is offline when deploying new version Symptoms A solution path • CRM • Online Store • Supplier • Stock • Accounts • Reports  Identify which parts of the system are used the most  Logically separate those parts  Deploying the separated parts independently  Scale the required parts independently
  • 10. Thought Experiment You are managing a coffee shop and have 2 employees who work alternate shifts. • Anna who is a great barista but is slow at operating the cash register. • Sam who doesn’t make great coffee but is fast at operating the register. • More people are coming to the store and you want a strategy to reduce wait times for customers.
  • 11. CQRS to the Rescue “CQRS stands for Command Query Responsibility Segregation. At its heart is the notion that you can use a different model to update information than the model you use to read information” – Martin Fowler
  • 12. Simple CQRS Solution Without CQRS ShoppingCatalogueService + AddItem(itemInfo): void + UpdateItem(item): void + RemoveItem(item): void + Search(criteria): Decimal + Browse(category): items[] + SetDiscount(item): void With CQRS ShoppingCatalogueReadService + Search(criteria): Decimal + Browse(category): items[] ShoppingCatalogueWriteService + AddItem(itemInfo): void + UpdateItem(item): void + RemoveItem(item): void + SetDiscount(item): void MonolithicApplication
  • 13. Updated Scenario You have successfully managed to logically separate your Online-Store module to writes (commands) and reads (queries). • It’s become clear that “data models” used for write vs read are different. • Investigate whether it is possible to deploy those as separate applications and have separate data models/ storage mechanisms.
  • 14. CQRS Solution Evolved What if we build and deploy them independently? ShoppingCatalogueReadService + Search(criteria): Decimal + Browse(category): items[] ShoppingCatalogueWriteService + AddItem(itemInfo): void + UpdateItem(item): void + RemoveItem(item): void + SetDiscount(item): void We get a solution that has…  Independent scalability  Manageable codebases But what about…  Shared storage?  Transactions + Locks?  Dependency availability?
  • 15.
  • 16. CQRS Solution Using Event Sourcing ShoppingCatalogueReadService + Search(criteria): Decimal + Browse(category): items[] ShoppingCatalogueWriteService + AddItem(itemInfo): void + UpdateItem(item): void + RemoveItem(item): void + SetDiscount(item): void Domain Events Event Database (Append Only) Read Model Database Subscribers listening to events Queue Storing an event publishes it to the queue Query Command Update Read Model
  • 17. A Bit More About Event Sourcing And CQRS  Event Sourcing is naturally CQRS  But… not all CQRS solutions are event sourced  CQRS is not an end goal  Event Sourcing is a natural functional model State GetNewState(State oldState, Event lastEvent) { return (oldState + lastEvent); }
  • 18. Key Benefits of Event Sourcing • Ability to track all changes done to the domain  Rebuild your state to a point in time • Less coupling between read and write sides  Reduction of impedance mismatch  Many world views  Independent scalability • Easier to debug
  • 19. Some Pitfalls When Using Event Sourcing • Unfamiliar concept to many • External systems / dependencies • Eventual consistency • Event schema changes
  • 20. What Did We Learn? • Event Sourcing And Command Query Responsibility Segregation • What they are? • When to apply them? • Key advantages • Disadvantages • Basic event sourcing workflow
  • 21. Want More? • My blog: dasith.me • ES ‘reference framework’ for .NET: NEventLite (Search: NEventLite on NuGet or GitHub) • Domain Driven Design – Eric Evans • Greg Young on YouTube • DDD/CQRS Google Group • ES database: eventstore.org

Editor's Notes

  1. CQRS and ES are concepts that have roots in DDD. The complexity at the heart of any software system isn’t in the architecture, user interface or in feature set. The complexity resides in understanding the domain. DDD introduces a common set of patterns and principles to model your domain in a way that reduces this complexity.
  2. In its most simple form, event sourcing is nothing but storing all the domain events so your state changes are represented as a series of actions. Auditability is the most key advantage event sourcing brings The bank balance example
  3. Blockchain based systems are “naturally event sourced”. Solves the audit and trust problems in a decentralized way.
  4. Easier to test and debug. Don’t have to deal with the availability of dependencies.
  5. Anything that changes the state of our system is considered a command while a Query is something that is used to just read state. What it is : A powerful tool that solves a very specific set of problems. What it’s not : A silver bullet for every problem domain.
  6. There is no perfect way to solve a problem. It always depends.
  7. CQRS is a stepping stone to an ES system Command Query Separation (CQRS is based on this) first introduced by Bertrand Meyer in 1988) Functionally ES state is a left fold of previous state
  8. ES is a application level architecture. If you use ES as a top level architecture like SOA you will end up with an event sourced monolith.