What if we stored events instead of state?
-
Upload
jef-claes -
Category
Technology
-
view
4.038 -
download
0
description
Transcript of What if we stored events instead of state?
![Page 1: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/1.jpg)
WHAT IF WE STORED EVENTS INSTEAD OF STATE?
![Page 3: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/3.jpg)
![Page 4: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/4.jpg)
![Page 5: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/5.jpg)
SCENARIO’S• The user can put up a card. • The user can move the card to the doing section. • …
![Page 6: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/6.jpg)
COMMANDS• Put up a card. • Move card to doing section. • …
![Page 7: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/7.jpg)
![Page 8: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/8.jpg)
![Page 9: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/9.jpg)
![Page 10: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/10.jpg)
![Page 11: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/11.jpg)
State + Behavior
![Page 12: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/12.jpg)
![Page 13: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/13.jpg)
![Page 14: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/14.jpg)
![Page 15: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/15.jpg)
Traditional systems store current state.
![Page 16: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/16.jpg)
We have no idea what has happened in our system.
![Page 17: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/17.jpg)
Audit logs anyone?
![Page 18: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/18.jpg)
State Audit log
![Page 19: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/19.jpg)
![Page 20: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/20.jpg)
Deposit 500 € 500 €
Deposit 200 € 700 €
Withdraw 300 € 400 €
Deposit 1000 € 1400 €
Withdraw 400 € 1000 €
Withdraw 200 € 800 €
… …
![Page 21: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/21.jpg)
Deposit 500 € Deposited 500 € 500 €
Deposit 200 € Deposited 200 € 700 €
Withdraw 300 € Withdrawn 300 € 400 €
Deposit 300 € Deposited 1000 € 1400 €
Withdraw 400 € Withdrawn 400 € 1000 €
Withdraw 200 € Withdrawn 200 € 800 €
… …
![Page 22: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/22.jpg)
Command - Event - State
![Page 23: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/23.jpg)
Something that happened - past tense.
![Page 24: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/24.jpg)
Store the sequence of events that led up to the current state, instead of the current state.
![Page 25: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/25.jpg)
Command State
Put up a new card“Reset Password”
Card“Reset Password”
“Todo”
Move card to doingCard
“Reset Password”“Doing”
… …
![Page 26: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/26.jpg)
Command Event State
Put up a new card“Reset Password”
Card put up“Reset Password”
“Todo”
Card“Reset Password”
“Todo”
Move card to doing Moved card to section “Doing”
Card“Reset Password”
“Doing”
… … …
![Page 27: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/27.jpg)
![Page 28: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/28.jpg)
![Page 29: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/29.jpg)
![Page 30: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/30.jpg)
![Page 31: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/31.jpg)
![Page 32: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/32.jpg)
![Page 33: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/33.jpg)
![Page 34: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/34.jpg)
![Page 35: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/35.jpg)
![Page 36: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/36.jpg)
![Page 37: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/37.jpg)
![Page 38: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/38.jpg)
![Page 39: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/39.jpg)
![Page 40: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/40.jpg)
![Page 41: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/41.jpg)
![Page 43: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/43.jpg)
![Page 44: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/44.jpg)
![Page 45: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/45.jpg)
![Page 46: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/46.jpg)
An event store
![Page 47: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/47.jpg)
![Page 48: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/48.jpg)
EventId StreamId Type Payload MetaData
1 card/1 CardPutUp { … } { … }
2 card/1 MovedCard ToSection { … } { … }
3 card/1 MovedCardToSection { … } { … }
… … … …
![Page 49: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/49.jpg)
![Page 50: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/50.jpg)
You can’t undo the past.
![Page 51: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/51.jpg)
Append-only.
![Page 52: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/52.jpg)
Forever cacheable.
![Page 53: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/53.jpg)
What about queries?
![Page 54: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/54.jpg)
Model
Writes Reads
![Page 55: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/55.jpg)
Write model
Writes
![Page 56: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/56.jpg)
Write model
Writes
Read model
Reads
![Page 57: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/57.jpg)
Write model
Writes
Read model
Reads
Events
![Page 58: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/58.jpg)
![Page 59: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/59.jpg)
We can build a read model from events committed to the write model.
![Page 60: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/60.jpg)
Events Dispatcher Projection Read model
![Page 61: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/61.jpg)
Events Dispatcher Projection Read model
Projection Read model
![Page 62: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/62.jpg)
Events Dispatcher Projection Read model
Projection Read model
Projection Read model
![Page 63: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/63.jpg)
We can build read models from events committed to the write model.
![Page 64: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/64.jpg)
More than one way to look at your data.
![Page 65: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/65.jpg)
BehaviorSearch
ReportingViews
…
![Page 66: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/66.jpg)
ComplexSlow
Fragile
![Page 67: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/67.jpg)
![Page 68: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/68.jpg)
![Page 69: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/69.jpg)
![Page 70: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/70.jpg)
![Page 71: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/71.jpg)
![Page 72: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/72.jpg)
![Page 73: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/73.jpg)
![Page 74: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/74.jpg)
![Page 75: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/75.jpg)
![Page 76: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/76.jpg)
![Page 77: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/77.jpg)
![Page 78: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/78.jpg)
![Page 79: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/79.jpg)
What if I mess up my read models?What if I need to update my read models?
What if I need a new read model?
![Page 80: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/80.jpg)
Temporal queries.
![Page 81: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/81.jpg)
Tell me which day most work gets done.
![Page 82: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/82.jpg)
Monday Tuesday Wednesday …
CardMovedCardMovedCardMovedCardMovedCardMoved
CardMovedCardMoved
CardMovedCardMovedCardMoved
![Page 83: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/83.jpg)
![Page 84: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/84.jpg)
Not just for read models and queries.
![Page 85: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/85.jpg)
![Page 86: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/86.jpg)
Events Dispatcher Projection Read model
Projection Read model
Projection Read model
Integration
![Page 87: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/87.jpg)
Pub-Sub
![Page 88: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/88.jpg)
Events Dispatcher
Projection
Projection
Projection
Transaction
![Page 89: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/89.jpg)
Events Dispatcher
Projection
Projection
Projection
![Page 90: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/90.jpg)
Events
Projection
Projection
Projection
![Page 91: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/91.jpg)
Events Dispatcher (Queue)
Projection (Queue)
Projection (Queue)
Projection (Queue)
![Page 92: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/92.jpg)
When?
![Page 93: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/93.jpg)
When you can’t afford to lose data.
![Page 94: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/94.jpg)
Business Intelligence Auditing
Reproducing issues Challenging/changing business models
![Page 95: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/95.jpg)
Decouple reads from writes
![Page 96: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/96.jpg)
Conceptual puritySimplicity (no monolith)
Polyglot persistancePerformance
High availability
![Page 97: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/97.jpg)
Integration with other systemsTesting
…
![Page 98: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/98.jpg)
No silver bullet
![Page 99: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/99.jpg)
In conclusion
![Page 100: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/100.jpg)
Event sourcing, for when the what and the when are important.
![Page 101: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/101.jpg)
… but really, it’s a lot more than that.
![Page 102: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/102.jpg)
Experiment!
![Page 103: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/103.jpg)
http://neventstore.org/http://geteventstore.com/
![Page 104: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/104.jpg)
https://groups.google.com/forum/#!forum/dddcqrs
![Page 105: What if we stored events instead of state?](https://reader034.fdocuments.us/reader034/viewer/2022052600/557d1121d8b42a3d3d8b45d2/html5/thumbnails/105.jpg)
@gregyoung
@abdullin
@randompunter
@jonathan_oliver
@jen20
@yreynhout @mathiasverraes
@thinkb4coding@eulerfx
@ziobrando
@tojans