Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
CQRS & Event Sourcing in OLX
Łukasz Szymański
May 16, 2016
Programming
7
1.6k
CQRS & Event Sourcing in OLX
Łukasz Szymański
May 16, 2016
Tweet
Share
More Decks by Łukasz Szymański
See All by Łukasz Szymański
Chain reaction of scaling up
szymanskilukasz
1
88
GraphQL Without Hype
szymanskilukasz
0
250
PHP's Not Dead - PHP7 In Practice
szymanskilukasz
10
41k
Text Retrieval
szymanskilukasz
0
150
OLX pod maską [PL]
szymanskilukasz
2
610
Other Decks in Programming
See All in Programming
花き業界のサプライチェーンを繋げるプロダクト開発の進め方
userlike1
0
190
Circuit⚡
monaapk
0
200
フロントエンドで 良いコードを書くために
t_keshi
3
1.7k
OIDC仕様に準拠した Makuake ID連携基盤構築の裏側
ymtdzzz
0
600
Form実装基本を学び直してみた
hyugatsukui
0
250
42tokyo-born2beroot-review
love42
0
120
Amebaブログの会員画面システム刷新の道程
ryotasugawara
1
250
10年以上続くプロダクトの フロントエンド刷新プロジェクトのふりかえり
yotahada3
2
360
CDKでValidationする本当の方法 / cdk-validation
gotok365
1
230
社会人 20 年目エンジニア、発信で技術学びなおしてる話
e99h2121
1
150
データドリブンな組織の不正検知
fkubota
0
310
ポケモンで学ぶiOS 16弾丸ツアー 🚅
giginet
PRO
1
620
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
2
410
Web Components: a chance to create the future
zenorocha
304
40k
Why Our Code Smells
bkeepers
PRO
326
55k
A Modern Web Designer's Workflow
chriscoyier
689
180k
The Language of Interfaces
destraynor
149
21k
Building Your Own Lightsaber
phodgson
96
4.9k
Pencils Down: Stop Designing & Start Developing
hursman
114
10k
The Pragmatic Product Professional
lauravandoore
21
3.5k
No one is an island. Learnings from fostering a developers community.
thoeni
12
1.5k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
109
16k
10 Git Anti Patterns You Should be Aware of
lemiorhan
643
54k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
7
590
Transcript
CQRS Event Sourcing in OLX
CQRS
you can use a different model to update information than
the model you use to read information http://martinfowler.com/bliki/CQRS.html „
Command Query Responsibility Segregation
Command Query Responsibility Segregation
new AddCredits($userId, $amount); Command
Command new AddCredits($userId, $amount); Query new GetCredits($userId);
Event Sourcing
http://www.martinfowler.com/eaaDev/EventSourcing.html „ ensures that all changes to application state are
stored as a sequence of events
Not just can we query these events, we can also
use the event log to reconstruct past states http://www.martinfowler.com/eaaDev/EventSourcing.html „
Commad Event Model Event Storage Event Bus Command Handler Listeners
Read Storage Read Model Query
Commad Event Model Event Storage Event Bus Command Handler Listeners
Read Storage Read Model Query Critical section - use transaction
Commad Event Model Event Storage Event Bus Command Handler Listeners
Read Storage Read Model Query Critical section - use transaction Treat like temporary cache
That’s all
E-Wallet Credits; Invoices; Refunds
Wallet Credits Bonus Credits Refund Credits EXPIRE: X DAYS EXPIRE:
X DAYS EXPIRE: X DAYS INVOICE: YES/NO INVOICE: YES/NO INVOICE: YES/NO
Wallet Credits Bonus Credits Refund Credits EXPIRE: NEVER EXPIRE: 90
DAYS EXPIRE: 90 DAYS INVOICE: YES INVOICE: NO INVOICE: YES
Opis walleta w Polsce specyfikacja komenty enventy Commands
Add Wallet Credits Add Bonus Credits Add Refund Credits
Sub Wallet Credits Sub Bonus Credits Sub Refund Credits SubCredits
Opis walleta w Polsce specyfikacja komenty enventy Events
Wallet CreditsWasAdded Bonus CreditsWasAdded Refund CreditsWasAdded
Wallet CreditsWasSubtracted Bonus CreditsWasSubtracted Refund CreditsWasSubtracted
specyfikacja komenty enventy 7 commands 6 events
specyfikacja komenty enventy What about other stuff?
Commad Event Model Event Storage Event Bus Command Handler Listeners
Read Storage Read Model Query ?
Broadway komponenty Broadway https://github.com/qandidate-labs/broadway
Auditing log whether commands were successful or not
CommandHandling Provides the interface and a CommandHandler base class for
handling events
Domain domain abstractions of the Broadway framework including the aggregate
root, domain messages and domain events.
EventDispatcher The component provides an event dispatcher interface and a
simple implementation
EventHandling provides interfaces for an event bus and event listeners,
but also an implementation of a simple event bus and an event bus that will record published events
EventSourcing Provides base classes for event sourced aggregate roots and
entities, an event sourced repository implementation and testing helpers.
EventStore implementation based on doctrine/dbal to store events in a
relational database and an in-memory implementation that is useful for using in tests
ReadModel provides storage for your read models, a projector implementation
to create read models from event streams and testing helpers.
Repository Component providing an abstraction of the storage of aggregates.
Serializers provides a simple serializer interface and a serializer implementation
based on "handwritten" serializers
Commad Event Model Event Storage Event Bus Command Handler Listeners
Read Storage Read Model Query Broadway
Adding Wallet Credits
None
None
Credits Query
None
None
Lessons Learned
Small Steps Don’t try to CQRS/EventSource everything
Keep It Simple Avoid names like BonusCreditsWasSubtractedBecauseAdminHitSubtractBonusCr editsInAdminPanelEvent
Event Storming is not that easy as it sounds
It’s not RDBM Remember about analysts
Code changes Events handle changes to data, what about changes
to code?
Synchronize Remember about synchronizing read layer - especially after fail
Commad Event Model Event Storage Event Bus Command Handler Listeners
Read Storage Read Model Query Critical section - use transaction
Performance is not an issue - for this case
Timezone Agnostic Implement your own EventStore if you want timezone
aware records
Our Team
Paid Features
Next challenge Open source Paid Features libraries with Hexagonal Architecture
in mind
Team Lead PHP Dev Junior PHP Dev You ?
Łukasz Szymański Development Team Lead at @szymanskilukasz http://szymanskilukasz.github.io/ https://www.linkedin.com/in/szymanskilukasz https://twitter.com/szymanskilukasz