SlideShare a Scribd company logo
A visual introduction to

Event Sourcing and CQRS
1
@nicusX
https://opencredo.com/author/lorenzo/
Lorenzo Nicora
Senior Consultant @ OpenCredo
2
A couple of concepts from DDD
Aggregate
(Current) State

of the Aggregate
Lorenzo Nicora Intro to Event Sourcing and CQRS
3
Once upon a time…
Everything
is synchronous
Request - Response
Lorenzo Nicora Intro to Event Sourcing and CQRS
4
Scaling up…
Updates —> Locks —> Contention!
<— Block <—
Lorenzo Nicora Intro to Event Sourcing and CQRS
5
Let’s go Asynchronous
Pwd —> “secret”
Pwd —> “12345”
Pwd —> “54321”
Pwd —> “secret”
Pwd —> “54321”
Pwd —> “12345”
===>

Out of 

Order
Asynchronous, Message-driven
Request/Response
ACID Transaction
Distributed, Message-based 

—> No order guaranteed
Lorenzo Nicora Intro to Event Sourcing and CQRS
6
Command Sourcing
💡
• Append Only —> No Contention
• Build State from Command history
Write fast,
Think later
K/V Store
Distributed
Lorenzo Nicora Intro to Event Sourcing and CQRS
Command
“Submit Order!”
—> A request (imperative sentence)
—> May fail
—> May affect multiple Aggregates
7
Commands vs Events
✉
Rebuild Aggregate State 

from Commands
Lorenzo Nicora Intro to Event Sourcing and CQRS
8
Event
“Order submitted”
—> Statement of facts (past tense)
—> Never fails
—> May affect a single Aggregate
✉
Rebuild Aggregate State 

from Events
Lorenzo Nicora Intro to Event Sourcing and CQRS
9
Commands to Events
(DDD patterns: Aggregate / Process Manager)
X
Y
Z
Lorenzo Nicora Intro to Event Sourcing and CQRS
10
Command > Event Sourcing
💡
Think a little,
Write,
Think later
Lorenzo Nicora Intro to Event Sourcing and CQRS
11
Event Sourcing
In many domains
Commands Events
Lorenzo Nicora Intro to Event Sourcing and CQRS
12
Additional Benefits
Easy

Eventual Business Consistency
—> Corrective Events
Robust to data corruption
(bugs, fat fingers…)
—> Rebuild state ignoring wrong events
Lorenzo Nicora Intro to Event Sourcing and CQRS
13
Additional Benefits
History
(for free)
Rebuild State 

at a point in Time
Lorenzo Nicora Intro to Event Sourcing and CQRS
14
Main Benefit
Scalable
—> Append only
-> Fits distributed k/v stores
—> Low-latency writes
—> Allows asynchronous processing
Lorenzo Nicora Intro to Event Sourcing and CQRS
What about reads?
15
Lorenzo Nicora Intro to Event Sourcing and CQRS
16
Retrieving the State
How do I retrieve the State?
“Get details of Order ‘AB123’”
❔
not very efficient, but…
…may work
Lorenzo Nicora Intro to Event Sourcing and CQRS
17
Querying (Searching) the State
❓
❓ How do query the State?
“Get all Orders delivered to ‘SE1 0NZ’”
❓
❓
Lorenzo Nicora Intro to Event Sourcing and CQRS
18
CQRS
Command
Query
Responsibility
Segregation
💡 Separate
• Code
• muService
• Datastore
-> Update
-—> Retrieve
“Query”
datastore is
downstream
Lorenzo Nicora Intro to Event Sourcing and CQRS
19
Not a new idea
Specialised
Downstream
Lorenzo Nicora Intro to Event Sourcing and CQRS
20
CQRS and Event Sourcing
Lorenzo Nicora Intro to Event Sourcing and CQRS
21
Materialised Views 

(of current State)
Lorenzo Nicora Intro to Event Sourcing and CQRS
22
Materialised Views (of State)
Latest (known) State
(Persistent)

Rebuildable
from Events
In Memory

K/V Store
Graph
…
RDBMS
Delayed
💡
Lorenzo Nicora Intro to Event Sourcing and CQRS
23
Materialised View of State
Query a RDBMS?!?
Wasn’t it the old way?
❓
RDBMS is just one of our options:

easy to use, easily become a bottleneck
Lorenzo Nicora Intro to Event Sourcing and CQRS
24
Materialised Views of State
* Views are optimised for 

specific query use cases
—> multiple Views from same Events
* Updated asynchronously, delayed
—> to Scale
-> may reorder Events
Lorenzo Nicora Intro to Event Sourcing and CQRS
25
Materialised Views of State
* Views can be rebuilt from Events
Event Log
is our Source of Truth
* Easy to evolve or fix
—> change or fix logic;
rebuild view from events
(not the View)
Lorenzo Nicora Intro to Event Sourcing and CQRS
26
Indexes
Lorenzo Nicora Intro to Event Sourcing and CQRS
27
Indexes
Search Engines

K/V Stores
• Optimised for querying (less for retrieving)
• Latest State; rebuild on the fly
💡
Lorenzo Nicora Intro to Event Sourcing and CQRS
28
Hybrid solutions
Lorenzo Nicora Intro to Event Sourcing and CQRS
29
Hybrid solutions: e.g. Snapshots
• Speed up rebuilding the current State
• Use recent Events to rebuild up-to-date
💡 Long delayed
Lorenzo Nicora Intro to Event Sourcing and CQRS
30
Eventual (Business) Consistency
Guess —> Compensate—> Apologies
Lorenzo Nicora Intro to Event Sourcing and CQRS
31
Eventual Consistency: Sagas
StatefulOut of band
Corrective Command 

or Event
Saga
Lorenzo Nicora Intro to Event Sourcing and CQRS
32
Lesson

from the Trenches
Lorenzo Nicora Intro to Event Sourcing and CQRS
33
Lesson Learned #1
If you put data in…
…you will eventually

have to get them out!
The “Query” side 

is not secondary
Lorenzo Nicora Intro to Event Sourcing and CQRS
34
Lessons Learned #2
In old days:

normalising one DB 

to support as many queries as possible
With CQRS: 

multiple denormalised “data stores”

optimised for different queries
No single “Q” implementation 

for all your queries
Lorenzo Nicora Intro to Event Sourcing and CQRS
35
Lessons Learned #3
A central, shared Event Store

may not be the best option
No Event-sourced Monolith
Prefer persistence 

per Bounded-Context
Lorenzo Nicora Intro to Event Sourcing and CQRS
+++ Summing up +++
36
Lorenzo Nicora Intro to Event Sourcing and CQRS
37
ES/CQRS Optimal Use Cases
High Volume
Low Latency writes
(big data)
Event Sourcing + CQRS
😋
Out-of-order Commands/Events

(IoT)
Lorenzo Nicora Intro to Event Sourcing and CQRS
38
ES/CQRS Drawbacks
x No “One-Size-Fits-All”

—> Multiple “Q” implementations
x Delayed reads
x No ACID Transactions
x Additional complexity (!)
🙁
Lorenzo Nicora Intro to Event Sourcing and CQRS
39
ES/CQRS Benefits
+ No “One-Size-Fits-All”
—> “Q” are optimised for use cases
+ Eventual (Business) Consistency
+ History, Temporal queries
+ Robust to data corruption
😀
Lorenzo Nicora Intro to Event Sourcing and CQRS
That’s all, Folks!
40
Lorenzo Nicora Intro to Event Sourcing and CQRS
??? Questions ???
41
Thanks.
⏳
Lorenzo Nicora Intro to Event Sourcing and CQRS

More Related Content

PDF
A Thorough Comparison of Delta Lake, Iceberg and Hudi
PDF
Networking in Java with NIO and Netty
PDF
eBPF - Observability In Deep
PDF
Microservices with Java, Spring Boot and Spring Cloud
PPTX
MySQL Slow Query log Monitoring using Beats & ELK
PDF
MySQL High Availability -- InnoDB Clusters
PDF
Serverless Kafka and Spark in a Multi-Cloud Lakehouse Architecture
PDF
[Spring Camp 2018] 11번가 Spring Cloud 기반 MSA로의 전환 : 지난 1년간의 이야기
A Thorough Comparison of Delta Lake, Iceberg and Hudi
Networking in Java with NIO and Netty
eBPF - Observability In Deep
Microservices with Java, Spring Boot and Spring Cloud
MySQL Slow Query log Monitoring using Beats & ELK
MySQL High Availability -- InnoDB Clusters
Serverless Kafka and Spark in a Multi-Cloud Lakehouse Architecture
[Spring Camp 2018] 11번가 Spring Cloud 기반 MSA로의 전환 : 지난 1년간의 이야기

What's hot (20)

PDF
Api Gateway
PDF
Introduction to Spring WebFlux #jsug #sf_a1
PDF
Prometheus
PDF
When NOT to use Apache Kafka?
PDF
Gitops: the kubernetes way
PPTX
Grafana.pptx
PDF
Introduction to Spring Cloud
PDF
Observability
PDF
11st Legacy Application의 Spring Cloud 기반 MicroServices로 전환 개발 사례
PDF
Kafka streams windowing behind the curtain
PPTX
Introduction to Microservices
PDF
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
PDF
SQL Transactions - What they are good for and how they work
PDF
Introduction to Apache Flink - Fast and reliable big data processing
PDF
Morel, a Functional Query Language
PPTX
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
PPTX
Dapr: distributed application runtime
PDF
Kafka Streams: What it is, and how to use it?
PPTX
Elastic - ELK, Logstash & Kibana
PDF
Unified Stream and Batch Processing with Apache Flink
Api Gateway
Introduction to Spring WebFlux #jsug #sf_a1
Prometheus
When NOT to use Apache Kafka?
Gitops: the kubernetes way
Grafana.pptx
Introduction to Spring Cloud
Observability
11st Legacy Application의 Spring Cloud 기반 MicroServices로 전환 개발 사례
Kafka streams windowing behind the curtain
Introduction to Microservices
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
SQL Transactions - What they are good for and how they work
Introduction to Apache Flink - Fast and reliable big data processing
Morel, a Functional Query Language
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
Dapr: distributed application runtime
Kafka Streams: What it is, and how to use it?
Elastic - ELK, Logstash & Kibana
Unified Stream and Batch Processing with Apache Flink
Ad

Viewers also liked (20)

PDF
Developing event-driven microservices with event sourcing and CQRS (phillyete)
PDF
Microservice Architecture with CQRS and Event Sourcing
PDF
Haufe #msaday - Building a Microservice Ecosystem by Daniel Bryant
PDF
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
PDF
Reactive Microservices By Lorenzo Nicora
PDF
QCON London 2017 - Monitoring Serverless Architectures by Rafal Gancarz
PDF
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
PDF
GOTO LONDON 2016: Concursus Event sourcing Evolved (Updated)
PDF
Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant
PDF
Evolving Project Management: from the sin to the virtue by Antonio Cobo
PDF
ServerlessConf: Serverless for the Enterprise - Rafal Gancarz
PPTX
O'Reilly 2016: "Continuous Delivery with Containers: The Trials and Tribulati...
PDF
High Load Strategy 2016 - Project Management: from Stone Age to DevOps
PDF
A year with event sourcing and CQRS
PDF
muCon 2016: Authentication in Microservice Systems By David Borsos
PPTX
CQRS and Event Sourcing, An Alternative Architecture for DDD
PDF
Event-sourced architectures with Akka
PDF
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
PDF
Haufe #msaday - The Actor model: an alternative approach to concurrency By Lo...
PPTX
Developing event-driven microservices with event sourcing and CQRS (phillyete)
Microservice Architecture with CQRS and Event Sourcing
Haufe #msaday - Building a Microservice Ecosystem by Daniel Bryant
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
Reactive Microservices By Lorenzo Nicora
QCON London 2017 - Monitoring Serverless Architectures by Rafal Gancarz
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
GOTO LONDON 2016: Concursus Event sourcing Evolved (Updated)
Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant
Evolving Project Management: from the sin to the virtue by Antonio Cobo
ServerlessConf: Serverless for the Enterprise - Rafal Gancarz
O'Reilly 2016: "Continuous Delivery with Containers: The Trials and Tribulati...
High Load Strategy 2016 - Project Management: from Stone Age to DevOps
A year with event sourcing and CQRS
muCon 2016: Authentication in Microservice Systems By David Borsos
CQRS and Event Sourcing, An Alternative Architecture for DDD
Event-sourced architectures with Akka
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
Haufe #msaday - The Actor model: an alternative approach to concurrency By Lo...
Ad

Similar to A Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora (20)

PDF
fram^ TechTalk #1 - CQRS and Event Sourcing (ES)
PPT
PPT
PPTX
Cqrs and Event Sourcing Intro For Developers
PPTX
Introduction to CQRS and Event Sourcing
PPTX
Intro to event sourcing and CQRS
PDF
CQRS & Event Sourcing
PDF
CQRS and Event Sourcing with PHP - shorter version
PDF
CQRS and Event Sourcing with PHP
PPTX
Advance Microservice Patterns - Event Souring , CQRS
PDF
CQRS + Event Sourcing
PDF
CQRS and Event Sourcing
PPTX
Event sourcing and CQRS
PDF
GECon2017_Building scalable application with cqrs and event sourcing (a. hars...
PDF
Implementing Event Sourcing in .NET
PPTX
Cqrs and event sourcing in azure
PDF
Unite 2017 - CQRS - Jens Gheerardyn
PDF
Introduction to Event Sourcing,CQRS and Axon
PDF
Event Sourcing without any Framework
PPTX
CQRS and Event Sourcing with Axon Framework
fram^ TechTalk #1 - CQRS and Event Sourcing (ES)
Cqrs and Event Sourcing Intro For Developers
Introduction to CQRS and Event Sourcing
Intro to event sourcing and CQRS
CQRS & Event Sourcing
CQRS and Event Sourcing with PHP - shorter version
CQRS and Event Sourcing with PHP
Advance Microservice Patterns - Event Souring , CQRS
CQRS + Event Sourcing
CQRS and Event Sourcing
Event sourcing and CQRS
GECon2017_Building scalable application with cqrs and event sourcing (a. hars...
Implementing Event Sourcing in .NET
Cqrs and event sourcing in azure
Unite 2017 - CQRS - Jens Gheerardyn
Introduction to Event Sourcing,CQRS and Axon
Event Sourcing without any Framework
CQRS and Event Sourcing with Axon Framework

More from OpenCredo (17)

PDF
Webinar - Design Thinking for Platform Engineering
PDF
MuCon 2019: Exploring Your Microservices Architecture Through Network Science...
PDF
Goto Chicago; Journeys To Cloud Native Architecture: Sun, Sea And Emergencies...
PPTX
Mucon 2018: Heuristics for Identifying Microservice Boundaries By Erich Eichi...
PDF
Journeys To Cloud Native Architecture: Sun, Sea And Emergencies - Nicki Watt
PDF
Machine Learning Game Changer for IT - Maartens Lourens
PDF
Kafka Summit 2018: A Journey Building Kafka Connectors - Pegerto Fernandez
PDF
MuCon 2017: A not So(A) Trivial Question by Tareq Abedrabbo
PDF
DevOpsCon Berlin 2017: Project Management from Stone Age to DevOps By Antoni...
PDF
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
PDF
Succeeding with DevOps Transformation - Rafal Gancarz
PDF
Progscon 2017: Serverless Architectures - Rafal Gancarz
PDF
Vault: Beyond secret storage - Using Vault to harden your infrastructure
PPTX
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
PDF
Spring Boot Microservices vs Akka Actor Cluster
PDF
Microservices Manchester: Microservices and Macro-Economics - A Shorty Histor...
PDF
Microservices Manchester: Security, Microservces and Vault by Nicki Watt
Webinar - Design Thinking for Platform Engineering
MuCon 2019: Exploring Your Microservices Architecture Through Network Science...
Goto Chicago; Journeys To Cloud Native Architecture: Sun, Sea And Emergencies...
Mucon 2018: Heuristics for Identifying Microservice Boundaries By Erich Eichi...
Journeys To Cloud Native Architecture: Sun, Sea And Emergencies - Nicki Watt
Machine Learning Game Changer for IT - Maartens Lourens
Kafka Summit 2018: A Journey Building Kafka Connectors - Pegerto Fernandez
MuCon 2017: A not So(A) Trivial Question by Tareq Abedrabbo
DevOpsCon Berlin 2017: Project Management from Stone Age to DevOps By Antoni...
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
Succeeding with DevOps Transformation - Rafal Gancarz
Progscon 2017: Serverless Architectures - Rafal Gancarz
Vault: Beyond secret storage - Using Vault to harden your infrastructure
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
Spring Boot Microservices vs Akka Actor Cluster
Microservices Manchester: Microservices and Macro-Economics - A Shorty Histor...
Microservices Manchester: Security, Microservces and Vault by Nicki Watt

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Encapsulation theory and applications.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Approach and Philosophy of On baking technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Modernizing your data center with Dell and AMD
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Encapsulation_ Review paper, used for researhc scholars
Teaching material agriculture food technology
Encapsulation theory and applications.pdf
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Approach and Philosophy of On baking technology
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
The Rise and Fall of 3GPP – Time for a Sabbatical?
Modernizing your data center with Dell and AMD
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Building Integrated photovoltaic BIPV_UPV.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Encapsulation_ Review paper, used for researhc scholars

A Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora

  • 1. A visual introduction to
 Event Sourcing and CQRS 1 @nicusX https://opencredo.com/author/lorenzo/ Lorenzo Nicora Senior Consultant @ OpenCredo
  • 2. 2 A couple of concepts from DDD Aggregate (Current) State
 of the Aggregate Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 3. 3 Once upon a time… Everything is synchronous Request - Response Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 4. 4 Scaling up… Updates —> Locks —> Contention! <— Block <— Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 5. 5 Let’s go Asynchronous Pwd —> “secret” Pwd —> “12345” Pwd —> “54321” Pwd —> “secret” Pwd —> “54321” Pwd —> “12345” ===>
 Out of 
 Order Asynchronous, Message-driven Request/Response ACID Transaction Distributed, Message-based 
 —> No order guaranteed Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 6. 6 Command Sourcing 💡 • Append Only —> No Contention • Build State from Command history Write fast, Think later K/V Store Distributed Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 7. Command “Submit Order!” —> A request (imperative sentence) —> May fail —> May affect multiple Aggregates 7 Commands vs Events ✉ Rebuild Aggregate State 
 from Commands Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 8. 8 Event “Order submitted” —> Statement of facts (past tense) —> Never fails —> May affect a single Aggregate ✉ Rebuild Aggregate State 
 from Events Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 9. 9 Commands to Events (DDD patterns: Aggregate / Process Manager) X Y Z Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 10. 10 Command > Event Sourcing 💡 Think a little, Write, Think later Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 11. 11 Event Sourcing In many domains Commands Events Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 12. 12 Additional Benefits Easy
 Eventual Business Consistency —> Corrective Events Robust to data corruption (bugs, fat fingers…) —> Rebuild state ignoring wrong events Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 13. 13 Additional Benefits History (for free) Rebuild State 
 at a point in Time Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 14. 14 Main Benefit Scalable —> Append only -> Fits distributed k/v stores —> Low-latency writes —> Allows asynchronous processing Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 15. What about reads? 15 Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 16. 16 Retrieving the State How do I retrieve the State? “Get details of Order ‘AB123’” ❔ not very efficient, but… …may work Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 17. 17 Querying (Searching) the State ❓ ❓ How do query the State? “Get all Orders delivered to ‘SE1 0NZ’” ❓ ❓ Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 18. 18 CQRS Command Query Responsibility Segregation 💡 Separate • Code • muService • Datastore -> Update -—> Retrieve “Query” datastore is downstream Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 19. 19 Not a new idea Specialised Downstream Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 20. 20 CQRS and Event Sourcing Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 21. 21 Materialised Views 
 (of current State) Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 22. 22 Materialised Views (of State) Latest (known) State (Persistent)
 Rebuildable from Events In Memory
 K/V Store Graph … RDBMS Delayed 💡 Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 23. 23 Materialised View of State Query a RDBMS?!? Wasn’t it the old way? ❓ RDBMS is just one of our options:
 easy to use, easily become a bottleneck Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 24. 24 Materialised Views of State * Views are optimised for 
 specific query use cases —> multiple Views from same Events * Updated asynchronously, delayed —> to Scale -> may reorder Events Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 25. 25 Materialised Views of State * Views can be rebuilt from Events Event Log is our Source of Truth * Easy to evolve or fix —> change or fix logic; rebuild view from events (not the View) Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 26. 26 Indexes Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 27. 27 Indexes Search Engines
 K/V Stores • Optimised for querying (less for retrieving) • Latest State; rebuild on the fly 💡 Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 28. 28 Hybrid solutions Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 29. 29 Hybrid solutions: e.g. Snapshots • Speed up rebuilding the current State • Use recent Events to rebuild up-to-date 💡 Long delayed Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 30. 30 Eventual (Business) Consistency Guess —> Compensate—> Apologies Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 31. 31 Eventual Consistency: Sagas StatefulOut of band Corrective Command 
 or Event Saga Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 32. 32 Lesson
 from the Trenches Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 33. 33 Lesson Learned #1 If you put data in… …you will eventually
 have to get them out! The “Query” side 
 is not secondary Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 34. 34 Lessons Learned #2 In old days:
 normalising one DB 
 to support as many queries as possible With CQRS: 
 multiple denormalised “data stores”
 optimised for different queries No single “Q” implementation 
 for all your queries Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 35. 35 Lessons Learned #3 A central, shared Event Store
 may not be the best option No Event-sourced Monolith Prefer persistence 
 per Bounded-Context Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 36. +++ Summing up +++ 36 Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 37. 37 ES/CQRS Optimal Use Cases High Volume Low Latency writes (big data) Event Sourcing + CQRS 😋 Out-of-order Commands/Events
 (IoT) Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 38. 38 ES/CQRS Drawbacks x No “One-Size-Fits-All”
 —> Multiple “Q” implementations x Delayed reads x No ACID Transactions x Additional complexity (!) 🙁 Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 39. 39 ES/CQRS Benefits + No “One-Size-Fits-All” —> “Q” are optimised for use cases + Eventual (Business) Consistency + History, Temporal queries + Robust to data corruption 😀 Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 40. That’s all, Folks! 40 Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 41. ??? Questions ??? 41 Thanks. ⏳ Lorenzo Nicora Intro to Event Sourcing and CQRS