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
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
1k
datadog dash 2025 LLM observability for reliability and stability
ivry_presentationmaterials
0
110
PostgreSQLのRow Level SecurityをPHPのORMで扱う Eloquent vs Doctrine #phpcon #track2
77web
2
290
[初登壇@jAZUG]アプリ開発者が気になるGoogleCloud/Azure+wasm/wasi
asaringo
0
130
Elixir で IoT 開発、 Nerves なら簡単にできる!?
pojiro
1
150
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
130
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
250
レガシーシステムの機能調査・開発におけるAI利活用
takuya_ohtonari
0
610
A2A プロトコルを試してみる
azukiazusa1
2
1.1k
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
420
童醫院敏捷轉型的實踐經驗
cclai999
0
180
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Agile that works and the tools we love
rasmusluckow
329
21k
Designing for humans not robots
tammielis
253
25k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
GitHub's CSS Performance
jonrohan
1031
460k
Designing Experiences People Love
moore
142
24k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
490
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
60k
Done Done
chrislema
184
16k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
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