Synchronizing The Commands and Queries Databases Slides
Synchronizing The Commands and Queries Databases Slides
Queries Databases
Vladimir Khorikov
@vkhorikov www.enterprisecraftsmanship.com
Agenda
Denormalized
Need a projection
State-driven Projections
Projections
Event-driven State-driven
Sync Async
State-driven Projections
State-driven projections
Flags in data tables
Student
aggregate
Course
IsSyncRequired / IsDirty
State-driven Projections
Commands Queries
Raise IsSyncRequired
Sync
Reset IsSyncRequired
State-driven Projections
Synchronization
IsSyncRequired
State-driven
projection
Straightforward
Easy to use
Database triggers
IsSyncRequired
Monitor all changes
Need to implement
a soft deletion
State-driven Projections
IsSyncRequired = true;
}
}
http://bit.ly/ef-vs-nh
State-driven Projections
Projections
Event-driven State-driven
Sync Async
Synchronous State-driven Projections
Sync Async
Runs Runs
synchronously asynchronously
Synchronous version
Synchronous projections
don't scale
Synchronous State-driven Projections
Synchronous projections
Sync Async
Event-driven projections
Domain events drive the changes
Synchronization
IsSyncRequired
Event-driven Projections
Event-driven projections
Domain events drive the changes
State
Don’t store
domain events
Impossible to derive
events from state
Uniqueness constraints
Display helpful
messages and set
proper expectations
Eventual Consistency
“Student registration
is submitted”
Two-way
communication
Eventual Consistency
http://bit.ly/starbucks-cons
Eventual consistency is
problematic when the cost of
making a decision based on
the stale data is high.
Eventual Consistency
Introduce versioning
Eventual Consistency
Update Alice
Commands Queries
UI
Check
current ver.
Commands Queries
Update Alice,
current ver.: 1 Alice v1
UI
Partition
Availability
tolerance
Writes Reads
Give up full
Full consistency
consistency
Give up partition
Partitionability
tolerance
Event-driven projection
- Using domain events to build the queries
database
Without Event Sourcing: use state-driven
projections