Post on 14-Apr-2017
Persistence that tells the truthRyan Platteryan@burnbush.net
Your model lies
Your model lies
“Customer 123 ordered the inexpensive product”
The truth is what actually happens
The truth is what actually happens
“Customer 123 ordered the expensive product and the cheaper one, then removed the expensive one after checking shipping”
So why not persist the whole truth?
So why not persist the whole truth?
Added Product
Customer 123
Product 1
Computed Shipping
Added Product
Customer 123
Product 2
Removed Product
Customer 123
Product 2
Past history is immutable
Ask your accountant whether it’s OK to change historical records
Append-only writes scalehttps://flic.kr/p/obgzhM
This is how many databases work internally anyway
Working from the whole truth supports future features
How to create event-sourced software
Command-event separation
Imperative vs. past tense
Command is an attempt or request
Event is a change that definitely registered
Persisting events in a database
Minimal implementation
Events
Aggregate_id (GUID)Data (blob or JSON)Version (integer)
Aggregates, or Event ProviderAggregate_id (GUID)Type (string)Version (integer)
Persisting events in a database
Events
Aggregate_id (GUID)Data (blob or JSON)Version (integer)TimestampIP addressPermission level
Aggregates, or Event ProviderAggregate_id (GUID)Type (string)Version (integer)
Read model: go nuts
Order openedItem addedItem added
Item removedOrder placed
Order approvedOrder shipped
Order delivered
Objects in memory
Mutable DB model
Graph DB
Work queues