XebiCon'16 : CQRS/EventSourcing certains en parlent, nous les avons implémentés ! Par...

Preview:

Citation preview

@xebiconfr #xebiconfr

Event Sourcing/CQRS Certains en parlent, nous les avons

implémentés!

Clément HELIOU

@c_heliou @xebiconfr #xebiconfr 2

@c_heliou

@c_heliou @xebiconfr #xebiconfr

L’Event SourcingEn bref

@c_heliou @xebiconfr #xebiconfr 4

« Capturer tous les changements d’état d’une application comme une séquence d’évènements »

Martin Fowler

@c_heliou @xebiconfr #xebiconfr 5

Date Débit Crédit

2016/05/14 100 €

2016/05/14 -20 €

2016/05/16 -30 €

2016/05/24 380 €

2016/06/01 -70 €

Total -120 € 480 €

Solde 360 €

@c_heliou @xebiconfr #xebiconfr 6

Pourquoi utiliser l’Event Sourcing?

Audit

Analyse/debugReprise dedonnées

Performance

@c_heliou @xebiconfr #xebiconfr 7

Application

Inspiré par J. Chassaing - http://thinkbeforecoding.com/post/2014/01/04/Event-Sourcing.-Draw-it

Commande

Fonction de Décision

@c_heliou @xebiconfr #xebiconfr 8

Fonction de décision (état courant + commande)

=> évènement(s)

@c_heliou @xebiconfr #xebiconfr 9

Application

Inspiré par J. Chassaing - http://thinkbeforecoding.com/post/2014/01/04/Event-Sourcing.-Draw-it

Fonction de Décision

Commande

Fonction d’évolution

Évènement(s)

Event store

@c_heliou @xebiconfr #xebiconfr 10

Fonction d’évolution (état courant + évènement)

=> nouvel étatPour chaque évènement émis par

la fonction de décision

@c_heliou @xebiconfr #xebiconfr 11

Application

Inspiré par J. Chassaing - http://thinkbeforecoding.com/post/2014/01/04/Event-Sourcing.-Draw-it

Évènement(s)Fonction de

Décision

Commande

Fonction d’évolution Event

store

Action

Effets de bord

@c_heliou @xebiconfr #xebiconfr

Contexte Au coeur des

salles de marché

@c_heliou @xebiconfr #xebiconfr 13

@c_heliou @xebiconfr #xebiconfr 14

http://www.les-terres-rares.com/platine-palladium-meme-famille-2-destins-differents/

@c_heliou @xebiconfr #xebiconfr 15

Couverture

Livraison physique

A l’échéance

@c_heliou @xebiconfr #xebiconfr 16

Client

Comptabilité

Trader Marché

Vendeur

Avant Multiplus

@c_heliou @xebiconfr #xebiconfr 17

Client

Comptabilité

Automatede prix

Marché

Multiplus

Avec Multiplus

Couverture

Limites

Marges

@c_heliou @xebiconfr #xebiconfr

L’EVENT SOURCINGchez Multiplus

@c_heliou @xebiconfr #xebiconfr 19

Application

Inspiré par J. Chassaing - http://thinkbeforecoding.com/post/2014/01/04/Event-Sourcing.-Draw-it

Fonction de Décision

RecevoirPrix {commande}

@c_heliou @xebiconfr #xebiconfr 20

Fonction de décision (état courant + commande)

=> évènement(s)

@c_heliou @xebiconfr #xebiconfr 21

Fonction de décision (état courant + RecevoirPrix)

=> PrixReçu

@c_heliou @xebiconfr #xebiconfr 22

Application

Inspiré par J. Chassaing - http://thinkbeforecoding.com/post/2014/01/04/Event-Sourcing.-Draw-it

Fonction de Décision

RecevoirPrix {commande}

Fonction d’évolution

PrixReçu{évènement}

@c_heliou @xebiconfr #xebiconfr 23

@c_heliou @xebiconfr #xebiconfr 24

Application

Inspiré par J. Chassaing - http://thinkbeforecoding.com/post/2014/01/04/Event-Sourcing.-Draw-it

Fonction de Décision

RecevoirPrix {commande}

Fonction d’évolution

PrixReçu{évènement}

Demande de prix

Réception de prix

PrixReçu{évènement}

TransférerPrix {action}

PrixTransféré {évènement}

@c_heliou @xebiconfr #xebiconfr 25

Application

PrixReçu{évènement}

PrixTransféré {évènement}

Bus d’évènements

PrixTransféréHandler {handler}

CLIENT

@c_heliou @xebiconfr #xebiconfr 26

Bus

Handler

HandlerEMS

thread pool

IUM thread

pool

EMS thread

pool

IUM thread

pool

Event loop

Commandes Évènements

Messages

Messages

@c_heliou @xebiconfr #xebiconfr 27

Bus

Handler

HandlerEMS

thread pool

IUM thread

pool

EMS thread

pool

IUM thread

pool

Event loop

Commandes Évènements

Messages

Messages

@c_heliou @xebiconfr #xebiconfr 28

C1 C2 C3

C1 = 10 ms C2 = 10 msC2 = 10 ms C2 = 10 + 10 ms

@c_heliou @xebiconfr #xebiconfr 29

Bus

Handler

HandlerEMS

thread pool

IUM thread

pool

EMS thread

pool

IUM thread

pool

Event loop

Commandes Évènements

Messages

Messages

@c_heliou @xebiconfr #xebiconfr 30

Bus

Handler

HandlerEMS

thread pool

IUM thread

pool

EMS thread

pool

IUM thread

pool

Event loop

CommandesÉvène

ments

Messages

Messages

Event loop

@c_heliou @xebiconfr #xebiconfr 31

Bus

Handler

HandlerEMS

thread pool

IUM thread

pool

EMS thread

pool

IUM thread

pool

Event loop

Commandes

Évènements

Messages

Messages

Event loop

Commandes

@c_heliou @xebiconfr #xebiconfr

Event sourcing ce que l’on a appris

@c_heliou @xebiconfr #xebiconfr 33

Vous pouvez (devez ?) faire sans framework

@c_heliou @xebiconfr #xebiconfr 34

Ne pas confondre Event sourcing et Command sourcing

@c_heliou @xebiconfr #xebiconfr 35

Application

Inspiré par J. Chassaing - http://thinkbeforecoding.com/post/2014/01/04/Event-Sourcing.-Draw-it

Évènement(s)Fonction de

Décision

Commande

Fonction d’évolution Event

store

Action

@c_heliou @xebiconfr #xebiconfr 36

Application

Inspiré par J. Chassaing - http://thinkbeforecoding.com/post/2014/01/04/Event-Sourcing.-Draw-it

Évènement(s)Fonction de

Décision

Commande

Fonction d’évolution Event

store

Action

@c_heliou @xebiconfr #xebiconfr 37

Recevoir prix {commande}

requêteId: 9387prix: 100€

Fonction de Décision

Fonction de Décision

Prix reçu{évènement}

requêteId: 9387prix: 100€marge: 0,10€

Recevoir prix {commande}

requêteId: 9387prix: 100€

Prix reçu{évènement}

requêteId: 9387prix: 100€marge: 0,20€

12/02/2016 - Marge 0,1%

01/07/2016 - Marge 0,2%

@c_heliou @xebiconfr #xebiconfr 38

Dénommer un évènement n’est pas chose Aisée.

« Anatomy of domain event » M. Praglowski - http://blog.arkency.com/2016/05/the-anatomy-of-domain-event/

@c_heliou @xebiconfr #xebiconfr

CQRS En bref

@c_heliou @xebiconfr #xebiconfr 40

Command Query Responsibility Segregation ?

@c_heliou @xebiconfr #xebiconfr 41

Pourquoi utiliser CQRS?

Maintenabilité

Performance des lectures

Intégration avec

l’Event Sourcing

@c_heliou @xebiconfr #xebiconfr

Contexte Monitorer

notre business

@c_heliou @xebiconfr #xebiconfr 43

Monitoring « Métier »

Contrôles basiquespar client, produit, etc.

Suivi temps-réel des transactions

@c_heliou @xebiconfr #xebiconfr

CQRS chez Multiplus

@c_heliou @xebiconfr #xebiconfr 45

Bus d’évènementsMultiplus

Handler

PUSH-API

Fonction de STOCKAGE

Fonction D’AGREGATION

Event store

Évènement

QUEUE EMS

WEB SOCKETVue CONSOLE

Vue

@c_heliou @xebiconfr #xebiconfr 46

PUSH-API

Fonction de STOCKAGE

Fonction D’AGREGATION

Event store

WEB SOCKET CONSOLE

Évènement{transaction #345}

Évènements {transaction #345}

Vue {transaction #345} Vue

{transaction #345}

@c_heliou @xebiconfr #xebiconfr 47

Fonction D’AGREGATION

ExécutionDemandée{transaction #345,idSéquence = 1}

ExécutionAcceptée{transaction #345,idSéquence = 2}

Fonction D’AGREGATION

Vue{transaction #345,

statut = TERMINÉE}

Vue{transaction #345,

statut = EN COURS}

@c_heliou @xebiconfr #xebiconfr 48

Fonction D’AGREGATION

ExécutionDemandée{transaction #345,idSéquence = 1}

ExécutionAcceptée{transaction #345,idSéquence = 2}

Fonction D’AGREGATION

Vue{transaction #345,

statut = TERMINÉE}

Vue{transaction #345,

statut = EN COURS}

Fonction D’AGREGATION

ExécutionAcceptée{transaction #345,idSéquence = 2}

Vue{transaction #345,

statut = TERMINÉE}

@c_heliou @xebiconfr #xebiconfr

CQRS ce que l’on a appris

@c_heliou @xebiconfr #xebiconfr 50

Il existe toujours un contrat, même s’il est implicite !

@c_heliou @xebiconfr #xebiconfr 51

Poser la 1ère pierre, à l’édifice CQRS !

Évènements d’intérêt

Évènements en mémoire

@c_heliou @xebiconfr #xebiconfr

CONCLUSION

@c_heliou @xebiconfr #xebiconfr 53

Ressources๏ Xebicon 15’ - CQRS + Event Sourcing: en direct !

๏ Back Day 15’ - Explorer les principes de l’event sourcing

๏ Thinkbe4coding #Eventsourcing

๏ KATA MixteR- https://github.com/devlyon/mixter- Kata explorant les principes de l’Event Sourcing/CQRS.

- https://www.youtube.com/watch?v=QGGZs0KqxZw- Live coding présentant les principes de l’Event Sourcing/CQRS.

- http://thinkbeforecoding.com/tag/Event%20Sourcing- L’un des auteurs français à suivre sur le sujet Event Sourcing/CQRS.

- http://www.xebia.tv/vod?videoId=S8566fyZHp0- Présentation plus large du projet Multiplus (DDD, BDD, Architecture hexagonale).

Recommended