Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Event sourcing (laracon online)
Freek Van der Herten
March 06, 2019
Programming
1
380
Event sourcing (laracon online)
Freek Van der Herten
March 06, 2019
Tweet
Share
More Decks by Freek Van der Herten
See All by Freek Van der Herten
An Introduction to Snapshot testing
freekmurze
0
220
Event Sourcing In Laravel
freekmurze
0
140
Building a realtime dashboard with Laravel Livewire (PHPKonf)
freekmurze
0
470
A tour behind the scenes of Oh Dear (PHP Benelux)
freekmurze
1
500
A practical look at multitenancy in Laravel
freekmurze
1
240
A practical look at multitenancy in Laravel (Laracon US)
freekmurze
0
470
Highlights Flare codebase (Laracon online)
freekmurze
0
190
Introducing Mailcoach
freekmurze
1
390
Highlights from the Flare codebase (Full Stack Ghent)
freekmurze
0
420
Other Decks in Programming
See All in Programming
Edge Side Frontend という新領域
mizchi
22
10k
SRE NEXT 2022に学ぶこれからのSREキャリア
fukubaka0825
2
390
Dagger, la CI, autrement
guikingone
1
100
How to start contributing to Kubernetes Projects
ydfu
0
140
SwiftUIで「意図」を伝える / swiftui_intention
uhooi
2
150
アジャイルで始める データ分析基盤構築
nagano
1
870
閱讀原始碼 - 再戰十年的 jQuery
eddie
1
290
Cloudflare WorkersでGoのHTTPサーバーを動かすライブラリを作った話
syumai
0
150
Pythonによる開発をアップデートするライブラリの紹介
daikikatsuragawa
1
600
ESM移行は無理だけどおれもSindreのライブラリが使いたい!
sosukesuzuki
2
540
OSS貢献を気軽にしたい Let's Go Talk #1
yuyaabo
2
230
Amazon SageMakerでImagenを動かして猫画像生成してみた
hotoke_neko
0
110
Featured
See All Featured
Building Applications with DynamoDB
mza
84
4.8k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
316
19k
Designing for humans not robots
tammielis
241
24k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
212
20k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
39
13k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
349
27k
A Tale of Four Properties
chriscoyier
149
21k
Building Adaptive Systems
keathley
25
1.2k
Learning to Love Humans: Emotional Interface Design
aarron
261
37k
Documentation Writing (for coders)
carmenintech
48
2.6k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
6
560
The Language of Interfaces
destraynor
148
21k
Transcript
Getting started with event sourcing in Laravel
About me Freek Van der Herten Partner & developer at
Spatie @freekmurze https://murze.be https://ohdear.app
Spatie Since 2003 Websites, applications and webshops Team 9 awesome
human beings Specialisation Laravel, front-end development
Open Source Software
We create a lot of it ± 200 packages on
Packagist ± 2,000,000 downloads a month ± 25,000,000 total downloads All Postcardware!
Highlights Popular laravel-backup laravel-medialibrary laravel-permission New laravel-query-builder laravel-blade-x
https://spatie.be/open-source
https://spatie.be/open-source/postcards
Let's talk about event sourcing
Talk overview Projecting events in short Laravel Event Projector demo
Eventsauce demo
Event Sourcing in short
Traditional application Write data in database An update means overwriting
the old data The old data cannot be accessed anymore
APPLICATION DATABASE TABLE value X
APPLICATION DATABASE TABLE value X value Y
Event Sourced Application The application will fire off events Events
will get written in a dedicated store Events are passed to consumers that create projections Aggregate, Aggregate Root...
APP EVENTS Event Event 1
APP EVENTS Event Event 1 Event 2
APP EVENTS Event Event 1 Event 2 Event 3
APP CONSUMER EVENTS PROJECTION Event Event 1 Event 2 Event
3
APP CONSUMER CONSUMER 2 EVENTS PROJECTION Event Event 1 Event
2 Event 3 ANOTHER PROJECTION
APP CONSUMER CONSUMER 2 EVENTS PROJECTION Event Event 1 Event
2 Event 3 ANOTHER PROJECTION
APP CONSUMER CONSUMER 2 EVENTS PROJECTION Event Event 1 Event
2 Event 3 Event 4 ANOTHER PROJECTION
Event Sourced Application Auditing requirements Extra reports needed Recording the
unhappy path There is some setup required
Laravel Event Projector
Laravel Event Projector Package made by Spatie It's not full
event sourcing, it focuses on projections Beautifully integrated into Laravel Easy to get started with
https://docs.spatie.be/laravel-event-projector
Demo
Eventsauce
Eventsauce Package made by Frank De Jonge Focuses on aggregates
Framework agnostic Separate Laravel bindings package available Very powerful, adds complexity
https://eventsauce.io/docs/
APP Subtract $1000
AGGREGATE ROOT REPOSITORY UUID PAYLOAD TIME APP Subtract $1000
AGGREGATE ROOT REPOSITORY UUID PAYLOAD TIME APP Subtract $1000 RETRIEVE
Subtract $1000 AGGREGATE ROOT (empty)
AGGREGATE ROOT REPOSITORY UUID PAYLOAD TIME APP Subtract $1000 RETRIEVE
PERSIST Subtract $1000 AGGREGATE ROOT ACCOUNTS CONSUMER -$1000 ABC-123 Subtract 1000 11:12 AM (empty)
AGGREGATE ROOT REPOSITORY UUID PAYLOAD TIME APP RETRIEVE PERSIST Subtract
$750 AGGREGATE ROOT ACCOUNTS -$1000 CONSUMER ABC-123 Subtract 1000 11:12 AM Subtract $750 Subtract $1000
AGGREGATE ROOT REPOSITORY UUID PAYLOAD TIME APP RETRIEVE PERSIST Subtract
$750 AGGREGATE ROOT ACCOUNTS -$1750 CONSUMER ABC-123 Subtract 1000 11:12 AM Subtract $750 Subtract $1000 ABC-124 Subtract 750 01:17 PM
AGGREGATE ROOT REPOSITORY UUID PAYLOAD TIME APP RETRIEVE PERSIST AGGREGATE
ROOT ACCOUNTS -$1750 CONSUMER ABC-123 Subtract 1000 11:12 AM ABC-124 Subtract 750 01:17 PM Subtract $1250 Subtract $1000 Subtract $750 Subtract $1250 Propose loan
AGGREGATE ROOT REPOSITORY ABC-123 Subtract 1000 11:12 AM ABC-124 Subtract
750 01:17 PM ABC-125 Subtract 1250, Propose loan 05:51 PM UUID PAYLOAD TIME ACCOUNTS APP CONSUMER CONSUMER 2 PROPOSED LOANS Subtract $1250 -$3000 RETRIEVE PERSIST Subtract $1000 Subtract $750 Subtract $1250 Propose loan AGGREGATE ROOT
Demo
In closing
Summary Laravel Event Projector Easy to use package to get
started with projections Hooks into Laravel's native events Replay capabilities No aggregates
Summary EventSauce Framework agnostic Support for aggregates, process modelling No
replay capabilities out of the box https://github.com/spatie/laravel-eventsauce
Writes are harder, reads are easier
Event sourcing makes the easy things harder… …and the harder
things easier — Frank De Jonge
Larabank https://github.com/spatie/larabank-traditional https://github.com/spatie/larabank-event-projector https://github.com/spatie/larabank-eventsauce
Resources https://kickstarter.engineering/event-sourcing-made-simple-4a2625113224 https://github.com/spatie/laravel-event-projector https://github.com/eventsaucephp/eventsauce https://github.com/prooph
Thank you! https://speakerdeck.com/freekmurze/event-sourcing-laracon-online https://spatie.be/open-source https://murze.be https://ohdear.app https://fullstackeurope.com