Domain-Driven Design and CQRS Xebia ITR on Command Query - - PowerPoint PPT Presentation

domain driven design and cqrs
SMART_READER_LITE
LIVE PREVIEW

Domain-Driven Design and CQRS Xebia ITR on Command Query - - PowerPoint PPT Presentation

Domain-Driven Design and CQRS Xebia ITR on Command Query Responsibility Separation Sjors Grijpink and Erik Rozendaal DDD Eric Evans, Domain- Driven Design, 2004 Key concepts Ubiquitous Language Value Object, Entity


slide-1
SLIDE 1

Domain-Driven Design and CQRS

Xebia ITR on Command Query Responsibility Separation Sjors Grijpink and Erik Rozendaal

slide-2
SLIDE 2

DDD

  • Eric Evans, Domain-

Driven Design, 2004

  • Key concepts
  • Ubiquitous Language
  • Value Object, Entity
  • Aggregate
slide-3
SLIDE 3

Ubiquitous Language

  • Language shared between domain experts

and developers

  • No need for error-prone translation
  • Maps directly to domain implementation
  • Implementation should be free of

“technical” terms

slide-4
SLIDE 4

Value Object

  • No conceptual identity
  • Describe characteristic of a thing
  • Usually immutable
  • Examples: Address, Money, ...
slide-5
SLIDE 5

Entity

  • Something with a unique identity
  • Identity does not change when any of its

attributes change

  • Examples: Customer, Order, ...
slide-6
SLIDE 6

Aggregate

  • Group of Entities &

Value Objects

  • One entity within the aggregate is the

aggregate root

  • All access to the objects inside go through

the root entity

  • Aggregates are consistency boundaries
slide-7
SLIDE 7

Lottery

  • Two aggregate roots
  • Lottery
  • Customer

Lottery Ticket Customer

slide-8
SLIDE 8

3 Tier

  • Presentation layer is

denormalized

  • Domain is behavioral
  • Transactional database

is normalized

slide-9
SLIDE 9

“A single model cannot be appropriate for reporting, searching, and transactional behaviors.” - Greg Young

slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14
slide-15
SLIDE 15

Purchase Lottery Ticket

slide-16
SLIDE 16

Purchase Lottery Ticket Lottery Ticket Purchased

slide-17
SLIDE 17

Purchase Lottery Ticket Lottery Ticket Purchased Find Lottery Tickets for Customer

slide-18
SLIDE 18

All state changes are represented by Domain Events

slide-19
SLIDE 19

Domain

slide-20
SLIDE 20

Reporting

slide-21
SLIDE 21

Packages

Domain Presentation Reporting Commands Events Queries

slide-22
SLIDE 22

Packages

Domain Presentation Reporting Commands Events Queries Shared

slide-23
SLIDE 23

Packages

Domain Presentation Reporting Commands Events Queries Shared CQRS framework

slide-24
SLIDE 24

Exercise 1

  • Implement “Create Customer”
  • Test that customers are listed on the

screen

  • Test that customers cannot be created with

an initial payment of less than 10.00

slide-25
SLIDE 25

Exercise 2

  • Implement “Purchase Lottery Ticket”
  • Ticket should be listed
  • Customer’s balance should be updated
  • Don’t forget to check the customer’s

account balance

slide-26
SLIDE 26

Benefits

slide-27
SLIDE 27

Benefits

  • Fully encapsulated domain that only exposes behavior
slide-28
SLIDE 28

Benefits

  • Fully encapsulated domain that only exposes behavior
  • Queries do not use the domain model
slide-29
SLIDE 29

Benefits

  • Fully encapsulated domain that only exposes behavior
  • Queries do not use the domain model
  • No object-relational impedance mismatch
slide-30
SLIDE 30

Benefits

  • Fully encapsulated domain that only exposes behavior
  • Queries do not use the domain model
  • No object-relational impedance mismatch
  • Bullet-proof auditing and historical tracing
slide-31
SLIDE 31

Benefits

  • Fully encapsulated domain that only exposes behavior
  • Queries do not use the domain model
  • No object-relational impedance mismatch
  • Bullet-proof auditing and historical tracing
  • Easy integration with external systems
slide-32
SLIDE 32

Benefits

  • Fully encapsulated domain that only exposes behavior
  • Queries do not use the domain model
  • No object-relational impedance mismatch
  • Bullet-proof auditing and historical tracing
  • Easy integration with external systems
  • Performance and scalability
slide-33
SLIDE 33

Benefits

  • Fully encapsulated domain that only exposes behavior
  • Queries do not use the domain model
  • No object-relational impedance mismatch
  • Bullet-proof auditing and historical tracing
  • Easy integration with external systems
  • Performance and scalability
  • Testability
slide-34
SLIDE 34

Bounded Context

slide-35
SLIDE 35

Advanced Topics

  • Snapshots
  • Command-event conflict resolution
  • Eventual consistency
  • Transaction-aware repository
  • ...
slide-36
SLIDE 36

Snapshot

Event Store 4 snapshot 3 2 1 Repository save load

slide-37
SLIDE 37

The End

  • Eric Evans, Domain-Driven Design
  • Greg

Young, Unshackle Your Domain