1 / 60

Rethink your architecture with CQRS

Rethink your architecture with CQRS. Pieter Joost van de Sande Passionated software developer , Atos. E mail: pj@born2code.net @ twitter : pjvds. This is meant to be a take away!. Architecture. Architecture. Presentation. Domain. Data. Presentation. Why do we love it?. Domain.

xenos
Download Presentation

Rethink your architecture with CQRS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Rethinkyourarchitecturewith 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. Architecture Presentation Domain Data

  5. Presentation Why do we love it? Domain Data

  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. A model can only be optimized for one thing… and one thing only!

  11. Request data Update screen Send update Presentation layer Request DTO Send DTO Map DTO Map DTO Domain layer RequestDTO RequestDTO Send DTO Send DTO Map DTO Map DTO Map DTO Map DTO Data layer Query data Query data Query data Query data Write data Write data Write data Write data

  12. TWO fundamentals

  13. Information

  14. Transitions

  15. WRITING != READING

  16. From 3-tier to CQRS Presentation layer Domain layer Data layer

  17. Just re-order the tiers Presentation layer Data layer Domain layer

  18. Switch dependency Presentation layer Data layer Domain layer

  19. CQRS! Presentation layer Command side Query side Data layer Domain layer

  20. Here we go! From concept toArchitecturE

  21. User interface

  22. Demand for information

  23. Read side User interface

  24. We read a lot

  25. We have multiple screens to fill

  26. Data should be close to us

  27. Relational databases are sub optimal for view data!

  28. 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!

  29. 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 Bottom line

  30. Read side User interface

  31. Read side Read databases User interface

  32. Read side Read databases Facade User interface

  33. Read side Read databases Facade DTO’s User interface

  34. Demand for change

  35. I want to tell the system something

  36. Read side Write side Read databases Facade DTO’s User interface

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

  38. Commands • Simple messagecontainsall info needed • Lowercoupling (law of demeter) • Causesa state transition • Contains the intend of the user • Exists in a bounded context • Examples: • AddProductToShoppingCart • PurchaseOrder • MoveUserToNewAddress • CorrectAddressForUser • FinalizeOrder

  39. Commands example

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

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

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

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

  44. Event Sourcing

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

More Related