In 2009, I first learned about Event Sourcing and Command Query Responsibility Seggregation (CQRS) at a training Greg Young gave in Utrecht, The Netherlands. I remembered to be awed by the scalability and architectural simplicity those styles provided. However, I also remembered the technical complexity that comes with it. In 2012, I was in charge of transitioning a CQRS-based system to Event Sourcing. I knew it would be non-trivial, but boy was I in for a surprise.
So over the last four years I've experienced first-hand how a large group of developers had to deal with the transition. It's a brilliant solution for high-performance or complex business systems, but you need to be aware that this also introduces challenges most people don't tell you about. In this talk, I'd like to share you some of the most powerful benefits of ES, but also show you the flipside of the coin and cover some of the smaller and bigger challenges you'll run into it. Again, I love it and would apply it again without any doubt, but I really want you to understand the trade-offs before you jump on the Event Sourcing train.
6. 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
8. Dennis (v4)
Persisted State Changes
Dennis (v3)
Role Granted
PasswordChangedEvent
Dennis (v4)
Dennis (v3)
User Created
Role Granted
Phone Number Added
Password Changed
Dennis (v5)
Role Revoked
Dennis (v6)
Role Granted
Time
Dennis (v7)
Password Changed
Dennis Doomen | @ddoomen | The Continuous Improver
20. Driven by invariants, not
composition
Only consistent within
aggregate
Small aggregates
Reference by identity
21.
22. 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
23. 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
24. 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
25. 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
29. • Column constraints (e.g. data truncation)
• Changes in data invariants (null vs non-
null in event versions)
• Unexpected projection dependencies
• Partial replays.
30. • Causing duplicate child records
• Causing large event streams
• Incorrect caching strategy (e.g. on
lookups)
• Identity case-sensitivity
• Incomplete SQL-backed event store
reads.
31. • Side by side rebuilding
• Functional archivability and archiving
• Projection tracking and ETAs
• Prioritization
• Partitioning.
32. • After bugs, schema changes, etc
• Manual or automatic (e.g. hashes)
33.
34. • Liquid Projections
– Designed as a library
– Promotes fully autonomous
projections
– Local tracking
– ETA calculations
• NEventStore
• GetEventStore
• Apache Kafka?
35.
36. • 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