Presentation is loading. Please wait.

Presentation is loading. Please wait.

Rethink your architecture with CQRS Pieter Joost van de Sande Passionated software developer, Atos pjvds.

Similar presentations


Presentation on theme: "Rethink your architecture with CQRS Pieter Joost van de Sande Passionated software developer, Atos pjvds."— Presentation transcript:

1 Rethink your architecture with CQRS Pieter Joost van de Sande Passionated software developer, Atos Email: pj@born2code.net @twitter: pjvds

2 This is meant to be a take away!

3 Architecture

4 Presentation Domain Data

5 Presentation Domain Data Why do we love it?

6 model Domain Driven Design Eric Evans - 2003

7 The value of a structured Model

8 Who believes in this?

9 Structured models are always created from a single viewpoint!

10

11

12

13

14

15 A model can only be optimized for one thing… and one thing only!

16 Presentation layer Data layer Domain layer Send DTO Map DTO Write data Map DTO Write data Send DTO Request DTO Map DTO Request DTO Map DTO Query data Request data Map DTO Query data Request DTO Send update Update screen

17 TWO FUNDAMENTALS

18 Information

19 Transitions

20 WRITING != READING

21 From 3-tier to CQRS Presentation layer Domain layer Data layer

22 Presentation layer Domain layer Data layer Just re-order the tiers

23 Presentation layer Domain layer Data layer Switch dependency

24 Presentation layer Domain layer Data layer CQRS! Query side Command side

25 FROM CONCEPT TO ARCHITECTURE HERE WE GO!

26 User interface

27 Demand for information

28 User interface Read side

29 We read a lot

30 We have multiple screens to fill

31 Data should be close to us

32 Relational databases are sub optimal for view data!

33 SELECT CCUS.CUST_FIRST_NAME, CCUS.CUST_LAST_NAME, CINT.CUST_INTEREST_RANK, CILO.CUST_INTERST FROM CUST_CUSTOMER AS CCUS, CUST_INTEREST_LOOKUP AS CILO, CUST_INTEREST AS CINT WHERE ( CCUS.CUST_CITY = 'Singapore' AND CCUS.CUST_PROV_STATE = 'Singapore' AND CCUS.CUST_CODE IN ( SELECT COHE.CUST_CODE FROM CUST_ORDER_HEADER AS COHE, CUST_ORDER_STATUS AS COST WHERE ( COHE.CUST_ORDER_DATE >='2009-01-01 00:00:00.001' AND COST.CUST_ORDER_STATUS IN( 'Shipped', 'Back-ordered', 'In-process' ) AND COHE.CUST_ORDER_STATUS_CODE = COST.CUST_ORDER_STATUS_CODE ) AND CCUS.CUST_CODE = CINT.CUST_CODE AND CINT.CUST_INTEREST_CODE = CILO.CUST_INTEREST_CODE ) ORDER BY CCUS.CUST_LAST_NAME ASC, CCUS.CUST_FIRST_NAME ASC, CINT.CUST_INTEREST_RANK ASC Evil execution plan!

34 Bottom line Getting data should be simple – select * from x where y Examples: – Get all products of user X – Get total price of all orders of month May

35 User interface Read side

36 User interface Read databases

37 Read side User interface Read databases Facade

38 Read side User interface Facade Read databases DTO’s

39 Demand for change

40 I want to tell the system something

41 Read side User interface Facade Read databases DTO’s Write side

42 User interface Commandhandlers Read databases Read side commands DTO’s Write side Facade

43 Commands Simple message contains all info needed Lower coupling (law of demeter) Causes a state transition Contains the intend of the user Exists in a bounded context Examples: – AddProductToShoppingCart – PurchaseOrder – MoveUserToNewAddress – CorrectAddressForUser – FinalizeOrder

44 Commands example Create Cart Add item Remove item Purchase

45 Users don’t make changes for nothing, intent is important!

46 Change has intent Users don’t make changes for nothing This intent has value! Correct the address for user X Customer X moved to new address VS.

47 User interface Commandhandlers Read databases Read side commands DTO’s Write side Facade

48 User interface Commandhandlers Read databases Read side commands DTO’s Domein Write side Repository Facade

49 Event Sourcing

50 Events Simple message that describes an event Contains intent Contains all the data related to the event Past tense CustomerMoved { CustomerId, NewAddress }

51 Transitional flow

52 User interface Commandhandlers Read databases Read side commands DTO’s Domein Write side Repository Facade

53 User interface Commandhandlers Read databases Read side commands DTO’s Domein Write side Repository Facade

54 Event store Contains all domain events Does not need to be relational Write are *awesomely* fast! Rock solid audit log Read models can (re)build themself of it The domain uses it to get the current state Can be used to build any structural model you want!

55 User interface Commandhandlers Read databases Read side commands DTO’s Domein Write side Repository ? Facade

56 User interface Commandhandlers Repository Event bus Read databases Write side Read side events commands DTO’s Domein Facade

57 User interface Commandhandlers Repository Event bus Denormalizers Read databases Write side Read side events commands DTO’s Domein Facade

58 Application flow

59 Wrap up Optimize for reading and writing Makes changes part of the problem domain Free rock solid audit log Capture the intent of changes Allow multiple read models

60 Thank you! You’ve been a great audience!


Download ppt "Rethink your architecture with CQRS Pieter Joost van de Sande Passionated software developer, Atos pjvds."

Similar presentations


Ads by Google