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 (laracon online)
Search
Freek Van der Herten
March 06, 2019
Programming
1
410
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
Uncharted packages (Laravel Live Denmark)
freekmurze
0
180
I shall define this only once
freekmurze
0
380
An Introduction to Snapshot testing
freekmurze
0
460
Event Sourcing In Laravel
freekmurze
0
230
Building a realtime dashboard with Laravel Livewire (PHPKonf)
freekmurze
0
770
A tour behind the scenes of Oh Dear (PHP Benelux)
freekmurze
2
820
A practical look at multitenancy in Laravel
freekmurze
1
330
A practical look at multitenancy in Laravel (Laracon US)
freekmurze
0
700
Highlights Flare codebase (Laracon online)
freekmurze
0
460
Other Decks in Programming
See All in Programming
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
200
ファインディLT_ポケモン対戦の定量的分析
fufufukakaka
0
930
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
5
1.1k
Generating OpenAPI schema from serializers throughout the Rails stack - Kyobashi.rb #5
envek
1
390
複数のAWSアカウントから横断で 利用する Lambda Authorizer の作り方
tc3jp
0
120
生成AIで加速するテスト実装 - ロリポップ for Gamersの事例と 生成AIエディタの活用
kinosuke01
0
130
Better Code Design in PHP
afilina
0
170
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
55
19k
読まないコードリーディング術
hisaju
0
100
GoとPHPのインターフェイスの違い
shimabox
2
210
1年目の私に伝えたい!テストコードを怖がらなくなるためのヒント/Tips for not being afraid of test code
push_gawa
1
620
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
1.1k
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
427
65k
Building a Scalable Design System with Sketch
lauravandoore
461
33k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
A Tale of Four Properties
chriscoyier
158
23k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The World Runs on Bad Software
bkeepers
PRO
67
11k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
100
18k
Rails Girls Zürich Keynote
gr2m
94
13k
The Language of Interfaces
destraynor
156
24k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
10
1.3k
Testing 201, or: Great Expectations
jmmastey
42
7.2k
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