SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
EVENT SOURCING (W PHP)
PIOTR KACAŁA
EVENT SOURCING
ZBUDUJMY SOBIE KOSZYK!
POBIERANIE ZAWARTOŚCI KOSZYKA
mysql> select * from cart_products;
+---------+------------+
| cart_id | product_id |
+---------+------------+
| 1 | 124 |
| 1 | 89 |
+---------+------------+
DODANIE PRODUKTU DO KOSZYKA
POST /CARTS/{CID}/PRODUCTS
INSERT INTO CART_PRODUCTS (…)
USUNIĘCIE PRODUKTU Z KOSZYKA
DELETE /CARTS/{CID}/PRODUCTS/{PID}
DELETE FROM CART_PRODUCTS (…)
DOBRA, MAMY KOSZYK.
PRZYPOMNIJMY
mysql> select * from cart_products;
+---------+------------+
| cart_id | product_id |
+---------+------------+
| 1 | 124 |
| 1 | 89 |
+---------+------------+
POROZMAWIAJMY O PIENIĄDZACH
A CO JEŚLI?
select * from salda_bankowe;
+---------------------+----------------+
| rachunek | ile_pieniazkow |
+---------------------+----------------+
| 4444 3333 2222 1111 | 1000 |
+---------------------+----------------+
PRZECIEŻ PISZE, ŻE 1000.
TRUDNO SIĘ KŁÓCIĆ
+---------------------+----------------+
| rachunek | ile_pieniazkow |
+---------------------+----------------+
| 4444 3333 2222 1111 | 1000 |
+---------------------+----------------+
CZYM JEST EVENT SOURCING?
EVENT STORE
Cart #1 Was
Created
Product #B
Added 

To The Cart
Product #A
Removed 

From The Cart
Product #A
Added 

To The Cart
Cart #1 Was
Checked Out
EVENT STORE
Cart #1 Was
Created
Product #B
Added 

To The Cart
Product #A
Removed 

From The Cart
Product #A
Added 

To The Cart
Cart #1 Was
Checked Out
JAK UPRAWIAĆ EVENT SOURCING (W PHP)?
TRADYCYJNY KOSZYK
class Cart

{

private $id;

private $products = [];



public function add($productId)

{
// changing the state of the cart
$this->products[] = $productId;

}

}
KOSZYK PRODUKUJĄCY EVENTY
class Cart

{

private $id;

private $products = [];

private $raisedEvents = [];



public function add($productId)

{
// changing the state of the cart

$this->products[] = $productId;



// let's raise an event

$this->raisedEvents[] = new ProductAddedToCart($this->id, $productId);

}

}
CartRepository::add(cart)
EVENT STORE
Cart Was
Created
Product #2
Added 

To The Cart
Product #1
Added 

To The Cart
Cart Was
Checked Out
Product #1
Removed 

From The Cart
EVENT STORE
mysql> select * from event_store;
+----+--------------+-------------------------------------------+
| id | aggregate_id | event |
+----+--------------+-------------------------------------------+
| 1 | 1 | CartWasCreated({"cartId":"1"}) |
| 2 | 1 | ProductAddedToCart({"productId":"A"}) |
| 3 | 1 | ProductRemovedFromCart({"productId":"A"}) |
| 4 | 1 | ProductAddedToCart({"productId":"B"}) |
+----+--------------+-------------------------------------------+
ODTWARZANIE AGREGATU KOSZYKA W REPOZYTORIUM
class EventSourcedCartRepository implements CartRepository

{

public function find($aggregateId)

{

$events = $this->eventStore->findEvents($aggregateId);

$cart = new Cart(); // inicjalizacja pustego agregatu



// "nagrywanie" eventów na agregacie cartu

foreach($events as $event) {


// metoda apply() woła odpowiednie metody prywatne

// na podstawie nazwy przekazywanego eventu, np.

// ProductWasAddedToCart => applyProductWasAddedToCart

$cart->apply($event); 

}

}

}
ENCJA
class Cart
{

// this method is called by event store to replay event on the cart
protected function applyProductAddedToCart(ProductAddedToCart $event)

{

$this->products[] = $event->getProductId();

}

}
OBIE METODY
class Cart

{

public function add($productId)

{

if ($this->products > 2) {

throw new CartLimitExceeded();

}



// raise the event

$event = new ProductAddedToCart($this->id, $productId);

$this->raisedEvents[] = $event;



// change the state

$this->applyProductAddedToCart($event);

}



// change the state, this is called by Event Store

public function applyProductAddedToCart(ProductAddedToCart $event)

{

$this->products[] = $event->getProductId();

}

}
CO Z WYDAJNOŚCIĄ?
JAK ROBIĆ ZAPYTANIA?
EVENT STORE
mysql> select * from event_store;
+----+--------------+-------------------------------------------+
| id | aggregate_id | event |
+----+--------------+-------------------------------------------+
| 1 | 1 | CartWasCreated({"cartId":"1"}) |
| 2 | 1 | ProductAddedToCart({"productId":"A"}) |
| 3 | 1 | ProductRemovedFromCart({"productId":"A"}) |
| 4 | 1 | ProductAddedToCart({"productId":"B"}) |
+----+--------------+-------------------------------------------+
CQRS! READ MODEL
MAŁY RECAP
Obiekt 

domeny
Event Store
Listenery
Eventy
TRAFIAJĄ DO
ZAPISYWANE W
PRODUKUJE
PROJEKCJE
class CurrentCartProductsProjector

{

public function applyProductAddedToCart(ProductAddedToCart $event)

{

$this->connection->query('insert into cart_products ...');

}



public function applyProductRemovedFromCart(ProductRemovedFromCart $event)

{

$this->connection->query('delete from cart_products ...');

}

}
POBIERANIE ZAWARTOŚCI KOSZYKA
mysql> select * from cart_products;
+---------+------------+
| cart_id | product_id |
+---------+------------+
| 1 | 124 |
| 1 | 89 |
+---------+------------+
CQRS W PEŁNI SWOJEJ CHWAŁY
Cart::add
Zapis w 

Event Store
Product Was
Added To Cart
Cart State
Projector
SQL
Redis
CO Z ZADANIEM OD PANI MAŁGOSI?
PODSUMOWANIE
PLUSY EVENT SOURCINGU
- HISTORYCZNY STAN APLIKACJI
- DEBUGOWANIE
- PROSTY MODEL ZAPISU
- ODPORNOŚĆ NA KREATYWNOŚĆ BIZNESU
- ŁATWA SKALOWALNOŚĆ
- WSPÓŁGRA Z MIKROSERWISAMI
MINUSY EVENT SOURCINGU
- PRÓG WEJŚCIA (ZMIANA PRZYZWYCZAJEŃ)
- KONIECZNOŚĆ SHARDOWANIA EVENT STORE’U*
- DŁUŻSZY ŁADOWANIE OBIEKTÓW DOMENOWYCH**
- ZWIĘKSZA ZŁOŻONOŚĆ APLIKACJI (VS CRUD)
* NIE DOTYCZY WSZYSTKICH APLIKACJI
** ROZWIĄZANY PRZEZ SNAPSHOTY
/QANDIDATE-LABS/BROADWAY
CIEKAWOSTKA
PYTANIA?
DZIĘKI! d:-)
/WORK

Más contenido relacionado

La actualidad más candente

Software Engineering - chp5- software architecture
Software Engineering - chp5- software architectureSoftware Engineering - chp5- software architecture
Software Engineering - chp5- software architectureLilia Sfaxi
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slidesSmithss25
 
Javascript Arrow function
Javascript Arrow functionJavascript Arrow function
Javascript Arrow functiontanerochris
 
Agile Methodology - Software Engineering
Agile Methodology - Software EngineeringAgile Methodology - Software Engineering
Agile Methodology - Software EngineeringPurvik Rana
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programmingAssaf Gannon
 
Single page application
Single page applicationSingle page application
Single page applicationArthur Fung
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event LoopDesignveloper
 
Uml diagrams
Uml diagramsUml diagrams
Uml diagramsbarney92
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Examplekamal kotecha
 
Asynchronous javascript
 Asynchronous javascript Asynchronous javascript
Asynchronous javascriptEman Mohamed
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsMichael Heron
 
Chapter 2 software development life cycle models
Chapter 2 software development life cycle modelsChapter 2 software development life cycle models
Chapter 2 software development life cycle modelsdespicable me
 

La actualidad más candente (20)

Software Engineering - chp5- software architecture
Software Engineering - chp5- software architectureSoftware Engineering - chp5- software architecture
Software Engineering - chp5- software architecture
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Javascript Arrow function
Javascript Arrow functionJavascript Arrow function
Javascript Arrow function
 
Agile Methodology - Software Engineering
Agile Methodology - Software EngineeringAgile Methodology - Software Engineering
Agile Methodology - Software Engineering
 
Struts
StrutsStruts
Struts
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
 
Single page application
Single page applicationSingle page application
Single page application
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Uml diagrams
Uml diagramsUml diagrams
Uml diagrams
 
Java script
Java scriptJava script
Java script
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Asynchronous javascript
 Asynchronous javascript Asynchronous javascript
Asynchronous javascript
 
E3 chap-08
E3 chap-08E3 chap-08
E3 chap-08
 
Jsf presentation
Jsf presentationJsf presentation
Jsf presentation
 
Visitor pattern
Visitor patternVisitor pattern
Visitor pattern
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design Patterns
 
Chapter 2 software development life cycle models
Chapter 2 software development life cycle modelsChapter 2 software development life cycle models
Chapter 2 software development life cycle models
 

Similar a Event sourcing w PHP (by Piotr Kacała)

Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsŁukasz Chruściel
 
Practical Event Sourcing
Practical Event SourcingPractical Event Sourcing
Practical Event SourcingMathias Verraes
 
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdf12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdffasttracksunglass
 
Why SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScriptWhy SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScriptmartinlippert
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWordCamp Indonesia
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介Jace Ju
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fabio Akita
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingSamuel ROZE
 
Confoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api PlatformConfoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api PlatformMateusz Zalewski
 
[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testing[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testingMateusz Zalewski
 
BDD Revolution - or how we came back from hell
BDD Revolution - or how we came back from hellBDD Revolution - or how we came back from hell
BDD Revolution - or how we came back from hellMateusz Zalewski
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Curscatalyst
CurscatalystCurscatalyst
CurscatalystKar Juan
 
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...Mateusz Zalewski
 
BDD revolution - or how we came back from hell
BDD revolution - or how we came back from hellBDD revolution - or how we came back from hell
BDD revolution - or how we came back from hellMateusz Zalewski
 
When cqrs meets event sourcing
When cqrs meets event sourcingWhen cqrs meets event sourcing
When cqrs meets event sourcingManel Sellés
 
CodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPigCodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPigDusan Zamurovic
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesCiaranMcNulty
 
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...Mateusz Zalewski
 

Similar a Event sourcing w PHP (by Piotr Kacała) (20)

Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Practical Event Sourcing
Practical Event SourcingPractical Event Sourcing
Practical Event Sourcing
 
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdf12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
 
Why SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScriptWhy SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScript
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda Bagus
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
 
Confoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api PlatformConfoo 2023 - Business logic testing with Behat, Twig and Api Platform
Confoo 2023 - Business logic testing with Behat, Twig and Api Platform
 
[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testing[PHPers Summit 2023] Business logic testing
[PHPers Summit 2023] Business logic testing
 
BDD Revolution - or how we came back from hell
BDD Revolution - or how we came back from hellBDD Revolution - or how we came back from hell
BDD Revolution - or how we came back from hell
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
 
BDD revolution - or how we came back from hell
BDD revolution - or how we came back from hellBDD revolution - or how we came back from hell
BDD revolution - or how we came back from hell
 
When cqrs meets event sourcing
When cqrs meets event sourcingWhen cqrs meets event sourcing
When cqrs meets event sourcing
 
CodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPigCodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPig
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
 
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
 

Más de GOG.com dev team

In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019GOG.com dev team
 
Always up to date, testable and maintainable documentation with OpenAPI
Always up to date, testable and maintainable documentation with OpenAPIAlways up to date, testable and maintainable documentation with OpenAPI
Always up to date, testable and maintainable documentation with OpenAPIGOG.com dev team
 
Symfony without the framework
Symfony without the frameworkSymfony without the framework
Symfony without the frameworkGOG.com dev team
 
Versioning challenges in micro services of Gwent
Versioning challenges in micro services of GwentVersioning challenges in micro services of Gwent
Versioning challenges in micro services of GwentGOG.com dev team
 
Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej w grze...
Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej w grze...Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej w grze...
Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej w grze...GOG.com dev team
 
GWINT: Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej...
GWINT: Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej...GWINT: Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej...
GWINT: Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej...GOG.com dev team
 
Jak wydaliśmy wiedźmina, GOG.com IT
Jak wydaliśmy wiedźmina, GOG.com ITJak wydaliśmy wiedźmina, GOG.com IT
Jak wydaliśmy wiedźmina, GOG.com ITGOG.com dev team
 
Dystrybucja gier w świecie online, przykład architektury webowego systemu ro...
Dystrybucja gier w świecie online, przykład architektury webowego systemu ro...Dystrybucja gier w świecie online, przykład architektury webowego systemu ro...
Dystrybucja gier w świecie online, przykład architektury webowego systemu ro...GOG.com dev team
 
Wykorzystanie technologii webowych w aplikacjach desktopowych (1)
Wykorzystanie technologii webowych w aplikacjach desktopowych  (1)Wykorzystanie technologii webowych w aplikacjach desktopowych  (1)
Wykorzystanie technologii webowych w aplikacjach desktopowych (1)GOG.com dev team
 
Design Thinking Workshop: Empathy in the User Experience
Design Thinking Workshop: Empathy in the User ExperienceDesign Thinking Workshop: Empathy in the User Experience
Design Thinking Workshop: Empathy in the User ExperienceGOG.com dev team
 
Lean UX - How to start with Lean Startup in User Experience
Lean UX - How to start with Lean Startup in User ExperienceLean UX - How to start with Lean Startup in User Experience
Lean UX - How to start with Lean Startup in User ExperienceGOG.com dev team
 
Czym jest złożoność ?
Czym jest złożoność ?Czym jest złożoność ?
Czym jest złożoność ?GOG.com dev team
 
Intro do Domain Driven Design. ( PL )
Intro do Domain Driven Design. ( PL )Intro do Domain Driven Design. ( PL )
Intro do Domain Driven Design. ( PL )GOG.com dev team
 
The story of GOG.com Cache - 4developers 2014 ( PL )
The story of GOG.com Cache - 4developers 2014 ( PL )The story of GOG.com Cache - 4developers 2014 ( PL )
The story of GOG.com Cache - 4developers 2014 ( PL )GOG.com dev team
 
The story of GOG.com Cache - PHPers 2014 ( PL )
 The story of GOG.com Cache - PHPers 2014 ( PL ) The story of GOG.com Cache - PHPers 2014 ( PL )
The story of GOG.com Cache - PHPers 2014 ( PL )GOG.com dev team
 

Más de GOG.com dev team (16)

In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
 
Always up to date, testable and maintainable documentation with OpenAPI
Always up to date, testable and maintainable documentation with OpenAPIAlways up to date, testable and maintainable documentation with OpenAPI
Always up to date, testable and maintainable documentation with OpenAPI
 
Symfony without the framework
Symfony without the frameworkSymfony without the framework
Symfony without the framework
 
Versioning challenges in micro services of Gwent
Versioning challenges in micro services of GwentVersioning challenges in micro services of Gwent
Versioning challenges in micro services of Gwent
 
Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej w grze...
Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej w grze...Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej w grze...
Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej w grze...
 
GWINT: Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej...
GWINT: Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej...GWINT: Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej...
GWINT: Przetwarzanie rozproszone z wykorzystaniem komunikacji asynchronicznej...
 
Jak wydaliśmy wiedźmina, GOG.com IT
Jak wydaliśmy wiedźmina, GOG.com ITJak wydaliśmy wiedźmina, GOG.com IT
Jak wydaliśmy wiedźmina, GOG.com IT
 
Dystrybucja gier w świecie online, przykład architektury webowego systemu ro...
Dystrybucja gier w świecie online, przykład architektury webowego systemu ro...Dystrybucja gier w świecie online, przykład architektury webowego systemu ro...
Dystrybucja gier w świecie online, przykład architektury webowego systemu ro...
 
Wykorzystanie technologii webowych w aplikacjach desktopowych (1)
Wykorzystanie technologii webowych w aplikacjach desktopowych  (1)Wykorzystanie technologii webowych w aplikacjach desktopowych  (1)
Wykorzystanie technologii webowych w aplikacjach desktopowych (1)
 
Design Thinking Workshop: Empathy in the User Experience
Design Thinking Workshop: Empathy in the User ExperienceDesign Thinking Workshop: Empathy in the User Experience
Design Thinking Workshop: Empathy in the User Experience
 
Lean UX - How to start with Lean Startup in User Experience
Lean UX - How to start with Lean Startup in User ExperienceLean UX - How to start with Lean Startup in User Experience
Lean UX - How to start with Lean Startup in User Experience
 
Varnish cache
Varnish cacheVarnish cache
Varnish cache
 
Czym jest złożoność ?
Czym jest złożoność ?Czym jest złożoność ?
Czym jest złożoność ?
 
Intro do Domain Driven Design. ( PL )
Intro do Domain Driven Design. ( PL )Intro do Domain Driven Design. ( PL )
Intro do Domain Driven Design. ( PL )
 
The story of GOG.com Cache - 4developers 2014 ( PL )
The story of GOG.com Cache - 4developers 2014 ( PL )The story of GOG.com Cache - 4developers 2014 ( PL )
The story of GOG.com Cache - 4developers 2014 ( PL )
 
The story of GOG.com Cache - PHPers 2014 ( PL )
 The story of GOG.com Cache - PHPers 2014 ( PL ) The story of GOG.com Cache - PHPers 2014 ( PL )
The story of GOG.com Cache - PHPers 2014 ( PL )
 

Último

What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 

Último (20)

Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 

Event sourcing w PHP (by Piotr Kacała)

  • 1. EVENT SOURCING (W PHP) PIOTR KACAŁA
  • 4. POBIERANIE ZAWARTOŚCI KOSZYKA mysql> select * from cart_products; +---------+------------+ | cart_id | product_id | +---------+------------+ | 1 | 124 | | 1 | 89 | +---------+------------+
  • 5. DODANIE PRODUKTU DO KOSZYKA POST /CARTS/{CID}/PRODUCTS INSERT INTO CART_PRODUCTS (…)
  • 6. USUNIĘCIE PRODUKTU Z KOSZYKA DELETE /CARTS/{CID}/PRODUCTS/{PID} DELETE FROM CART_PRODUCTS (…)
  • 8. PRZYPOMNIJMY mysql> select * from cart_products; +---------+------------+ | cart_id | product_id | +---------+------------+ | 1 | 124 | | 1 | 89 | +---------+------------+
  • 10. A CO JEŚLI? select * from salda_bankowe; +---------------------+----------------+ | rachunek | ile_pieniazkow | +---------------------+----------------+ | 4444 3333 2222 1111 | 1000 | +---------------------+----------------+
  • 12. TRUDNO SIĘ KŁÓCIĆ +---------------------+----------------+ | rachunek | ile_pieniazkow | +---------------------+----------------+ | 4444 3333 2222 1111 | 1000 | +---------------------+----------------+
  • 13. CZYM JEST EVENT SOURCING?
  • 14. EVENT STORE Cart #1 Was Created Product #B Added 
 To The Cart Product #A Removed 
 From The Cart Product #A Added 
 To The Cart Cart #1 Was Checked Out
  • 15. EVENT STORE Cart #1 Was Created Product #B Added 
 To The Cart Product #A Removed 
 From The Cart Product #A Added 
 To The Cart Cart #1 Was Checked Out
  • 16. JAK UPRAWIAĆ EVENT SOURCING (W PHP)?
  • 17. TRADYCYJNY KOSZYK class Cart
 {
 private $id;
 private $products = [];
 
 public function add($productId)
 { // changing the state of the cart $this->products[] = $productId;
 }
 }
  • 18. KOSZYK PRODUKUJĄCY EVENTY class Cart
 {
 private $id;
 private $products = [];
 private $raisedEvents = [];
 
 public function add($productId)
 { // changing the state of the cart
 $this->products[] = $productId;
 
 // let's raise an event
 $this->raisedEvents[] = new ProductAddedToCart($this->id, $productId);
 }
 }
  • 20. EVENT STORE Cart Was Created Product #2 Added 
 To The Cart Product #1 Added 
 To The Cart Cart Was Checked Out Product #1 Removed 
 From The Cart
  • 21. EVENT STORE mysql> select * from event_store; +----+--------------+-------------------------------------------+ | id | aggregate_id | event | +----+--------------+-------------------------------------------+ | 1 | 1 | CartWasCreated({"cartId":"1"}) | | 2 | 1 | ProductAddedToCart({"productId":"A"}) | | 3 | 1 | ProductRemovedFromCart({"productId":"A"}) | | 4 | 1 | ProductAddedToCart({"productId":"B"}) | +----+--------------+-------------------------------------------+
  • 22. ODTWARZANIE AGREGATU KOSZYKA W REPOZYTORIUM class EventSourcedCartRepository implements CartRepository
 {
 public function find($aggregateId)
 {
 $events = $this->eventStore->findEvents($aggregateId);
 $cart = new Cart(); // inicjalizacja pustego agregatu
 
 // "nagrywanie" eventów na agregacie cartu
 foreach($events as $event) { 
 // metoda apply() woła odpowiednie metody prywatne
 // na podstawie nazwy przekazywanego eventu, np.
 // ProductWasAddedToCart => applyProductWasAddedToCart
 $cart->apply($event); 
 }
 }
 }
  • 23. ENCJA class Cart {
 // this method is called by event store to replay event on the cart protected function applyProductAddedToCart(ProductAddedToCart $event)
 {
 $this->products[] = $event->getProductId();
 }
 }
  • 24. OBIE METODY class Cart
 {
 public function add($productId)
 {
 if ($this->products > 2) {
 throw new CartLimitExceeded();
 }
 
 // raise the event
 $event = new ProductAddedToCart($this->id, $productId);
 $this->raisedEvents[] = $event;
 
 // change the state
 $this->applyProductAddedToCart($event);
 }
 
 // change the state, this is called by Event Store
 public function applyProductAddedToCart(ProductAddedToCart $event)
 {
 $this->products[] = $event->getProductId();
 }
 }
  • 27. EVENT STORE mysql> select * from event_store; +----+--------------+-------------------------------------------+ | id | aggregate_id | event | +----+--------------+-------------------------------------------+ | 1 | 1 | CartWasCreated({"cartId":"1"}) | | 2 | 1 | ProductAddedToCart({"productId":"A"}) | | 3 | 1 | ProductRemovedFromCart({"productId":"A"}) | | 4 | 1 | ProductAddedToCart({"productId":"B"}) | +----+--------------+-------------------------------------------+
  • 29. MAŁY RECAP Obiekt 
 domeny Event Store Listenery Eventy TRAFIAJĄ DO ZAPISYWANE W PRODUKUJE
  • 30. PROJEKCJE class CurrentCartProductsProjector
 {
 public function applyProductAddedToCart(ProductAddedToCart $event)
 {
 $this->connection->query('insert into cart_products ...');
 }
 
 public function applyProductRemovedFromCart(ProductRemovedFromCart $event)
 {
 $this->connection->query('delete from cart_products ...');
 }
 }
  • 31. POBIERANIE ZAWARTOŚCI KOSZYKA mysql> select * from cart_products; +---------+------------+ | cart_id | product_id | +---------+------------+ | 1 | 124 | | 1 | 89 | +---------+------------+
  • 32. CQRS W PEŁNI SWOJEJ CHWAŁY Cart::add Zapis w 
 Event Store Product Was Added To Cart Cart State Projector SQL Redis
  • 33. CO Z ZADANIEM OD PANI MAŁGOSI?
  • 35. PLUSY EVENT SOURCINGU - HISTORYCZNY STAN APLIKACJI - DEBUGOWANIE - PROSTY MODEL ZAPISU - ODPORNOŚĆ NA KREATYWNOŚĆ BIZNESU - ŁATWA SKALOWALNOŚĆ - WSPÓŁGRA Z MIKROSERWISAMI
  • 36. MINUSY EVENT SOURCINGU - PRÓG WEJŚCIA (ZMIANA PRZYZWYCZAJEŃ) - KONIECZNOŚĆ SHARDOWANIA EVENT STORE’U* - DŁUŻSZY ŁADOWANIE OBIEKTÓW DOMENOWYCH** - ZWIĘKSZA ZŁOŻONOŚĆ APLIKACJI (VS CRUD) * NIE DOTYCZY WSZYSTKICH APLIKACJI ** ROZWIĄZANY PRZEZ SNAPSHOTY
  • 41. /WORK