SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

CQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationCQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationBrian Ritchie
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQAraf Karsh Hamid
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...Chris Richardson
 
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...Chris Richardson
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaAraf Karsh Hamid
 
Real World Event Sourcing and CQRS
Real World Event Sourcing and CQRSReal World Event Sourcing and CQRS
Real World Event Sourcing and CQRSMatthew Hawkins
 
Scaling your Data Pipelines with Apache Spark on Kubernetes
Scaling your Data Pipelines with Apache Spark on KubernetesScaling your Data Pipelines with Apache Spark on Kubernetes
Scaling your Data Pipelines with Apache Spark on KubernetesDatabricks
 
How to build massive service for advance
How to build massive service for advanceHow to build massive service for advance
How to build massive service for advanceDaeMyung Kang
 
Road to (Enterprise) Observability
Road to (Enterprise) ObservabilityRoad to (Enterprise) Observability
Road to (Enterprise) ObservabilityChristoph Engelbert
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Steve Pember
 
CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event SourcingMike Bild
 
MicroCPH - Managing data consistency in a microservice architecture using Sagas
MicroCPH - Managing data consistency in a microservice architecture using SagasMicroCPH - Managing data consistency in a microservice architecture using Sagas
MicroCPH - Managing data consistency in a microservice architecture using SagasChris Richardson
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyVMware Tanzu
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing ArchitecturesVictor Rentea
 
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기Kiyoung Moon
 
Elastic stack Presentation
Elastic stack PresentationElastic stack Presentation
Elastic stack PresentationAmr Alaa Yassen
 
The Art of Discovering Bounded Contexts
The Art of Discovering Bounded ContextsThe Art of Discovering Bounded Contexts
The Art of Discovering Bounded ContextsNick Tune
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootMikalai Alimenkou
 

Was ist angesagt? (20)

CQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility SegregationCQRS: Command/Query Responsibility Segregation
CQRS: Command/Query Responsibility Segregation
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQ
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
 
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and Saga
 
Real World Event Sourcing and CQRS
Real World Event Sourcing and CQRSReal World Event Sourcing and CQRS
Real World Event Sourcing and CQRS
 
Scaling your Data Pipelines with Apache Spark on Kubernetes
Scaling your Data Pipelines with Apache Spark on KubernetesScaling your Data Pipelines with Apache Spark on Kubernetes
Scaling your Data Pipelines with Apache Spark on Kubernetes
 
How to build massive service for advance
How to build massive service for advanceHow to build massive service for advance
How to build massive service for advance
 
Road to (Enterprise) Observability
Road to (Enterprise) ObservabilityRoad to (Enterprise) Observability
Road to (Enterprise) Observability
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
 
CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event Sourcing
 
MicroCPH - Managing data consistency in a microservice architecture using Sagas
MicroCPH - Managing data consistency in a microservice architecture using SagasMicroCPH - Managing data consistency in a microservice architecture using Sagas
MicroCPH - Managing data consistency in a microservice architecture using Sagas
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor Netty
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing Architectures
 
ELK Stack
ELK StackELK Stack
ELK Stack
 
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
 
Elastic stack Presentation
Elastic stack PresentationElastic stack Presentation
Elastic stack Presentation
 
The Art of Discovering Bounded Contexts
The Art of Discovering Bounded ContextsThe Art of Discovering Bounded Contexts
The Art of Discovering Bounded Contexts
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 

Andere mochten auch

From C to Q one event at a time: Event Sourcing illustrated
From C to Q one event at a time: Event Sourcing illustratedFrom C to Q one event at a time: Event Sourcing illustrated
From C to Q one event at a time: Event Sourcing illustratedLorenzo Nicora
 
Reactive Principles and Microservices
Reactive Principles and MicroservicesReactive Principles and Microservices
Reactive Principles and MicroservicesLorenzo Nicora
 
The Actor model: an alternative approach to concurrency
The Actor model: an alternative approach to concurrencyThe Actor model: an alternative approach to concurrency
The Actor model: an alternative approach to concurrencyLorenzo Nicora
 
Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012Bradley Holt
 
Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"bincangteknologi
 
An Introduction to Domain Driven Design for Product Managers
An Introduction to Domain Driven Design for Product ManagersAn Introduction to Domain Driven Design for Product Managers
An Introduction to Domain Driven Design for Product Managersr4isstatic
 
Agile development and domain driven design
Agile development and domain driven designAgile development and domain driven design
Agile development and domain driven designJacopo Romei
 
ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignBradley Holt
 
Introduction to Domain Driven Design
Introduction to Domain Driven DesignIntroduction to Domain Driven Design
Introduction to Domain Driven DesignChristos Tsakostas
 
Towards a Political Aesthetic of Everyday Life
Towards a Political Aesthetic of Everyday Life Towards a Political Aesthetic of Everyday Life
Towards a Political Aesthetic of Everyday Life Zeliha Uyurca
 
From Islands to Cities – Applications for Smart Energy Storage - Dr. Wolfram ...
From Islands to Cities – Applications for Smart Energy Storage - Dr. Wolfram ...From Islands to Cities – Applications for Smart Energy Storage - Dr. Wolfram ...
From Islands to Cities – Applications for Smart Energy Storage - Dr. Wolfram ...IPPAI
 
Achieving best practice in delivering government information and services online
Achieving best practice in delivering government information and services onlineAchieving best practice in delivering government information and services online
Achieving best practice in delivering government information and services onlineeGovernment Resource Centre
 
Security, Privacy & Convenience – key drivers for mobile adoption from a cons...
Security, Privacy & Convenience – key drivers for mobile adoption from a cons...Security, Privacy & Convenience – key drivers for mobile adoption from a cons...
Security, Privacy & Convenience – key drivers for mobile adoption from a cons...Subho Halder
 
Government Controlled Mobile VoIP
Government Controlled Mobile VoIPGovernment Controlled Mobile VoIP
Government Controlled Mobile VoIPHabibur Rahman
 
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignNaeem Sarfraz
 
The importance of a mobile government
The importance of a mobile governmentThe importance of a mobile government
The importance of a mobile governmentCapgemini
 
Mobile Governance Applications
Mobile Governance ApplicationsMobile Governance Applications
Mobile Governance Applicationsachalkumar
 
OECD GOV Open government data
OECD GOV Open government dataOECD GOV Open government data
OECD GOV Open government dataadamlerouge
 

Andere mochten auch (20)

From C to Q one event at a time: Event Sourcing illustrated
From C to Q one event at a time: Event Sourcing illustratedFrom C to Q one event at a time: Event Sourcing illustrated
From C to Q one event at a time: Event Sourcing illustrated
 
Reactive Principles and Microservices
Reactive Principles and MicroservicesReactive Principles and Microservices
Reactive Principles and Microservices
 
The Actor model: an alternative approach to concurrency
The Actor model: an alternative approach to concurrencyThe Actor model: an alternative approach to concurrency
The Actor model: an alternative approach to concurrency
 
Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012Domain-Driven Design at ZendCon 2012
Domain-Driven Design at ZendCon 2012
 
Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"
 
An Introduction to Domain Driven Design for Product Managers
An Introduction to Domain Driven Design for Product ManagersAn Introduction to Domain Driven Design for Product Managers
An Introduction to Domain Driven Design for Product Managers
 
Agile development and domain driven design
Agile development and domain driven designAgile development and domain driven design
Agile development and domain driven design
 
ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven Design
 
Introduction to Domain Driven Design
Introduction to Domain Driven DesignIntroduction to Domain Driven Design
Introduction to Domain Driven Design
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Towards a Political Aesthetic of Everyday Life
Towards a Political Aesthetic of Everyday Life Towards a Political Aesthetic of Everyday Life
Towards a Political Aesthetic of Everyday Life
 
From Islands to Cities – Applications for Smart Energy Storage - Dr. Wolfram ...
From Islands to Cities – Applications for Smart Energy Storage - Dr. Wolfram ...From Islands to Cities – Applications for Smart Energy Storage - Dr. Wolfram ...
From Islands to Cities – Applications for Smart Energy Storage - Dr. Wolfram ...
 
Achieving best practice in delivering government information and services online
Achieving best practice in delivering government information and services onlineAchieving best practice in delivering government information and services online
Achieving best practice in delivering government information and services online
 
Security, Privacy & Convenience – key drivers for mobile adoption from a cons...
Security, Privacy & Convenience – key drivers for mobile adoption from a cons...Security, Privacy & Convenience – key drivers for mobile adoption from a cons...
Security, Privacy & Convenience – key drivers for mobile adoption from a cons...
 
Government Controlled Mobile VoIP
Government Controlled Mobile VoIPGovernment Controlled Mobile VoIP
Government Controlled Mobile VoIP
 
MGov2010
MGov2010MGov2010
MGov2010
 
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
 
The importance of a mobile government
The importance of a mobile governmentThe importance of a mobile government
The importance of a mobile government
 
Mobile Governance Applications
Mobile Governance ApplicationsMobile Governance Applications
Mobile Governance Applications
 
OECD GOV Open government data
OECD GOV Open government dataOECD GOV Open government data
OECD GOV Open government data
 

Ähnlich wie A visual introduction to Event Sourcing and CQRS

From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino...
From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino...From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino...
From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino...Lorenzo Nicora
 
Event sourcing for IoT and mobile - JAX London 2017
Event sourcing for IoT and mobile - JAX London 2017Event sourcing for IoT and mobile - JAX London 2017
Event sourcing for IoT and mobile - JAX London 2017Lorenzo Nicora
 
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...OpenCredo
 
How Fast Data Is Turned into Fast Information and Timely Action (OOW 2014)
How Fast Data Is Turned into Fast Information and Timely Action (OOW 2014)How Fast Data Is Turned into Fast Information and Timely Action (OOW 2014)
How Fast Data Is Turned into Fast Information and Timely Action (OOW 2014)Lucas Jellema
 
Introduction to ksqlDB and stream processing (Vish Srinivasan - Confluent)
Introduction to ksqlDB and stream processing (Vish Srinivasan  - Confluent)Introduction to ksqlDB and stream processing (Vish Srinivasan  - Confluent)
Introduction to ksqlDB and stream processing (Vish Srinivasan - Confluent)KafkaZone
 
Stream processing with Apache Flink - Maximilian Michels Data Artisans
Stream processing with Apache Flink - Maximilian Michels Data ArtisansStream processing with Apache Flink - Maximilian Michels Data Artisans
Stream processing with Apache Flink - Maximilian Michels Data ArtisansEvention
 
Sync or swim: the challenge of complex offline apps
Sync or swim:  the challenge of complex offline appsSync or swim:  the challenge of complex offline apps
Sync or swim: the challenge of complex offline appsOutSystems
 

Ähnlich wie A visual introduction to Event Sourcing and CQRS (9)

From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino...
From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino...From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino...
From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino...
 
Event sourcing for IoT and mobile - JAX London 2017
Event sourcing for IoT and mobile - JAX London 2017Event sourcing for IoT and mobile - JAX London 2017
Event sourcing for IoT and mobile - JAX London 2017
 
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
 
How Fast Data Is Turned into Fast Information and Timely Action (OOW 2014)
How Fast Data Is Turned into Fast Information and Timely Action (OOW 2014)How Fast Data Is Turned into Fast Information and Timely Action (OOW 2014)
How Fast Data Is Turned into Fast Information and Timely Action (OOW 2014)
 
Introduction to ksqlDB and stream processing (Vish Srinivasan - Confluent)
Introduction to ksqlDB and stream processing (Vish Srinivasan  - Confluent)Introduction to ksqlDB and stream processing (Vish Srinivasan  - Confluent)
Introduction to ksqlDB and stream processing (Vish Srinivasan - Confluent)
 
Stream processing with Apache Flink - Maximilian Michels Data Artisans
Stream processing with Apache Flink - Maximilian Michels Data ArtisansStream processing with Apache Flink - Maximilian Michels Data Artisans
Stream processing with Apache Flink - Maximilian Michels Data Artisans
 
Big Data Warsaw
Big Data WarsawBig Data Warsaw
Big Data Warsaw
 
Sync or swim: the challenge of complex offline apps
Sync or swim:  the challenge of complex offline appsSync or swim:  the challenge of complex offline apps
Sync or swim: the challenge of complex offline apps
 
How fast data is turned into fast information and timely action - Oracle Open...
How fast data is turned into fast information and timely action - Oracle Open...How fast data is turned into fast information and timely action - Oracle Open...
How fast data is turned into fast information and timely action - Oracle Open...
 

Kürzlich hochgeladen

Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
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
 
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
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 

Kürzlich hochgeladen (20)

Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
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...
 
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
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 

A visual introduction to Event Sourcing and CQRS

  • 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