$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Event Sourcing in practice
Search
Adam Kosiński
April 12, 2013
Programming
0
440
Event Sourcing in practice
Adam Kosiński
April 12, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
これならできる!個人開発のすゝめ
tinykitten
PRO
0
110
WebRTC と Rust と8K 60fps
tnoho
2
2k
Rubyで鍛える仕組み化プロヂュース力
muryoimpl
0
130
ID管理機能開発の裏側 高速にSaaS連携を実現したチームのAI活用編
atzzcokek
0
230
非同期処理の迷宮を抜ける: 初学者がつまづく構造的な原因
pd1xx
1
720
WebRTC、 綺麗に見るか滑らかに見るか
sublimer
1
190
dotfiles 式年遷宮 令和最新版
masawada
1
780
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
320
マスタデータ問題、マイクロサービスでどう解くか
kts
0
100
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
410
UIデザインに役立つ 2025年の最新CSS / The Latest CSS for UI Design 2025
clockmaker
18
7.5k
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
390
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
2.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
Making Projects Easy
brettharned
120
6.5k
A Tale of Four Properties
chriscoyier
162
23k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
Agile that works and the tools we love
rasmusluckow
331
21k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Optimizing for Happiness
mojombo
379
70k
The Pragmatic Product Professional
lauravandoore
37
7.1k
Transcript
History Defines Us... Event Sourcing in practice Adam Kosiński, 4Developers
2013
About what is Event Sourcing? Imagine a bank account: Transaction
Amount Balance after transaction Payment Deposit + $3000 $3000 Bill Payments - $1800 $1200 CC Charge - $900 $300 Speed Fine - $300 $0
Save state approach $0 WTF!? Why no money? Event sourcing
Payment Deposit + $3000 Bill Payments - $1800 CC Charge - $900 Speed Fine - $300 $0 Hmm… need cheaper room Retrieving our data:
Seriously, what is ES? Entity (State 0) Entity (State 1)
Domain Event #1
Entity (State 1) Entity (State n) Domain Event #1 Domain
Event #2 Domain Event #n ...
Domain Event #1 ... Domain Event #2 Domain Event #3
Domain Event #4 Domain Event #5 Domain Event #6 Entity (Version 6) We only need events Persisted!
What is Domain Event • Something important • Something foreseen
in domain model • Something happened in the past
Sample Domain: Room Access Control AC Software Hardware Controlers Access
Control Zone Lock Valid Permission None or invalid Permission
Access Control Model
Demo #0 Initial, save state model
Demo #1 What We need for Event Sourcing: • Domain
Events • Event Store • Event handling methods
What can be used as event store: • SQL Relational
DB (slight overkill) • NoSql (ie. RavenDB) • EventStore by Greg Young • Even simple file storage :)
Event Sourcing pros: • No ambiguity between events and data
model • Complete historical data • No DB maintenance when modyfying • Very fast data update
Event Sourcing Limitations
Performance when events grow • Can be troublesome to replay
incerasing number of events every time • Solution: Serialized, captured state of entity - Snapshot
Snapshot Event #1 Snapshot (Version3) Entity (Version 6) Event #2
Event #3 Event #4 Event #5 Event #6 Event #4 Event #5 Event #6
Demo #2 • Creating and restoring snapshots • Snapshot store
Yet another issue - Queries • How should we filter
queries? • Almost always a good idea: CQRS select * from eventStore.Entities where … (? ? ?)
What's with Command-Query Responsibility Segregation ? User UI DB Query
(non-domain views) Domain Logic Read Side view-only data Lift up domain entities Update domain Entities Command (non-domain parameters)
Why CQRS helps ES User UI Read Store Query (non-domain
views) Domain Logic Read Side view-only data Add Events Command (non-domain parameters) Event Store Synchronization
Demo #3 • How does Read Store look like •
Synchronization – Read Side Update
ES – to do or not to do • Yes
when: – Event Driven Architecture – History data need – Concurency – Scalable, modifiable systems • Maybe no when: – Simple CRUD apps – No events needed – Initial cost too high – Legacy software
What next: • Greg Young blog, Event Store website: –
http://geteventstore.com/blog/ • Udi Dahan – http://www.udidahan.com/ • Project CQRS Journey – http://cqrsjourney.github.io/ • Szymon Pobiega – http://simon-says-architecture.com/
Thanks for watching! meet me at: https://twitter.com/a_kosinski