Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
1
440
Event Sourcing in practice
Adam Kosiński
April 12, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
Behind VS Code Extensions for JavaScript / TypeScript Linnting and Formatting
unvalley
5
840
入門 AWS Amplify Gen2 / Introduction to AWS Amplify Gen2
genkiogasawara
1
320
Tailwind CSSを本気でカスタマイズする方法
fsubal
13
5k
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
42
18k
MetricKitで予期せぬ終了を検知する話 / Detect unexpected termination with MetricKit
nekowen
0
180
PostmanでAPIの動作確認が楽になった話
h455h1
0
160
Rubyでたのしむクリエイティブコーディング/Enjoy Creative coding with Ruby
chobishiba
1
170
if constexpr文はテンプレート世界のラムダ式である
faithandbrave
3
620
GitHub Copilotのススメ
marcy731
0
190
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
350
Elm 0.19.0 Changes
bkuhlmann
0
490
Goのエラースタックトレースの歴史と今後
sonatard
6
420
Featured
See All Featured
Building Applications with DynamoDB
mza
88
5.6k
How GitHub (no longer) Works
holman
304
140k
Teambox: Starting and Learning
jrom
128
8.4k
GraphQLの誤解/rethinking-graphql
sonatard
50
9.2k
Become a Pro
speakerdeck
PRO
10
4.5k
Rails Girls Zürich Keynote
gr2m
91
13k
Build The Right Thing And Hit Your Dates
maggiecrowley
23
2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
186
16k
Web Components: a chance to create the future
zenorocha
305
41k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
20
1.6k
Optimising Largest Contentful Paint
csswizardry
7
2.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
990
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