SlideShare una empresa de Scribd logo
1 de 33
Dennis Doomen | @ddoomen | Aviva Solutions | The Continuous Improver
Web
Application
Command
Service
Query
Processor
ChangeUser
EmailHandler
User
Unit of
Work
User
Projector
DAL
Query
Handler
Read DB
Write DB
ChangeUserEmailCommand
Execute query
Get<User>(identity)
Invoke method
Event Store
Load(events)
Apply
Get changes
Dispatcher Events
Handle(UserEmailChangedEvent)
Submit changes
History
Query Language / SQL
Dennis Doomen | @ddoomen | The Continuous Improver
The Good
Domain
Event Store
Events
App
RDBMS
Events
Projection
EventsProjection
Projection
Projector
Optimized for
specific queries
Separate
projections
database NoSQL
Projector
Projection-specific
storage
Projector
HTML
Raw SQL, Dapper
or OR/M
Run
asynchronously
Great for
sharding
Dennis Doomen | @ddoomen | The Continuous Improver
Events
Transaction 6
Transaction 5
Transaction 4
Transaction 3
Transaction 2
Transaction 1
Temporal
Projector
Read
Store
Time
Projected until
this point
Immutable, thus
auditable and SOX
compliance
Dennis Doomen | @ddoomen | The Continuous Improver
Domain
Event Store
Events
App
Events
Projection
EventsProjection
Projection
Projector
Application
projections
RDBMS
Reporting
Projector
Traditional
reporting model
Asynchronous
OLAP
Dennis Doomen | @ddoomen | The Continuous Improver
StreamId: User-Dedo, Rev: 5
Persisted State Changes
StreamId: User-Dedo, Rev: 4
GrantedRoleEvent
PasswordChangedEvent
StreamId: User-Dedo, Rev: 4
StreamId: User-Dedo, Rev: 3
UserCreatedEvent
GrantedRoleEvent
PhoneNumberAddedEven
t
PasswordChangedEvent
StreamId: User-Dedo, Rev: 5
RoleRevokedEvent
StreamId: User-Dedo, Rev: 6
GrantedRoleEvent
Time
StreamId: User-Dedo, Rev: 7
PasswordChangedEvent
Dennis Doomen | @ddoomen | The Continuous Improver
Changes
1
2
3
6297
6298
6298
Query Data
Documents
Groups
Users
Objects
Folders
User
Interface
Changes Queries
Changes
1
2
3
6299
6300
6301
Query Data
Documents
Groups
Users
Objects
Folders
User
Interface
ChangesQueries
Node Node
Replication Process
Dennis Doomen | @ddoomen | The Continuous Improver
Events
Aggregate
Root
Entity
Entity
Value
Object
Aggregate
Root
Aggregate
Root
Aggregate
Root
Entity
Value
Object
Value
Object
Dennis Doomen | @ddoomen | The Continuous Improver
The Bad
The pains
of wrongly
designed
aggregates
• Designing your domain based on
ownership
• Relying on eventual consistent
projections
• Bad choice in functional keys (e.g.
username vs ID)
• Running business logic after an
domain event is raised
• Domain-specific value types in
events
• Fast growing aggregates
Finding the
right
boundaries
First
• Ask the difficult questions about
consistency
• Understand the real world
Then use these guidelines
• Driven by invariants, not
composition
• Only consistent within aggregate
• Small aggregates
• Reference by identity.
Practical
challenges
public class Order
{
private Status status;
public void Cancel()
{
if (status == Status.InProgress)
{
Apply(new OrderCanceledEvent());
}
}
private void When(OrderCanceledEvent e)
{
status = Status.Canceled;
}
}
In single classes
Dennis Doomen | @ddoomen | The Continuous Improver
public partial class Order
{
private Status status;
public void Cancel()
{
if (status == Status.InProgress)
{
Apply(new OrderCanceledEvent());
}
}
}
In partial classes
public partial class Order
{
private void When(OrderCanceledEvent e)
{
status = Status.Canceled;
}
}
Dennis Doomen | @ddoomen | The Continuous Improver
public class Order
{
private OrderState state;
public void Cancel()
{
if (state.Status == Status.InProgress)
{
state.Apply(new OrderCanceledEvent());
}
}
}
In separate classes
internal class OrderState
{
public Status Status { get; set; }
private void When(OrderCanceledEvent e)
{
Status = Status.Canceled;
}
}
Dennis Doomen | @ddoomen | The Continuous Improver
Risk Assessment
Level Changed
Risk Assessment
Team Member
Removed
Risk Assessment
Team Member
Removed
Risk Assessment
Level Demoted
Versus
Dennis Doomen | @ddoomen | The Continuous Improver
Assembly
AvSol.Domain.dll
Namespace
AvSol.Domain.RiskAssessments
Type
RiskAssessmentLevelChanged
Assembly
AvSol.ThreadAssessment.dll
Namespace:
AvSol.ThreadAssessment.Risks.Domain
Type
RiskAssessmentLevelDowngraded
Dennis Doomen | @ddoomen | The Continuous Improver
The Ugly
Domain
Event Store
Events
App
Query
Store
Data Access
Projectors
Events
API Controller
Projections
Events
Figuring
out the
right
testing
scope
Projection
rebuilding
pains
Rebuilding time with large databases
• Side by side rebuilding (a.k.a. blue-
green)
• Functional archivability and archiving
• Projection tracking and prediction
• Clear separation between critical and
auxiliary data -> prioritization
• Partitioning.
Dynamic rebuilding
• After bugs, schema changes, etc
• Manual or automatic (e.g. hashes)
Projection consistency
• Idempotency of projections
• Projection autonomy results in
more duplication.
Projections that crash
• Column constraints (e.g. data
truncation)
• Changes in data invariants (null
vs non-null in event versions)
• Unexpected projection
dependencies
• Partial replays.
Projection dependencies
• Synchronous -> asynchronous and
existing bugs
• Assuming order of events
Bugs
• Causing duplicate child records
• Causing large event streams
• Incorrect caching strategy (e.g. on
lookups)
• Identity case-sensitivity
• Incomplete SQL-backed event store
reads.
Tips &
Tricks
• Liquid Projections
– Designed as a library
– Promotes fully autonomous
projections
– Local tracking
– ETA calculations
• NEventStore
• GetEventStore
• Apache Kafka?
• The Good, The Bad and the Ugly of Event
Sourcing
http://www.continuousimprover.com/search/label/event%20sourcing
• Effective Aggregate Design (Vaughn Vernon)
http://dddcommunity.org/library/vernon_2011/
• Liquid Projections
https://github.com/LiquidProjections
• Distributed Event Sourcing (Slides)
http://www.slideshare.net/dennisdoomen/building-occasionally-
connected-applications-using-event-sourcing
• Data schema changes in an event sourced
system (paper)
http://files.movereem.nl/2017saner-eventsourcing.pdf
The Good, The Bad and the Ugly of Event Sourcing

Más contenido relacionado

Más de Dennis Doomen

Más de Dennis Doomen (20)

What you can learn from an open-source project with 250 million downloads
What you can learn from an open-source project with 250 million downloadsWhat you can learn from an open-source project with 250 million downloads
What you can learn from an open-source project with 250 million downloads
 
Getting a grip on your code dependencies
Getting a grip on your code dependenciesGetting a grip on your code dependencies
Getting a grip on your code dependencies
 
My Laws of Test Driven Development (2023)
My Laws of Test Driven Development (2023)My Laws of Test Driven Development (2023)
My Laws of Test Driven Development (2023)
 
Design patterns for Event Sourcing in .NET
Design patterns for Event Sourcing in .NETDesign patterns for Event Sourcing in .NET
Design patterns for Event Sourcing in .NET
 
Automate Infrastructure with Pulumi and C#
Automate Infrastructure with Pulumi and C#Automate Infrastructure with Pulumi and C#
Automate Infrastructure with Pulumi and C#
 
What is the right unit in unit testing (UpdateConf 2022)
What is the right unit in unit testing (UpdateConf 2022)What is the right unit in unit testing (UpdateConf 2022)
What is the right unit in unit testing (UpdateConf 2022)
 
Slow Event Sourcing (re)projections - Just make them faster!
Slow Event Sourcing (re)projections - Just make them faster!Slow Event Sourcing (re)projections - Just make them faster!
Slow Event Sourcing (re)projections - Just make them faster!
 
50 things software teams should not do.pptx
50 things software teams should not do.pptx50 things software teams should not do.pptx
50 things software teams should not do.pptx
 
What is the right "unit" in unit testing and why it is not a class?
What is the right "unit" in unit testing and why it is not a class?What is the right "unit" in unit testing and why it is not a class?
What is the right "unit" in unit testing and why it is not a class?
 
A lab around the principles and practices for writing maintainable code
A lab around the principles and practices for writing maintainable codeA lab around the principles and practices for writing maintainable code
A lab around the principles and practices for writing maintainable code
 
How to Practice TDD Without Shooting Yourself in the Foot
How to Practice TDD Without Shooting Yourself in the FootHow to Practice TDD Without Shooting Yourself in the Foot
How to Practice TDD Without Shooting Yourself in the Foot
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservices
 
Event Sourcing from the Trenches (DDD Europe 2020)
Event Sourcing from the Trenches (DDD Europe 2020)Event Sourcing from the Trenches (DDD Europe 2020)
Event Sourcing from the Trenches (DDD Europe 2020)
 
Practical introduction to DDD, CQRS and Event Sourcing
Practical introduction to DDD, CQRS and Event SourcingPractical introduction to DDD, CQRS and Event Sourcing
Practical introduction to DDD, CQRS and Event Sourcing
 
How to practice TDD without shooting yourself in the foot
How to practice TDD without shooting yourself in the footHow to practice TDD without shooting yourself in the foot
How to practice TDD without shooting yourself in the foot
 
Decomposing the Monolith (Riga Dev Days 2019)
Decomposing the Monolith (Riga Dev Days 2019)Decomposing the Monolith (Riga Dev Days 2019)
Decomposing the Monolith (Riga Dev Days 2019)
 
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
 
Lessons learned from two decades of professional software development
Lessons learned from two decades of professional software developmentLessons learned from two decades of professional software development
Lessons learned from two decades of professional software development
 
The Good, The Bad and The Ugly of Event Sourcing
The Good, The Bad and The Ugly of Event Sourcing The Good, The Bad and The Ugly of Event Sourcing
The Good, The Bad and The Ugly of Event Sourcing
 
Event Sourcing from the Trenches (with examples from .NET)
Event Sourcing from the Trenches (with examples from .NET)Event Sourcing from the Trenches (with examples from .NET)
Event Sourcing from the Trenches (with examples from .NET)
 

Último

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

Último (20)

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
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
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
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
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
 
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
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
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
 

The Good, The Bad and the Ugly of Event Sourcing

Notas del editor

  1. Event/Format structure: primitive types only, self-describing