SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
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 BeneïŹts
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 BeneïŹts
History
(for free)
Rebuild State ‹
at a point in Time
Lorenzo Nicora Intro to Event Sourcing and CQRS
14
Main BeneïŹt
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 BeneïŹts
+ 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

Mais conteĂșdo relacionado

Destaque

Machine Learning & IT Service Intelligence for the Enterprise: The Future is ...
Machine Learning & IT Service Intelligence for the Enterprise: The Future is ...Machine Learning & IT Service Intelligence for the Enterprise: The Future is ...
Machine Learning & IT Service Intelligence for the Enterprise: The Future is ...Precisely
 
CatĂĄlogo 15 16 elksport
CatĂĄlogo 15 16 elksportCatĂĄlogo 15 16 elksport
CatĂĄlogo 15 16 elksportElk Sport
 
Developing highly scalable applications with Symfony and RabbitMQ
Developing highly scalable applications with  Symfony and RabbitMQDeveloping highly scalable applications with  Symfony and RabbitMQ
Developing highly scalable applications with Symfony and RabbitMQAlexey Petrov
 
Python Pants Build System for Large Codebases
Python Pants Build System for Large CodebasesPython Pants Build System for Large Codebases
Python Pants Build System for Large CodebasesAngad Singh
 
CloudStack EU user group - Trillian
CloudStack EU user group - TrillianCloudStack EU user group - Trillian
CloudStack EU user group - TrillianShapeBlue
 
NSM (Network Security Monitoring) - Tecland Chapeco
NSM (Network Security Monitoring) - Tecland ChapecoNSM (Network Security Monitoring) - Tecland Chapeco
NSM (Network Security Monitoring) - Tecland ChapecoRodrigo Montoro
 
Automated Infrastructure Security: Monitoring using FOSS
Automated Infrastructure Security: Monitoring using FOSSAutomated Infrastructure Security: Monitoring using FOSS
Automated Infrastructure Security: Monitoring using FOSSSonatype
 
Gaurav dev ops (AWS, Linux, Automation-ansible, jenkins:CI and CD:Ansible)
Gaurav dev ops (AWS, Linux, Automation-ansible, jenkins:CI and CD:Ansible)Gaurav dev ops (AWS, Linux, Automation-ansible, jenkins:CI and CD:Ansible)
Gaurav dev ops (AWS, Linux, Automation-ansible, jenkins:CI and CD:Ansible)Gaurav Srivastav
 
Bridging the Gap: Connecting AWS and Kafka
Bridging the Gap: Connecting AWS and KafkaBridging the Gap: Connecting AWS and Kafka
Bridging the Gap: Connecting AWS and KafkaPengfei (Jason) Li
 
Platform - Technical architecture
Platform - Technical architecturePlatform - Technical architecture
Platform - Technical architectureDavid Rundle
 
Yirgacheffe Chelelelktu Washed Coffee 2015
Yirgacheffe Chelelelktu Washed Coffee 2015Yirgacheffe Chelelelktu Washed Coffee 2015
Yirgacheffe Chelelelktu Washed Coffee 2015Golden Future Trading Ltd
 
Apostila De Dispositivos EléTricos
Apostila De Dispositivos EléTricosApostila De Dispositivos EléTricos
Apostila De Dispositivos EléTricoselkbcion
 
Choosing the right data storage in the Cloud.
Choosing the right data storage in the Cloud. Choosing the right data storage in the Cloud.
Choosing the right data storage in the Cloud. Amazon Web Services
 
Chicago AWS user group meetup - May 2014 at Cohesive
Chicago AWS user group meetup - May 2014 at CohesiveChicago AWS user group meetup - May 2014 at Cohesive
Chicago AWS user group meetup - May 2014 at CohesiveAWS Chicago
 
Aws + Puppet = Dynamic Scale
Aws + Puppet = Dynamic ScaleAws + Puppet = Dynamic Scale
Aws + Puppet = Dynamic ScalePuppet
 
Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...
Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...
Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...Nagios
 
Streaming architecture with HDP & ELK
Streaming architecture with HDP & ELKStreaming architecture with HDP & ELK
Streaming architecture with HDP & ELKAlain Douangpraseuth
 
Persistence in the cloud with bosh
Persistence in the cloud with boshPersistence in the cloud with bosh
Persistence in the cloud with boshm_richardson
 

Destaque (20)

Machine Learning & IT Service Intelligence for the Enterprise: The Future is ...
Machine Learning & IT Service Intelligence for the Enterprise: The Future is ...Machine Learning & IT Service Intelligence for the Enterprise: The Future is ...
Machine Learning & IT Service Intelligence for the Enterprise: The Future is ...
 
CatĂĄlogo 15 16 elksport
CatĂĄlogo 15 16 elksportCatĂĄlogo 15 16 elksport
CatĂĄlogo 15 16 elksport
 
Developing highly scalable applications with Symfony and RabbitMQ
Developing highly scalable applications with  Symfony and RabbitMQDeveloping highly scalable applications with  Symfony and RabbitMQ
Developing highly scalable applications with Symfony and RabbitMQ
 
Python Pants Build System for Large Codebases
Python Pants Build System for Large CodebasesPython Pants Build System for Large Codebases
Python Pants Build System for Large Codebases
 
CloudStack EU user group - Trillian
CloudStack EU user group - TrillianCloudStack EU user group - Trillian
CloudStack EU user group - Trillian
 
NSM (Network Security Monitoring) - Tecland Chapeco
NSM (Network Security Monitoring) - Tecland ChapecoNSM (Network Security Monitoring) - Tecland Chapeco
NSM (Network Security Monitoring) - Tecland Chapeco
 
Automated Infrastructure Security: Monitoring using FOSS
Automated Infrastructure Security: Monitoring using FOSSAutomated Infrastructure Security: Monitoring using FOSS
Automated Infrastructure Security: Monitoring using FOSS
 
Gaurav dev ops (AWS, Linux, Automation-ansible, jenkins:CI and CD:Ansible)
Gaurav dev ops (AWS, Linux, Automation-ansible, jenkins:CI and CD:Ansible)Gaurav dev ops (AWS, Linux, Automation-ansible, jenkins:CI and CD:Ansible)
Gaurav dev ops (AWS, Linux, Automation-ansible, jenkins:CI and CD:Ansible)
 
Bridging the Gap: Connecting AWS and Kafka
Bridging the Gap: Connecting AWS and KafkaBridging the Gap: Connecting AWS and Kafka
Bridging the Gap: Connecting AWS and Kafka
 
Platform - Technical architecture
Platform - Technical architecturePlatform - Technical architecture
Platform - Technical architecture
 
Yirgacheffe Chelelelktu Washed Coffee 2015
Yirgacheffe Chelelelktu Washed Coffee 2015Yirgacheffe Chelelelktu Washed Coffee 2015
Yirgacheffe Chelelelktu Washed Coffee 2015
 
ITV& Bashton
ITV& Bashton ITV& Bashton
ITV& Bashton
 
Apostila De Dispositivos EléTricos
Apostila De Dispositivos EléTricosApostila De Dispositivos EléTricos
Apostila De Dispositivos EléTricos
 
Linux Malware Analysis
Linux Malware Analysis	Linux Malware Analysis
Linux Malware Analysis
 
Choosing the right data storage in the Cloud.
Choosing the right data storage in the Cloud. Choosing the right data storage in the Cloud.
Choosing the right data storage in the Cloud.
 
Chicago AWS user group meetup - May 2014 at Cohesive
Chicago AWS user group meetup - May 2014 at CohesiveChicago AWS user group meetup - May 2014 at Cohesive
Chicago AWS user group meetup - May 2014 at Cohesive
 
Aws + Puppet = Dynamic Scale
Aws + Puppet = Dynamic ScaleAws + Puppet = Dynamic Scale
Aws + Puppet = Dynamic Scale
 
Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...
Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...
Nagios Conference 2014 - Fernando Covatti - Nagios in Power Transmission Util...
 
Streaming architecture with HDP & ELK
Streaming architecture with HDP & ELKStreaming architecture with HDP & ELK
Streaming architecture with HDP & ELK
 
Persistence in the cloud with bosh
Persistence in the cloud with boshPersistence in the cloud with bosh
Persistence in the cloud with bosh
 

Semelhante a An 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
 

Semelhante a An 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)
 
Big Data Warsaw
Big Data WarsawBig Data Warsaw
Big Data Warsaw
 
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
 
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...
 

Mais de Haufe-Lexware GmbH & Co KG

X-celerate 2019: Iterating fast with the MERN Stack
X-celerate 2019: Iterating fast with the MERN StackX-celerate 2019: Iterating fast with the MERN Stack
X-celerate 2019: Iterating fast with the MERN StackHaufe-Lexware GmbH & Co KG
 
Nils Rhode - Does it always have to be k8s - TeC Day 2019
Nils Rhode - Does it always have to be k8s - TeC Day 2019Nils Rhode - Does it always have to be k8s - TeC Day 2019
Nils Rhode - Does it always have to be k8s - TeC Day 2019Haufe-Lexware GmbH & Co KG
 
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019Haufe-Lexware GmbH & Co KG
 
Cloud Journey: Lifting a Major Product to Kubernetes
Cloud Journey: Lifting a Major Product to KubernetesCloud Journey: Lifting a Major Product to Kubernetes
Cloud Journey: Lifting a Major Product to KubernetesHaufe-Lexware GmbH & Co KG
 
ONA ( organizational network analysis ) to enable individuals to impact their...
ONA ( organizational network analysis ) to enable individuals to impact their...ONA ( organizational network analysis ) to enable individuals to impact their...
ONA ( organizational network analysis ) to enable individuals to impact their...Haufe-Lexware GmbH & Co KG
 
ONA ( organizational network analysis ) enabling individuals to impact their ...
ONA ( organizational network analysis ) enabling individuals to impact their ...ONA ( organizational network analysis ) enabling individuals to impact their ...
ONA ( organizational network analysis ) enabling individuals to impact their ...Haufe-Lexware GmbH & Co KG
 
Using word vectors to enable better search in our legal products
Using word vectors to enable better search in our legal productsUsing word vectors to enable better search in our legal products
Using word vectors to enable better search in our legal productsHaufe-Lexware GmbH & Co KG
 
Identifying customer potentials through unsupervised learning
Identifying customer potentials through unsupervised learningIdentifying customer potentials through unsupervised learning
Identifying customer potentials through unsupervised learningHaufe-Lexware GmbH & Co KG
 
Field report: Rapid application development
Field report: Rapid application developmentField report: Rapid application development
Field report: Rapid application developmentHaufe-Lexware GmbH & Co KG
 
Externalized Spring Boot App Configuration
Externalized  Spring Boot App ConfigurationExternalized  Spring Boot App Configuration
Externalized Spring Boot App ConfigurationHaufe-Lexware GmbH & Co KG
 
Managing short lived Kubernetes (Production) deployments
Managing short lived Kubernetes (Production) deploymentsManaging short lived Kubernetes (Production) deployments
Managing short lived Kubernetes (Production) deploymentsHaufe-Lexware GmbH & Co KG
 
DevOps Journey of Foundational Services at Haufe
DevOps Journey of Foundational Services at HaufeDevOps Journey of Foundational Services at Haufe
DevOps Journey of Foundational Services at HaufeHaufe-Lexware GmbH & Co KG
 
New Serverless World - Cloud Native Apps
New Serverless World - Cloud Native AppsNew Serverless World - Cloud Native Apps
New Serverless World - Cloud Native AppsHaufe-Lexware GmbH & Co KG
 
Microservice Transformation of the Haufe Publishing System
Microservice Transformation of the Haufe Publishing SystemMicroservice Transformation of the Haufe Publishing System
Microservice Transformation of the Haufe Publishing SystemHaufe-Lexware GmbH & Co KG
 

Mais de Haufe-Lexware GmbH & Co KG (20)

Tech stackhaufegroup
Tech stackhaufegroupTech stackhaufegroup
Tech stackhaufegroup
 
X-celerate 2019: Iterating fast with the MERN Stack
X-celerate 2019: Iterating fast with the MERN StackX-celerate 2019: Iterating fast with the MERN Stack
X-celerate 2019: Iterating fast with the MERN Stack
 
Nils Rhode - Does it always have to be k8s - TeC Day 2019
Nils Rhode - Does it always have to be k8s - TeC Day 2019Nils Rhode - Does it always have to be k8s - TeC Day 2019
Nils Rhode - Does it always have to be k8s - TeC Day 2019
 
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
 
Cloud Journey: Lifting a Major Product to Kubernetes
Cloud Journey: Lifting a Major Product to KubernetesCloud Journey: Lifting a Major Product to Kubernetes
Cloud Journey: Lifting a Major Product to Kubernetes
 
ONA ( organizational network analysis ) to enable individuals to impact their...
ONA ( organizational network analysis ) to enable individuals to impact their...ONA ( organizational network analysis ) to enable individuals to impact their...
ONA ( organizational network analysis ) to enable individuals to impact their...
 
ONA ( organizational network analysis ) enabling individuals to impact their ...
ONA ( organizational network analysis ) enabling individuals to impact their ...ONA ( organizational network analysis ) enabling individuals to impact their ...
ONA ( organizational network analysis ) enabling individuals to impact their ...
 
Using word vectors to enable better search in our legal products
Using word vectors to enable better search in our legal productsUsing word vectors to enable better search in our legal products
Using word vectors to enable better search in our legal products
 
Identifying customer potentials through unsupervised learning
Identifying customer potentials through unsupervised learningIdentifying customer potentials through unsupervised learning
Identifying customer potentials through unsupervised learning
 
Field report: Rapid application development
Field report: Rapid application developmentField report: Rapid application development
Field report: Rapid application development
 
Behavior-Driven Development with JGiven
Behavior-Driven Development with JGivenBehavior-Driven Development with JGiven
Behavior-Driven Development with JGiven
 
Externalized Spring Boot App Configuration
Externalized  Spring Boot App ConfigurationExternalized  Spring Boot App Configuration
Externalized Spring Boot App Configuration
 
Managing short lived Kubernetes (Production) deployments
Managing short lived Kubernetes (Production) deploymentsManaging short lived Kubernetes (Production) deployments
Managing short lived Kubernetes (Production) deployments
 
Docker in Production at the Aurora Team
Docker in Production at the Aurora TeamDocker in Production at the Aurora Team
Docker in Production at the Aurora Team
 
DevOps Journey of Foundational Services at Haufe
DevOps Journey of Foundational Services at HaufeDevOps Journey of Foundational Services at Haufe
DevOps Journey of Foundational Services at Haufe
 
New Serverless World - Cloud Native Apps
New Serverless World - Cloud Native AppsNew Serverless World - Cloud Native Apps
New Serverless World - Cloud Native Apps
 
Microservice Transformation of the Haufe Publishing System
Microservice Transformation of the Haufe Publishing SystemMicroservice Transformation of the Haufe Publishing System
Microservice Transformation of the Haufe Publishing System
 
Haufe API Strategy
Haufe API StrategyHaufe API Strategy
Haufe API Strategy
 
Haufe's Tech Strategy In Practice
Haufe's Tech Strategy In PracticeHaufe's Tech Strategy In Practice
Haufe's Tech Strategy In Practice
 
Kubernetes Intro @HaufeDev
Kubernetes Intro @HaufeDev Kubernetes Intro @HaufeDev
Kubernetes Intro @HaufeDev
 

Último

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
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...panagenda
 
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 GoalsJhone kinadey
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
(Genuine) Escort Service Lucknow | Starting â‚č,5K To @25k with A/C đŸ§‘đŸœâ€â€ïžâ€đŸ§‘đŸ» 89...
(Genuine) Escort Service Lucknow | Starting â‚č,5K To @25k with A/C đŸ§‘đŸœâ€â€ïžâ€đŸ§‘đŸ» 89...(Genuine) Escort Service Lucknow | Starting â‚č,5K To @25k with A/C đŸ§‘đŸœâ€â€ïžâ€đŸ§‘đŸ» 89...
(Genuine) Escort Service Lucknow | Starting â‚č,5K To @25k with A/C đŸ§‘đŸœâ€â€ïžâ€đŸ§‘đŸ» 89...gurkirankumar98700
 
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 ApplicationsAlberto GonzĂĄlez Trastoy
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Último (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
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...
 
Call Girls In Mukherjee Nagar đŸ“± 9999965857 đŸ€© Delhi đŸ«Š HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar đŸ“±  9999965857  đŸ€© Delhi đŸ«Š HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar đŸ“±  9999965857  đŸ€© Delhi đŸ«Š HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar đŸ“± 9999965857 đŸ€© Delhi đŸ«Š HOT AND SEXY VVIP 🍎 SE...
 
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
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
(Genuine) Escort Service Lucknow | Starting â‚č,5K To @25k with A/C đŸ§‘đŸœâ€â€ïžâ€đŸ§‘đŸ» 89...
(Genuine) Escort Service Lucknow | Starting â‚č,5K To @25k with A/C đŸ§‘đŸœâ€â€ïžâ€đŸ§‘đŸ» 89...(Genuine) Escort Service Lucknow | Starting â‚č,5K To @25k with A/C đŸ§‘đŸœâ€â€ïžâ€đŸ§‘đŸ» 89...
(Genuine) Escort Service Lucknow | Starting â‚č,5K To @25k with A/C đŸ§‘đŸœâ€â€ïžâ€đŸ§‘đŸ» 89...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
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
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

An 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 BeneïŹts 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 BeneïŹts History (for free) Rebuild State ‹ at a point in Time Lorenzo Nicora Intro to Event Sourcing and CQRS
  • 14. 14 Main BeneïŹt 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 BeneïŹts + 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