SlideShare a Scribd company logo
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
From C to Q

one Event at a time
1
Lorenzo Nicora
OpenCredo
Event Sourcing illustrated
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
Lorenzo Nicora
@nicusX
lorenzo.nicora@opencredo.com
https://opencredo.com/author/lorenzo/
Senior Consultant
@ OpenCredo, London
• Microservices
• Cloud
• Event-driven, Event Sourcing, Reactive
• Java, Spring, Akka…
2
3
Concepts from DDD
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
Aggregate
Event Sourcing,CQRS => DDD/
State: f(t)
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 4
Once upon a time…
Everything was Synchronous
Request <-> Response
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 5
Scaling out…
Updates —> Locks —> Contention!
<— Block! <—
-> Distributed

still Synchronous
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 6
Let’s go Asynchronous
-> Distributed & Message-driven
Request/Response ACID Transactions
• Distributed: Propagation takes time
• Async: No global order strictly guaranteed
Updates applied in the wrong order
=> Inconsistent state!
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 7
Command Sourcing
💡
• Append Only —> No Contention, No Update
• Build State from Commands history
K/V Store
—> scale horizontally
Command
“Submit this Order!”
-> A request (imperative sentence)
-> May fail, be rejected
-> May affect multiple Aggregates
8
Commands
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
✉
Rebuild Aggregate State 

from Commands
9
Events
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
Event
“Order submitted”
-> Statement of facts (past tense)
-> Never fails
-> Can’t be changed
-> May be designed 

to affect a single Aggregate
✉
Rebuild Aggregate State 

from Events
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 10
Command > Event Sourcing
💡
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 11
Commands to Events
X
Y
Z
?
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 12
(Business) Consistency
ACID
Eventual (Business) Consistency
Guess —> Compensate—> Apologies
Long (Business) Transactions
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 13
e.g. Saga
Stateful
Out of band
Corrective Action

(Command / Event)
Saga
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
–Greg Young
(and Pat Helland before him, https://goo.gl/dCKDgw )
“Accountants don’t use pencils.
They use pens”
Corrective Actions
14
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 15
Benefits of Event Sourcing
History
(for free)
Rebuild State 

at a point in Time
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 16
Benefits of Event Sourcing
Easier

Eventual Business Consistency
—> Corrective Events
Robust to data corruption
(bugs, malicious, fat fingers…)
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 17
Benefits of Event Sourcing
Horizontal Scalability
&
Low Latency commands
-> Distributed systems & data store
—> Append-only Log
—> Asynchronous processing
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
18
Commands to Events
Stateful: Events depends 0n current State
Stateless: Validate, split by Aggregate…
Depends on
Business
Domain
x Point of synchronisation

? Out-of-order commands (IoT, Mobile)
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 19
Thinking fast or slow
Stateless:

Think fast,
Write fast,
More thinking later
Stateful:

Think slow…(rebuild state),
Write fast,
Less thinking later
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
What about reads?
20
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 21
Retrieving the State
How do I retrieve the State?
“Get details of Order ‘AB123’”
❔
not very efficient, but…
…may work
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 22
Querying (Searching) the State
❓ How do query the State?
“Get all Orders delivered to ‘SE1 0NZ’”
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 23
CQRS
Command
Query
Responsibility
Segregation
💡
Separate
• Code
• muService
• Datastore
-> Update
-—> Retrieve
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 24
Not a new idea
Specialised
Downstream
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 25
CQRS and Event Sourcing
Event Sourcing => CQRS
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 26
Materialised Views
• In Memory

K/V Store

Graph DB

RDBMS

• Rebuildable

from Events
💡
a.k.a.
Read-optimised Views
Read Views
Projections…
“Weak” persistence
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 27
Materialised Views
* May be updated asynchronously
+ low latency writes, scalability
- delayed
+ may reorder Events
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 28
Forward compatibility
The Event Log
is your Source of Truth
* Easy to evolve or fix
—> change or fix logic;
rebuild view from events
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 29
Indexes
• Search Engines

K/V Stores

Graph DB
+ Optimised for querying (less for retrieving)
+ Reduced delay of State
💡
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 30
Hybrid solutions: e.g. Snapshots
+ Speed up rebuilding the State
+ Use recent Events to rebuild up-to-date
💡 Long delayed
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 31
Multiple Read Models
* Read Models are optimised for 

specific query use case
Event stream —> multiple Read Models
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 32
Lesson

from the Trenches
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 33
Lesson Learned #1
If you put data in…
…you will eventually

have to get them out!
The “Query” side 

is not secondary
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 34
Lessons Learned #2
In old days:

normalising one DB 

to support as many queries as possible
With CQRS (also No SQL in general) 

multiple denormalised read models

optimised for different queries
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 35
Lessons Learned #3
Don’t use 

Event Sourcing
if your behaviour 

is CRUD
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
+++ Summing up +++
36
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 37
ES/CQRS Drawbacks
x No “One-Q-Fits-All”
—> Multiple “Q” implementations
x Delayed reads
x No ACID Transactions
x Additional complexity (!!!)
🙁
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 38
ES/CQRS Benefits
+ C and Q scale independently
+ Distributed systems (Microservices)
+ Eventual (Business) Consistency
+ History, Temporal queries
+ Robust to data corruption
😀
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 39
Happy use case
Stateless Command processing
(Commands —> Events)
+ High Volume (Big Data)
+ Low-latency commands
+ Out-of-order Commands

(IoT, Mobile)
😀
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
That’s all, Folks!
40
Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX
??? Questions ???
41
Thanks.
⏳

More Related Content

Similar to From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino 2017]

A visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRSA visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRS
Lorenzo Nicora
 
Purple seven-ntxissacsc5 walcutt
Purple seven-ntxissacsc5 walcuttPurple seven-ntxissacsc5 walcutt
Purple seven-ntxissacsc5 walcutt
North Texas Chapter of the ISSA
 
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа....NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
NETFest
 
Scylla Summit 2022: Stream Processing with ScyllaDB
Scylla Summit 2022: Stream Processing with ScyllaDBScylla Summit 2022: Stream Processing with ScyllaDB
Scylla Summit 2022: Stream Processing with ScyllaDB
ScyllaDB
 
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
Dina Goldshtein
 
Microservices, geerdet
Microservices, geerdetMicroservices, geerdet
Microservices, geerdet
inovex GmbH
 
Unify Stream and Batch Processing using Dataflow, a Portable Programmable Mod...
Unify Stream and Batch Processing using Dataflow, a Portable Programmable Mod...Unify Stream and Batch Processing using Dataflow, a Portable Programmable Mod...
Unify Stream and Batch Processing using Dataflow, a Portable Programmable Mod...
DataWorks Summit
 
Understanding and Deploying DNSSEC, by Champika Wijayatunga [APRICOT 2015]
Understanding and Deploying DNSSEC, by Champika Wijayatunga [APRICOT 2015]Understanding and Deploying DNSSEC, by Champika Wijayatunga [APRICOT 2015]
Understanding and Deploying DNSSEC, by Champika Wijayatunga [APRICOT 2015]
APNIC
 
Enterprise Ready: A Look at Neo4j in Production
Enterprise Ready: A Look at Neo4j in ProductionEnterprise Ready: A Look at Neo4j in Production
Enterprise Ready: A Look at Neo4j in Production
Neo4j
 
Cisco and Splunk: Under the Hood of Cisco IT Breakout Session
Cisco and Splunk: Under the Hood of Cisco IT Breakout SessionCisco and Splunk: Under the Hood of Cisco IT Breakout Session
Cisco and Splunk: Under the Hood of Cisco IT Breakout Session
Splunk
 
The Decomposition Dilemma
The Decomposition DilemmaThe Decomposition Dilemma
The Decomposition Dilemma
JoAnna Cheshire
 
Patterns of Streaming Applications
Patterns of Streaming ApplicationsPatterns of Streaming Applications
Patterns of Streaming Applications
C4Media
 
DNSSEC Deployment for .VN and share information of DNSSEC's plan in 2017
DNSSEC Deployment for .VN and share information of DNSSEC's plan in 2017DNSSEC Deployment for .VN and share information of DNSSEC's plan in 2017
DNSSEC Deployment for .VN and share information of DNSSEC's plan in 2017
APNIC
 
[Heap con19] designing data intensive applications in serverless architecture
[Heap con19] designing data intensive applications in serverless architecture[Heap con19] designing data intensive applications in serverless architecture
[Heap con19] designing data intensive applications in serverless architecture
Nikolay Matvienko
 
WSO2Con USA 2015: Patterns for Deploying Analytics in the Real World
WSO2Con USA 2015: Patterns for Deploying Analytics in the Real WorldWSO2Con USA 2015: Patterns for Deploying Analytics in the Real World
WSO2Con USA 2015: Patterns for Deploying Analytics in the Real World
WSO2
 
.NET Fest 2019. Денис Резник. Когда SQL Server Best Practices не работают
.NET Fest 2019. Денис Резник. Когда SQL Server Best Practices не работают.NET Fest 2019. Денис Резник. Когда SQL Server Best Practices не работают
.NET Fest 2019. Денис Резник. Когда SQL Server Best Practices не работают
NETFest
 
Rolling the Root Zone DNSSEC Key Signing Key
Rolling the Root Zone DNSSEC Key Signing KeyRolling the Root Zone DNSSEC Key Signing Key
Rolling the Root Zone DNSSEC Key Signing Key
APNIC
 
Our journey with druid - from initial research to full production scale
Our journey with druid - from initial research to full production scaleOur journey with druid - from initial research to full production scale
Our journey with druid - from initial research to full production scale
Itai Yaffe
 
Sizing MongoDB Clusters
Sizing MongoDB Clusters Sizing MongoDB Clusters
Sizing MongoDB Clusters
MongoDB
 
SplunkLive! Warsaw 2016 - Cisco
SplunkLive! Warsaw 2016 - Cisco SplunkLive! Warsaw 2016 - Cisco
SplunkLive! Warsaw 2016 - Cisco
Splunk
 

Similar to From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino 2017] (20)

A visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRSA visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRS
 
Purple seven-ntxissacsc5 walcutt
Purple seven-ntxissacsc5 walcuttPurple seven-ntxissacsc5 walcutt
Purple seven-ntxissacsc5 walcutt
 
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа....NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
.NET Fest 2017. Денис Резник. Исполнение Запроса в SQL Server. Ожидание - Реа...
 
Scylla Summit 2022: Stream Processing with ScyllaDB
Scylla Summit 2022: Stream Processing with ScyllaDBScylla Summit 2022: Stream Processing with ScyllaDB
Scylla Summit 2022: Stream Processing with ScyllaDB
 
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
ETW - Monitor Anything, Anytime, Anywhere (NDC Oslo 2017)
 
Microservices, geerdet
Microservices, geerdetMicroservices, geerdet
Microservices, geerdet
 
Unify Stream and Batch Processing using Dataflow, a Portable Programmable Mod...
Unify Stream and Batch Processing using Dataflow, a Portable Programmable Mod...Unify Stream and Batch Processing using Dataflow, a Portable Programmable Mod...
Unify Stream and Batch Processing using Dataflow, a Portable Programmable Mod...
 
Understanding and Deploying DNSSEC, by Champika Wijayatunga [APRICOT 2015]
Understanding and Deploying DNSSEC, by Champika Wijayatunga [APRICOT 2015]Understanding and Deploying DNSSEC, by Champika Wijayatunga [APRICOT 2015]
Understanding and Deploying DNSSEC, by Champika Wijayatunga [APRICOT 2015]
 
Enterprise Ready: A Look at Neo4j in Production
Enterprise Ready: A Look at Neo4j in ProductionEnterprise Ready: A Look at Neo4j in Production
Enterprise Ready: A Look at Neo4j in Production
 
Cisco and Splunk: Under the Hood of Cisco IT Breakout Session
Cisco and Splunk: Under the Hood of Cisco IT Breakout SessionCisco and Splunk: Under the Hood of Cisco IT Breakout Session
Cisco and Splunk: Under the Hood of Cisco IT Breakout Session
 
The Decomposition Dilemma
The Decomposition DilemmaThe Decomposition Dilemma
The Decomposition Dilemma
 
Patterns of Streaming Applications
Patterns of Streaming ApplicationsPatterns of Streaming Applications
Patterns of Streaming Applications
 
DNSSEC Deployment for .VN and share information of DNSSEC's plan in 2017
DNSSEC Deployment for .VN and share information of DNSSEC's plan in 2017DNSSEC Deployment for .VN and share information of DNSSEC's plan in 2017
DNSSEC Deployment for .VN and share information of DNSSEC's plan in 2017
 
[Heap con19] designing data intensive applications in serverless architecture
[Heap con19] designing data intensive applications in serverless architecture[Heap con19] designing data intensive applications in serverless architecture
[Heap con19] designing data intensive applications in serverless architecture
 
WSO2Con USA 2015: Patterns for Deploying Analytics in the Real World
WSO2Con USA 2015: Patterns for Deploying Analytics in the Real WorldWSO2Con USA 2015: Patterns for Deploying Analytics in the Real World
WSO2Con USA 2015: Patterns for Deploying Analytics in the Real World
 
.NET Fest 2019. Денис Резник. Когда SQL Server Best Practices не работают
.NET Fest 2019. Денис Резник. Когда SQL Server Best Practices не работают.NET Fest 2019. Денис Резник. Когда SQL Server Best Practices не работают
.NET Fest 2019. Денис Резник. Когда SQL Server Best Practices не работают
 
Rolling the Root Zone DNSSEC Key Signing Key
Rolling the Root Zone DNSSEC Key Signing KeyRolling the Root Zone DNSSEC Key Signing Key
Rolling the Root Zone DNSSEC Key Signing Key
 
Our journey with druid - from initial research to full production scale
Our journey with druid - from initial research to full production scaleOur journey with druid - from initial research to full production scale
Our journey with druid - from initial research to full production scale
 
Sizing MongoDB Clusters
Sizing MongoDB Clusters Sizing MongoDB Clusters
Sizing MongoDB Clusters
 
SplunkLive! Warsaw 2016 - Cisco
SplunkLive! Warsaw 2016 - Cisco SplunkLive! Warsaw 2016 - Cisco
SplunkLive! Warsaw 2016 - Cisco
 

Recently uploaded

14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
Massimo Artizzu
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 

Recently uploaded (20)

14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 

From C to Q, one event at the time: Event sourcing illustrated [Voxxed Ticino 2017]

  • 1. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX From C to Q
 one Event at a time 1 Lorenzo Nicora OpenCredo Event Sourcing illustrated
  • 2. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX Lorenzo Nicora @nicusX lorenzo.nicora@opencredo.com https://opencredo.com/author/lorenzo/ Senior Consultant @ OpenCredo, London • Microservices • Cloud • Event-driven, Event Sourcing, Reactive • Java, Spring, Akka… 2
  • 3. 3 Concepts from DDD Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX Aggregate Event Sourcing,CQRS => DDD/ State: f(t)
  • 4. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 4 Once upon a time… Everything was Synchronous Request <-> Response
  • 5. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 5 Scaling out… Updates —> Locks —> Contention! <— Block! <— -> Distributed
 still Synchronous
  • 6. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 6 Let’s go Asynchronous -> Distributed & Message-driven Request/Response ACID Transactions • Distributed: Propagation takes time • Async: No global order strictly guaranteed Updates applied in the wrong order => Inconsistent state!
  • 7. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 7 Command Sourcing 💡 • Append Only —> No Contention, No Update • Build State from Commands history K/V Store —> scale horizontally
  • 8. Command “Submit this Order!” -> A request (imperative sentence) -> May fail, be rejected -> May affect multiple Aggregates 8 Commands Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX ✉ Rebuild Aggregate State 
 from Commands
  • 9. 9 Events Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX Event “Order submitted” -> Statement of facts (past tense) -> Never fails -> Can’t be changed -> May be designed 
 to affect a single Aggregate ✉ Rebuild Aggregate State 
 from Events
  • 10. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 10 Command > Event Sourcing 💡
  • 11. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 11 Commands to Events X Y Z ?
  • 12. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 12 (Business) Consistency ACID Eventual (Business) Consistency Guess —> Compensate—> Apologies Long (Business) Transactions
  • 13. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 13 e.g. Saga Stateful Out of band Corrective Action
 (Command / Event) Saga
  • 14. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX –Greg Young (and Pat Helland before him, https://goo.gl/dCKDgw ) “Accountants don’t use pencils. They use pens” Corrective Actions 14
  • 15. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 15 Benefits of Event Sourcing History (for free) Rebuild State 
 at a point in Time
  • 16. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 16 Benefits of Event Sourcing Easier
 Eventual Business Consistency —> Corrective Events Robust to data corruption (bugs, malicious, fat fingers…)
  • 17. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 17 Benefits of Event Sourcing Horizontal Scalability & Low Latency commands -> Distributed systems & data store —> Append-only Log —> Asynchronous processing
  • 18. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 18 Commands to Events Stateful: Events depends 0n current State Stateless: Validate, split by Aggregate… Depends on Business Domain x Point of synchronisation
 ? Out-of-order commands (IoT, Mobile)
  • 19. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 19 Thinking fast or slow Stateless:
 Think fast, Write fast, More thinking later Stateful:
 Think slow…(rebuild state), Write fast, Less thinking later
  • 20. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX What about reads? 20
  • 21. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 21 Retrieving the State How do I retrieve the State? “Get details of Order ‘AB123’” ❔ not very efficient, but… …may work
  • 22. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 22 Querying (Searching) the State ❓ How do query the State? “Get all Orders delivered to ‘SE1 0NZ’”
  • 23. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 23 CQRS Command Query Responsibility Segregation 💡 Separate • Code • muService • Datastore -> Update -—> Retrieve
  • 24. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 24 Not a new idea Specialised Downstream
  • 25. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 25 CQRS and Event Sourcing Event Sourcing => CQRS
  • 26. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 26 Materialised Views • In Memory
 K/V Store
 Graph DB
 RDBMS
 • Rebuildable
 from Events 💡 a.k.a. Read-optimised Views Read Views Projections… “Weak” persistence
  • 27. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 27 Materialised Views * May be updated asynchronously + low latency writes, scalability - delayed + may reorder Events
  • 28. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 28 Forward compatibility The Event Log is your Source of Truth * Easy to evolve or fix —> change or fix logic; rebuild view from events
  • 29. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 29 Indexes • Search Engines
 K/V Stores
 Graph DB + Optimised for querying (less for retrieving) + Reduced delay of State 💡
  • 30. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 30 Hybrid solutions: e.g. Snapshots + Speed up rebuilding the State + Use recent Events to rebuild up-to-date 💡 Long delayed
  • 31. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 31 Multiple Read Models * Read Models are optimised for 
 specific query use case Event stream —> multiple Read Models
  • 32. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 32 Lesson
 from the Trenches
  • 33. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 33 Lesson Learned #1 If you put data in… …you will eventually
 have to get them out! The “Query” side 
 is not secondary
  • 34. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 34 Lessons Learned #2 In old days:
 normalising one DB 
 to support as many queries as possible With CQRS (also No SQL in general) 
 multiple denormalised read models
 optimised for different queries
  • 35. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 35 Lessons Learned #3 Don’t use 
 Event Sourcing if your behaviour 
 is CRUD
  • 36. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX +++ Summing up +++ 36
  • 37. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 37 ES/CQRS Drawbacks x No “One-Q-Fits-All” —> Multiple “Q” implementations x Delayed reads x No ACID Transactions x Additional complexity (!!!) 🙁
  • 38. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 38 ES/CQRS Benefits + C and Q scale independently + Distributed systems (Microservices) + Eventual (Business) Consistency + History, Temporal queries + Robust to data corruption 😀
  • 39. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX 39 Happy use case Stateless Command processing (Commands —> Events) + High Volume (Big Data) + Low-latency commands + Out-of-order Commands
 (IoT, Mobile) 😀
  • 40. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX That’s all, Folks! 40
  • 41. Voxxed Days Ticino 2017 Lorenzo Nicora - @nicusX ??? Questions ??? 41 Thanks. ⏳