SlideShare a Scribd company logo
1 of 132
Download to read offline
Loosely
Coupled
Complexity


  Unleash
the
power
of
your
Domain

  Model
using
CQRS
&
Event
Sourcing
       Alberto.brandolini@avanscopertas.it
About
me
In
the
IT
field
since
ZX
Spectrum
Generally
in
large
scale
projects
(I
might
be
biased)
Freelance
consultant:
NotOnlyCode
Trainer
(Freelance
&
Skills
MaKer
+
Zenika)
Technical
Writer
Blogger:
h>p://ziobrando.blogspot.com
TwiKer:
ziobrando


My
e‐mail:

alberto.brandolini@gmail.com
@avanscoperta
www.avanscoperta.it
avanscoperta.wordpress.com
alberto.brandolini@avanscoperta.it




                               ©
Alberto
Brandolini
2009
These
3
guys

have
something

really
interesEng
to

share
What’s
wrong
with
that?



                            ApplicaEon
Services
            Remote
facade
     DTO




                                                  ORM
UI
      DTO




                                                        ©
Alberto
Brandolini
‐
2010
nothing
Thank
you
alberto.brandolini@avanscoperta.it
  hKp://ziobrando.blogspot.com
         twiKer:
ziobrando
...What

hump?




           ‐
Quale
gobba?
How
many
assumpEons

are
driving
our
choices?
let’s
try
again...



                            ApplicaEon
Services
            Remote
facade
     DTO




                                                  ORM
UI
      DTO




                                                        ©
Alberto
Brandolini
‐
2010
Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing
Anaemic Domain Model
Anaemic Domain Model

DTOs?
Anaemic Domain Model

DTOs?

Optimizing ORM queries
Anaemic Domain Model

DTOs?

Optimizing ORM queries

Development time
Anaemic Domain Model

DTOs?

Optimizing ORM queries

Development time

Testability
Anaemic Domain Model

DTOs?

Optimizing ORM queries

Development time

Testability

...
Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing
Do we really need...
Do we really need...

  a Domain Model?
Do we really need...

  a Domain Model?

  a Database?
Do we really need...

  a Domain Model?

  a Database?

  transactions?
Do we really need...

  a Domain Model?

  a Database?

  transactions?

  an Object Relational Mapper?
Do we really need...

  a Domain Model?

  a Database?

  transactions?

  an Object Relational Mapper?

  DTOs?
Anaemic
Domain
Model

       <<Ser vice>>               <<Entity>>

      OrderService
                                   Order
 registerOrder(...)
                           date
 closeOrder(...)
                           customer
 checkOrder(...)
                           amount
 updateAvailability(...)
                           ...

                           getDate()
                           setDate(...)
                           getCustomer()
                           setCustomer(...)
                           getAmount()
                           setAmount()
                           ...
Not
every
present
is

 necessarily
nice
Advantages
of
Anaemic
Domain
Model
Advantages
of
Anaemic
Domain
Model

1)
Business
code
is
located
in
a
single
place:
Advantages
of
Anaemic
Domain
Model

1)
Business
code
is
located
in
a
single
place:
 Easier
to
read
for
young
developers
not
familiar
with

 OOP
Advantages
of
Anaemic
Domain
Model

1)
Business
code
is
located
in
a
single
place:
 Easier
to
read
for
young
developers
not
familiar
with

 OOP




 Sorry,
can’t
find
number
2
:‐(
Disadvantages
of
Anemic
Domain

            Model




Sad
as
a
hospital
meal
Disadvantages
of
Anemic
Domain

            Model


                 hard
to
maintain




Sad
as
a
hospital
meal
Disadvantages
of
Anemic
Domain

            Model


                 hard
to
maintain
                      hard
to
test



Sad
as
a
hospital
meal
Disadvantages
of
Anemic
Domain

            Model


                  hard
to
maintain
                       hard
to
test
                fosters
duplicaEon


Sad
as
a
hospital
meal
Disadvantages
of
Anemic
Domain

            Model


                  hard
to
maintain
                       hard
to
test
                fosters
duplicaEon


Sad
as
a
hospital
meal
How
to
shoot
yourself
in
the
foot




                          avanscoper
                              ta
How
to
shoot
yourself
in
the
foot
  Design your application starting from the data model




                                                         avanscoper
                                                             ta
How
to
shoot
yourself
in
the
foot
  Design your application starting from the data model
  Create your domain model by reverse engineering




                                                         avanscoper
                                                             ta
How
to
shoot
yourself
in
the
foot
  Design your application starting from the data model
  Create your domain model by reverse engineering
  Pretend that you’re doing TDD and start testing your domain classes




                                                         avanscoper
                                                             ta
How
to
shoot
yourself
in
the
foot
  Design your application starting from the data model
  Create your domain model by reverse engineering
  Pretend that you’re doing TDD and start testing your domain classes
      Particularly getters and setters




                                                         avanscoper
                                                             ta
How
to
shoot
yourself
in
the
foot
  Design your application starting from the data model
  Create your domain model by reverse engineering
  Pretend that you’re doing TDD and start testing your domain classes
      Particularly getters and setters

  Now start testing the logic with Integration Tests and get stuck by
  test data related issues




                                                         avanscoper
                                                             ta
How
to
shoot
yourself
in
the
foot
  Design your application starting from the data model
  Create your domain model by reverse engineering
  Pretend that you’re doing TDD and start testing your domain classes
      Particularly getters and setters

  Now start testing the logic with Integration Tests and get stuck by
  test data related issues
  Declare that TDD provides no benefit and only slows you down




                                                         avanscoper
                                                             ta
How
to
shoot
yourself
in
the
foot
  Design your application starting from the data model
  Create your domain model by reverse engineering
  Pretend that you’re doing TDD and start testing your domain classes
      Particularly getters and setters

  Now start testing the logic with Integration Tests and get stuck by
  test data related issues
  Declare that TDD provides no benefit and only slows you down
  Comment tests in your Build-Integration process


                                                         avanscoper
                                                             ta
How
to
shoot
yourself
in
the
foot
  Design your application starting from the data model
  Create your domain model by reverse engineering
  Pretend that you’re doing TDD and start testing your domain classes
      Particularly getters and setters

  Now start testing the logic with Integration Tests and get stuck by
  test data related issues
  Declare that TDD provides no benefit and only slows you down
  Comment tests in your Build-Integration process
  Keep on whining
                                                         avanscoper
                                                             ta
I won’t reverse engineer my
data model to create a
domain model
I won’t reverse engineer my
data model to create a
domain model

I won’t reverse engineer my
data model to create a
domain model
I won’t reverse engineer my data
model to create a domain model

I won’t reverse engineer my data
model to create a domain model

I won’t reverse engineer my data
model to create a domain model
I won’t reverse engineer my data
model to create a domain model

I won’t reverse engineer my data
model to create a domain model

I won’t reverse engineer my data
model to create a domain model

I won’t reverse engineer my data
model to create a domain model
I won’t reverse engineer my data model to
create a domain model

I won’t reverse engineer my data model to
create a domain model

I won’t reverse engineer my data model to
create a domain model

I won’t reverse engineer my data model to
create a domain model

I won’t reverse engineer my data model to
create a domain model
I won’t reverse engineer my data model to create a
domain model

I won’t reverse engineer my data model to create a
domain model

I won’t reverse engineer my data model to create a
domain model

I won’t reverse engineer my data model to create a
domain model

I won’t reverse engineer my data model to create a
domain model

I won’t reverse engineer my data model to create a
domain model
How
should
we
implement
a
Domain
Model?
How
should
we
implement
a
Domain
Model?
How
should
we
implement
a
Domain
Model?
Behavior
should
be

placed
in
the


Domain
Model
How
should
we
implement
a
Domain
Model?
Behavior
should
be

placed
in
the


Domain
Model
Have
your
code

speak
the
Ubiquitous

Language
How
should
we
implement
a
Domain
Model?
Behavior
should
be

placed
in
the


Domain
Model
Have
your
code

speak
the
Ubiquitous

Language
Use
Aggregates
as
unit

of
consistency
across

your
domain
model
How
should
we
implement
a
Domain
Model?
Behavior
should
be

placed
in
the


Domain
Model
Have
your
code

speak
the
Ubiquitous

Language
Use
Aggregates
as
unit

of
consistency
across

your
domain
model
Protect
your
model

with
clearly
defined

Bounded
Contexts
Anemic
Domain
Model

      <<Ser vice>>               <<Entity>>

     OrderService
                                  Order
registerOrder(...)
                          date
closeOrder(...)
                          customer
checkOrder(...)
                          amount
updateAvailability(...)
                          ...

                          getDate()
                          setDate(...)
                          getCustomer()
                          setCustomer(...)
                          getAmount()
                          setAmount()
                          ...
Rich
domain
model          <<Value Object>>
                          <<Entity>>
           ....
                                     Order           LineItem
registerOrder(...)
                          date               goods
closeOrder(...)
                          customer           quantity
checkOrder(...)
                          amount             notes
updateAvailability(...)
                          ...
                                             calculate amount()
                          update()           ...
                          close()
                          ship()
                          ...


                                             <<Value Object>>
                          <<Value Object>>
                                                      Money
                                  Customer
                                             currency
                          name               amount
                          surname
                          address            plus(Money other)
                                             minus(Money other)
                          annota()...        ...
s
           TDD
and
DDD
                       Frequent
rewriEng

       Focus
on
Unit
Tests
                               Exploratory
coding
    Frequent
Short
Cycles
                             Tiny
Domain
Objects
               Quick
Feedback
                    Self
explanatory
code
                         Freedom
to
change   ©
Alberto
Brandolini
‐
2010
Aggregate




            ©
Alberto
Brandolini
‐
2010
Aggregate


A
group
of
objects
that

naturally
belong
together
Unit
of
consistency
in
the

domain
model

updated
in
the
same

transacEon
deleted
together
transferred
together

                              ©
Alberto
Brandolini
‐
2010
Aggregate
                              <<Entity>>         <<Value Object>>

                                         Order           LineItem
                              date               goods
A
group
of
objects
that
      customer
                              amount
                                                 quantity
                                                 notes

naturally
belong
together
                              ...
                                                 subtotal()
                              update()           ...
                              close()
Unit
of
consistency
in
the
   ship()
                              ...

domain
model                  <<Value Object>>
                                                 <<Value Object>>

                                                            Money
                                      Customer
                                                 currency

updated
in
the
same

                              name               amount
                              surname
                              address            plus(Money other)

transacEon
                                                 minus(Money other)
                                                 ...


deleted
together
transferred
together

                                                         ©
Alberto
Brandolini
‐
2010
MulEple
aggregates
                               Money
                    currency
                    amount

                    plus(Money other)
                    minus(Money other)
                    ...




 <<Entity>>         <<Root>>             <<Value Object>>
                                                                                     <<Entity>>    <<Root>>
            Order                                    LineItem
                                                                                             Customer
 date                                    goods
                                                                                     name
 customer                                quantity
                                                                                     surname
 amount                                  notes
                                                                                     address
 ...
                                         subtotal()                                  ...
 update()                                ...
                                                                                     updateDiscount()
 close()
                                                                                     ...
 ship()
 ...


                                              shipping address
 <<Value Object>>

      CustomerData
                                   billing address
 name
 surname                                                         <<Value Object>>

                                                                           Address
                                              <<Value Object>>   street
                                                                 city
                                                                 country
                                                                 zipcode




                                                                                                              ©
Alberto
Brandolini
‐
2010
Isn’t
duplicaEon
bad?
‐   If
you
think
“data”
then,
...there’s
duplica6on

‐   If
you
think
“behaviour”
then
some
objects

    definitely
are
not
the
same


‐   enforcing
aggregates
boundaries
makes
your
system
    ‐   strictly
consistent
within
the
aggregate
boundaries

    ‐   eventually
consistent
outside
the
aggregate
boundaries




                                                         ©
Alberto
Brandolini
‐
2010
It
turns
out
to
be
simple




                            ©
Alberto
Brandolini
‐
2010
Why
does
it
have
to
be
hard?




                          ©
Alberto
Brandolini
‐
2010
Hmm...
Once
coupling

between

aggregates
is

dramaEcally

reduced,
I
can

potenEally
choose

a
different

persistence

strategy
for
each

aggregate...
                     ©
Alberto
Brandolini
‐
2010
From
the
same
old
stuff



                            ApplicaEon
Services
            Remote
facade
     DTO




                                                  ORM
UI
      DTO




                                                        ©
Alberto
Brandolini
‐
2010
TradiEonal
DDD
view



                             ApplicaEon
Services
             Remote
facade
      DTO




                                                   ORM
UI
       DTO




                                                         ©
Alberto
Brandolini
‐
2010
TradiEonal
DDD
view
           bou
             c o n n de d
                  te x
                       ts




                             ApplicaEon
Services
             Remote
facade
      DTO




                                                   ORM
UI
       DTO




                                                         ©
Alberto
Brandolini
‐
2010
TradiEonal
DDD
view



                             ApplicaEon
Services
             Remote
facade
      DTO




                                                   ORM
UI
       DTO




                                                         ©
Alberto
Brandolini
‐
2010
TradiEonal
DDD
view
            ag g
                 r   bou           ega
                               n d a te
                                    r ie
                                         s




                             ApplicaEon
Services
             Remote
facade
      DTO




                                                   ORM
UI
       DTO




                                                         ©
Alberto
Brandolini
‐
2010
TradiEonal
DDD
view



                             ApplicaEon
Services
             Remote
facade
      DTO




                                                   ORM
UI
       DTO




                                                         ©
Alberto
Brandolini
‐
2010
TradiEonal
DDD
view
     t hi
            na
                pp l


                                          ApplicaEon
Services
                          Remote
facade
             l ay ic at io
            DTOe r         n




                                                                ORM
UI
              DTO




                                                                      ©
Alberto
Brandolini
‐
2010
TradiEonal
DDD
view



                             ApplicaEon
Services
             Remote
facade
      DTO




                                                   ORM
UI
       DTO




                                                         ©
Alberto
Brandolini
‐
2010
Sending
Domain
Objects
to
the
UI?




                            ©
Alberto
Brandolini
‐
2010
Sending
Domain
Objects
to
the
UI?

‐ Nobody
really
likes
DTOs...




                                ©
Alberto
Brandolini
‐
2010
Sending
Domain
Objects
to
the
UI?

‐ Nobody
really
likes
DTOs...
‐ Some
tools
allow
that!
(let’s
have
some
more

  hawaiian
shirts)




                                         ©
Alberto
Brandolini
‐
2010
Sending
Domain
Objects
to
the
UI?

‐ Nobody
really
likes
DTOs...
‐ Some
tools
allow
that!
(let’s
have
some
more

  hawaiian
shirts)
‐ Validafon
creep


                                         ©
Alberto
Brandolini
‐
2010
Sending
Domain
Objects
to
the
UI?

‐ Nobody
really
likes
DTOs...
‐ Some
tools
allow
that!
(let’s
have
some
more

  hawaiian
shirts)
‐ Validafon
creep
‐ Double
state
objects

                                         ©
Alberto
Brandolini
‐
2010
Sending
Domain
Objects
to
the
UI?

‐ Nobody
really
likes
DTOs...
‐ Some
tools
allow
that!
(let’s
have
some
more

  hawaiian
shirts)
‐ Validafon
creep
‐ Double
state
objects
 ‐   Framework
temptafon
:‐(


                                         ©
Alberto
Brandolini
‐
2010
Sending
Domain
Objects
to
the
UI?

‐ Nobody
really
likes
DTOs...
‐ Some
tools
allow
that!
(let’s
have
some
more

                                           ens
  hawaiian
shirts)
                                         ap p
                                   at  h is
‐ Validafon
creep              W h         I
                                          U rom
                                    t he t f
‐ Double
state
objects          in
                                       er en in
 ‐   Framework
temptafon
:‐(     d iff oma
                                      e d
                                   th        l!
                                       o de
                                    m   ©
Alberto
Brandolini
‐
2010
How
would
you
implement
this?
                         As a Sales Office
                         I want to ship order on purchase
                         command
                         In order to deliver purchased
                         goods to the customer
As a Marketing Office
I want to assign discount points
to customer on every purchase
In order to enable more deals in
the future


                                                ©
Alberto
Brandolini
‐
2010
Events
and
aggregate
coordinaEon
 ‐ Operafons
spanning
mulfple

    aggregates
shouldn’t
be
in
the
same

    Unit
of
Work


‐   Communicafon
between
aggregates
       <<Domain Event>>
    is
inherently
asynchronous                   OrderPurchased


‐   Domain
Events
as
a
communicafon

                                           order
                                           where
    mechanism                              when
                                           amount
    ‐   from
the
outside                   payment method

    ‐   among
aggregates                   ...

                                           ...

                                                       ©
Alberto
Brandolini
‐
2010
Domain
Event


‐ in
the
Ubiquitous
Language,
they’re

 Completed
AcEons:
verbs
in
past
tense.




                                   ©
Alberto
Brandolini
‐
2010
Asynchronously
responding
to
events
                                                          <<Domain Event>>
                                                                OrderPurchased

                                                          order
                                                          where
                                                          when
                                                          amount
      <<Entity>>       <<Root>>                           payment method         s u bs                    <<Entity>>    <<Root>>
                                                   s to   ...                             cri b
               Order              su b   s c ri be                                                e s to
                                                                                                                   Customer
      date                                                ...
                                                                                                           name
      customer
                                                                                                           surname
      amount
                                                                                                           address
      ...
                                                                                                           ...
      onPurchaseEvent(...)
                                                                                                           onPurchaseEvent(...)
      update()
                                                                                                           updateDiscount()
      close()
                                                                                                           ...
      ship()
      ...




‐   Don’t
forget:
Business
rules
everything!!!

                                                                                                                        ©
Alberto
Brandolini
‐
2010
Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing
SOA
Anyone?
...just
draw
it
differently

     and
think
about

   “service
granularity”
Command/Query

 Responsibility

  SegregaEon
Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing
Why
do
we
have
to

choose
a
trade‐off?
StarEng
small...

‐ Command/Query
SeparaEon
was
an
OOD

 principle
part
of
DDD
 ‐   accessors
shouldn’t
have
side
effects
 ‐   mutators
shouldn’t
return
a
value

     ‐   (with
the
excepfon
of
this
in
some
cases)




                                                     ©
Alberto
Brandolini
‐
2010
Command



!
      Usually
targeted
to
single
enEEes
      Behaviour
maKers
      Flexibility
maKers




                                ©
Alberto
Brandolini
‐
2010
Query



?
        Large
amount
of
data
        No
behavior
        Performance
maKers
        Availability
of
off‐the
shelves
components
                                         ©
Alberto
Brandolini
‐
2010
!
?
         UI
              DTO



   DTO
Remote
facade
ApplicaEon
Services
                      from
this...




         ORM
!
?
                     UI
               DTO
                          DTO
                                           ...to
this


Remote
facade             Remote
facade
                          ApplicaEon
Services




 Thin
Read
Layer




                                ORM
!
        A
separate
path
for

      commands
issued
to
the

          Domain
Model




?   A
separate
path
for
querying

                Data
?               Querying
‐   Have
a
look
to
Users,
what
are

    they
really
interested
in?
    ‐   It’s
not
searching,
it’s
finding
    ‐   It’s
not
refreshing,
it’s

        looking
for
events
                                  ©
Alberto
Brandolini
‐
2010
?               Staleness
‐ Is
it
really
so
bad?
‐ Does
it
really
maKers
if
the
data
is...

    ‐ 20
seconds
old?
    ‐ Or
10
minutes?
‐ ...
who
are
we
to
decide
this?
‐ ...
can
you
keep
a
print
in
sync?
                                      ©
Alberto
Brandolini
‐
2010
?            It’s
just
data


‐   There’s
no
behaviour
in
what
we
see.
‐ Do
we
really
need
objects
for
that?

                                  ©
Alberto
Brandolini
‐
2010
?       Query‐Only
Architecture
‐   It’s
just
(stale)
data:
no
behaviour...
    ‐   =>
Why
don’t
we
go
straight
to
the
database?

‐   No
coupling
between
UI
screens...
    ‐   =>
Do
we
really
need
referenEal
integrity?

    ‐   =>
Why
don’t
we
just
a
table‐per‐UI‐view
strategy,

        calculated
in
the
background?

‐   What
are
we
already
doing
with
the
search
model

    and
the
cache?
                                                         ©
Alberto
Brandolini
‐
2010
?        Even
stale
data
can


‐ ...
provide
useful
informafon
for

    preliminary
validaEon
of
commands
    ‐ =>
less
failing
commands

                                       ©
Alberto
Brandolini
‐
2010
!      ...less
failing
commands
    ‐ Since
most
of
our
commands
will
actually

      pass...
    ‐ ...
do
we
really
need
to
answer
immediately

      on
the
same
channel?
    ‐ What
about:
“Thank
you
for
your
order,
your

      confirmaDon
e‐mail
will
arrive
shortly”?


                                            ©
Alberto
Brandolini
‐
2010
!             Capturing
user
intent
    ‐   Do
we
really
know
what
the
user
wants
to
do
with

        our
applicaEon?

    ‐   Are
we
really
suppor6ng
our
users?

    ‐   Who’s
carrying
the
complexity
burden?

    ‐   ...
can’t
we
do
anything
smarter
than
just
showing

        raw
data?
        ‐   ...most
of
the
load
olen
turns
out
to
be
simply
useless


                                                             ©
Alberto
Brandolini
‐
2010
!          Commands
!=
EnEEes


    ‐   There’s
not
so
much
in
common




                                        ©
Alberto
Brandolini
‐
2010
!                 Write‐only
model
    ‐   The
domain
model
is
not
used
to
collect
or
to
display

        data
        ‐   Query
oriented
relafonships
between
enffes
no
longer

            needed.

    ‐   The
Domain
Model
is
always
in
a
consistent
state
(from

        Factory
to
Garbage
Collecfon)

    ‐   No
validaEon
on
the
Domain
Model
(commands
are

        validated
before)

    ‐   Tesfng
the
Domain
Model
turns
even
simpler

                                                             ©
Alberto
Brandolini
‐
2010
!              PersisEng
the
model


    ‐   Do
we
really
need
to
persist
all
the
data?

    ‐   Do
we
really
need
to
persist
it
in
Relafonal
Form?
        ‐   (remember,
we’re
not
running
queries...)




                                                       ©
Alberto
Brandolini
‐
2010
!
?
                     UI
               DTO
                          Commands


Remote
facade             Remote
facade
                          ApplicaEon
Services




 Thin
Read
Layer




                                     ORM
!
?
                      UI
                                                            voilà



               DTO
                                           Commands


Remote
facade                              Remote
facade
                                           ApplicaEon
Services




 Thin
Read
Layer




                                                       ORM?

                     Eventually
                       publish
subscribe
voilà

!

                                                                              ORM?
                                    ApplicaEon
Services
                    Remote
facade
         Commands




                                                                                     Eventually
    UI                                                    Sp e publish
subscribe
                                                              cia
                                                                  l i ze
                                                              mo d d a
                    Remote
facade
            DTO




?
                                                                   de l  ta



                                                            Thin
Read
Layer
!
?
                      UI
                                                            voilà



               DTO
                                           Commands


Remote
facade                              Remote
facade
                                           ApplicaEon
Services




 Thin
Read
Layer




                                                       ORM?

                     Eventually
                       publish
subscribe
do e
    voilà                                                       s it




!
                                                          t o b re
                                                                e re a l l y




                                                                                   ORM?
                                    ApplicaEon
Services
                    Remote
facade
                                                                     l at ne e
                                                                         io n      d
                                                                              a l?


         Commands




                                                                                          Eventually
    UI              Remote
facade                                           publish
subscribe
            DTO




?                                                                Thin
Read
Layer
!
?
                      UI
                                                            voilà



               DTO
                                           Commands


Remote
facade                              Remote
facade
                                           ApplicaEon
Services




 Thin
Read
Layer




                                                       ORM?

                     Eventually
                       publish
subscribe
!               A
nice
side
effect
    ‐   ...
fewer
collecfons

    ‐   =>
less
memory
footprint

    ‐   =>
less
Garbage
Collecfon

    ‐   on
some
systems,
the
DM
is
basically
always

        available




                                                   ©
Alberto
Brandolini
‐
2010
The
paper‐based
system



Many
business
pre‐date
computers
TransacEons
are
ocen
NOT
a

business
concern
Data
might
be
stale...
accept
it
ASK
the
Business
Event
Sourcing
!       So
what
is
our
DM
doing?

    ‐   basically
answering
to
self
contained
external

        messages...
        ‐   events
from
the
UI
or
from
external
sources




                                                          ©
Alberto
Brandolini
‐
2010
!   Single
source
of
truth?




                        ©
Alberto
Brandolini
‐
2010
!        Single
source
of
truth?


    ‐   Once
it
used
be
paper...





                                    ©
Alberto
Brandolini
‐
2010
!      Single
source
of
truth?


    ‐Once
it
used
be
paper...

    ‐ now
the
best
candidate
is
Events



                                 ©
Alberto
Brandolini
‐
2010
!
?
                     UI
                                                          voilà

                                         Events




               DTO
Remote
facade                            Remote
facade
                                         ApplicaEon
Services




 Thin
Read
Layer




                                                      ORM
?

                     Events
                     publish
subscribe
!       Do
we
need
state
in
EnEEes?

    ‐   We
have
all
the
needed
informafon
in
the
Event

        Queue
        ‐   SINGLE
SOURCE
of
TRUTH

    ‐   What’s
an
Aggregate?
something
that
changes
its

        state
according
to
events
        ‐   ...according
to
the
current
understanding
of
the
system




                                                            ©
Alberto
Brandolini
‐
2010
!      Aggregates
and
events
                                           OrderCreated
                                                              MAY

                                                                 3
                                                              MAY
                                             ItemsAdded

                             Order
                                                                 5
    Aggregates
   date
                  customer                 PriceUpdated
                                                              MAY

                                                               10
    track

                  amount
                  ...


    Events
and

                  onItemsAdded(...)                           MAY
                                          Order Purchased
                  onPriceUpdated(...)
                  onOrderPurchased(...)                        12
    derive
       ...
                                                              MAY
                                           Order Shipped

    state
from
                                                15
    that                                   OrderDelivered
                                                              MAY

                                                               25
                                                              JUN
                                          PaymentReceived
                                                               26

                                                       ©
Alberto
Brandolini
‐
2010
!                 What
if
we...
    ‐ derive
the
Aggregate
state
from
the
sequence
of

      events
that
occurred
in
the
system?

    ‐ =>
We
can
add
retroacEve
features...
    ‐ =>
We
can
say
YES
to
a
lot
of
interesfng/awkward

      request
for
the
business.

    ‐ =>
Reproducing
bugs?

                                               ©
Alberto
Brandolini
‐
2010
!



    ©
Alberto
Brandolini
‐
2010
The
land
of
opportunity
Loosely
coupled

aggregates
allow
            be>er

simpler
                     scalability
development

Polyglot

persistence
       Painless
        Rewindable

       SOA              applicaEons
Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing
Start
small
you
might
not
need
all
of
it
       each
step
is
an

        improvement
 Even
in
Eny
architectures
      ...challenge
one

   assumpEon
at
a
Eme
Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing
Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing
References

   h>p://groups.google.com/group/dddcqrs

h>p://cqrs.wordpress.com/

h>p://www.infoq.com/interviews/Architecture‐Eric‐Evans‐Interviews‐Greg‐Young

h>p://www.udidahan.com/2009/12/09/clarified‐cqrs/

h>p://www.infoq.com/presentaEons/Command‐Query‐Responsibility‐SegregaEon

h>p://www.infoq.com/presentaEons/SOA‐Business‐Autonomous‐Components

h>p://marEnfowler.com/eaaDev/EventSourcing.html

h>p://skillsma>er.com/podcast/design‐architecture/architectural‐innovaEon‐evenEng‐
event‐sourcing


                                                                      ©
Alberto
Brandolini
‐
2010
Thank
you
alberto.brandolini@avanscoperta.it
  hKp://ziobrando.blogspot.com
         twiKer:
ziobrando

More Related Content

What's hot

モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組みモバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組みMorioImai
 
IoT GatewayとNode-REDの美味しい関係 - OpenBlocks IoTへのNode-REDの実装 -
IoT GatewayとNode-REDの美味しい関係 - OpenBlocks IoTへのNode-REDの実装 -IoT GatewayとNode-REDの美味しい関係 - OpenBlocks IoTへのNode-REDの実装 -
IoT GatewayとNode-REDの美味しい関係 - OpenBlocks IoTへのNode-REDの実装 -nodered_ug_jp
 
Windows 10 の新機能 Azure AD Domain Join とは
Windows 10 の新機能 Azure AD Domain Join とはWindows 10 の新機能 Azure AD Domain Join とは
Windows 10 の新機能 Azure AD Domain Join とはMari Miyakawa
 
新社会人が今すぐ使える、​ExcelでC#を使う方法
新社会人が今すぐ使える、​ExcelでC#を使う方法新社会人が今すぐ使える、​ExcelでC#を使う方法
新社会人が今すぐ使える、​ExcelでC#を使う方法Tetsuo Honda
 
우린 같은 곳을 바라 보고 있나요?
우린 같은 곳을 바라 보고 있나요?우린 같은 곳을 바라 보고 있나요?
우린 같은 곳을 바라 보고 있나요?Arawn Park
 
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台Shengyou Fan
 
A Brief History of UniRx/UniTask, IUniTaskSource in Depth
A Brief History of UniRx/UniTask, IUniTaskSource in DepthA Brief History of UniRx/UniTask, IUniTaskSource in Depth
A Brief History of UniRx/UniTask, IUniTaskSource in DepthYoshifumi Kawai
 
JenkinsとjMeterで負荷テストの自動化
JenkinsとjMeterで負荷テストの自動化JenkinsとjMeterで負荷テストの自動化
JenkinsとjMeterで負荷テストの自動化Satoshi Akama
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021Hiroshi Tokumaru
 
Node-RED導入時の効果的な開発を考える
Node-RED導入時の効果的な開発を考えるNode-RED導入時の効果的な開発を考える
Node-RED導入時の効果的な開発を考えるMakoto SAKAI
 
Microfrontends Monoreops & Trunkbased based
Microfrontends Monoreops & Trunkbased basedMicrofrontends Monoreops & Trunkbased based
Microfrontends Monoreops & Trunkbased basedVinci Rufus
 
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法NGINX, Inc.
 
DiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみたDiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみたtak
 
ドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したことドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したことBIGLOBE Inc.
 
UIbuilderを使ったフロントエンド開発
UIbuilderを使ったフロントエンド開発UIbuilderを使ったフロントエンド開発
UIbuilderを使ったフロントエンド開発Atsushi Kojo
 
大学等におけるAzure AD B2Cを使用したSNS認証の活用
大学等におけるAzure AD B2Cを使用したSNS認証の活用大学等におけるAzure AD B2Cを使用したSNS認証の活用
大学等におけるAzure AD B2Cを使用したSNS認証の活用Naohiro Fujie
 
CI、CD、Automation你還沒準備好!?(Agile Tour Kaohsiung 2017)
CI、CD、Automation你還沒準備好!?(Agile Tour Kaohsiung 2017)CI、CD、Automation你還沒準備好!?(Agile Tour Kaohsiung 2017)
CI、CD、Automation你還沒準備好!?(Agile Tour Kaohsiung 2017)Chen Cheng-Wei
 
Integración Continua con Gitlab + Fastlane
Integración Continua con Gitlab + FastlaneIntegración Continua con Gitlab + Fastlane
Integración Continua con Gitlab + FastlaneJesús Martín Alonso
 
20160526 依存関係逆転の原則
20160526 依存関係逆転の原則20160526 依存関係逆転の原則
20160526 依存関係逆転の原則bonjin6770 Kurosawa
 

What's hot (20)

モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組みモバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
 
IoT GatewayとNode-REDの美味しい関係 - OpenBlocks IoTへのNode-REDの実装 -
IoT GatewayとNode-REDの美味しい関係 - OpenBlocks IoTへのNode-REDの実装 -IoT GatewayとNode-REDの美味しい関係 - OpenBlocks IoTへのNode-REDの実装 -
IoT GatewayとNode-REDの美味しい関係 - OpenBlocks IoTへのNode-REDの実装 -
 
Windows 10 の新機能 Azure AD Domain Join とは
Windows 10 の新機能 Azure AD Domain Join とはWindows 10 の新機能 Azure AD Domain Join とは
Windows 10 の新機能 Azure AD Domain Join とは
 
新社会人が今すぐ使える、​ExcelでC#を使う方法
新社会人が今すぐ使える、​ExcelでC#を使う方法新社会人が今すぐ使える、​ExcelでC#を使う方法
新社会人が今すぐ使える、​ExcelでC#を使う方法
 
우린 같은 곳을 바라 보고 있나요?
우린 같은 곳을 바라 보고 있나요?우린 같은 곳을 바라 보고 있나요?
우린 같은 곳을 바라 보고 있나요?
 
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
[MOPCON 2022] 以 Kotlin Multiplatform 制霸全平台
 
A Brief History of UniRx/UniTask, IUniTaskSource in Depth
A Brief History of UniRx/UniTask, IUniTaskSource in DepthA Brief History of UniRx/UniTask, IUniTaskSource in Depth
A Brief History of UniRx/UniTask, IUniTaskSource in Depth
 
JenkinsとjMeterで負荷テストの自動化
JenkinsとjMeterで負荷テストの自動化JenkinsとjMeterで負荷テストの自動化
JenkinsとjMeterで負荷テストの自動化
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021
 
Node-RED導入時の効果的な開発を考える
Node-RED導入時の効果的な開発を考えるNode-RED導入時の効果的な開発を考える
Node-RED導入時の効果的な開発を考える
 
Microfrontends Monoreops & Trunkbased based
Microfrontends Monoreops & Trunkbased basedMicrofrontends Monoreops & Trunkbased based
Microfrontends Monoreops & Trunkbased based
 
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
 
Using the Splunk Java SDK
Using the Splunk Java SDKUsing the Splunk Java SDK
Using the Splunk Java SDK
 
DiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみたDiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみた
 
ドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したことドメイン駆動設計 失敗したことと成功したこと
ドメイン駆動設計 失敗したことと成功したこと
 
UIbuilderを使ったフロントエンド開発
UIbuilderを使ったフロントエンド開発UIbuilderを使ったフロントエンド開発
UIbuilderを使ったフロントエンド開発
 
大学等におけるAzure AD B2Cを使用したSNS認証の活用
大学等におけるAzure AD B2Cを使用したSNS認証の活用大学等におけるAzure AD B2Cを使用したSNS認証の活用
大学等におけるAzure AD B2Cを使用したSNS認証の活用
 
CI、CD、Automation你還沒準備好!?(Agile Tour Kaohsiung 2017)
CI、CD、Automation你還沒準備好!?(Agile Tour Kaohsiung 2017)CI、CD、Automation你還沒準備好!?(Agile Tour Kaohsiung 2017)
CI、CD、Automation你還沒準備好!?(Agile Tour Kaohsiung 2017)
 
Integración Continua con Gitlab + Fastlane
Integración Continua con Gitlab + FastlaneIntegración Continua con Gitlab + Fastlane
Integración Continua con Gitlab + Fastlane
 
20160526 依存関係逆転の原則
20160526 依存関係逆転の原則20160526 依存関係逆転の原則
20160526 依存関係逆転の原則
 

Viewers also liked

Rethinking Enterprise Software - Brandolini
Rethinking Enterprise Software - BrandoliniRethinking Enterprise Software - Brandolini
Rethinking Enterprise Software - BrandoliniCodemotion
 
Introduction To Domain Driven Design
Introduction To Domain Driven DesignIntroduction To Domain Driven Design
Introduction To Domain Driven DesignPaul Rayner
 
Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)Dennis Traub
 
Strategic design using ddd
Strategic design using dddStrategic design using ddd
Strategic design using dddPaul Rayner
 
Domain Driven Design Up And Running
Domain Driven Design Up And RunningDomain Driven Design Up And Running
Domain Driven Design Up And RunningIASA
 
Secure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best PracticesSecure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best PracticesWebsecurify
 
Domain Driven Design - DDDSydney 2011
Domain Driven Design - DDDSydney 2011Domain Driven Design - DDDSydney 2011
Domain Driven Design - DDDSydney 2011thinkddd
 
Challenges of industry formation
Challenges of industry formationChallenges of industry formation
Challenges of industry formationJeffrey Funk
 
Politica Y Democracia
Politica Y DemocraciaPolitica Y Democracia
Politica Y DemocraciaContinuum HQ
 
Jp purchasing consultancy 2013
Jp purchasing consultancy 2013Jp purchasing consultancy 2013
Jp purchasing consultancy 2013Jan Piet Jacobi
 
Everything you always wanted to know about Distributed databases, at devoxx l...
Everything you always wanted to know about Distributed databases, at devoxx l...Everything you always wanted to know about Distributed databases, at devoxx l...
Everything you always wanted to know about Distributed databases, at devoxx l...javier ramirez
 
1. qué es un amigo
1. qué es un amigo1. qué es un amigo
1. qué es un amigo7-2
 

Viewers also liked (20)

Rethinking Enterprise Software - Brandolini
Rethinking Enterprise Software - BrandoliniRethinking Enterprise Software - Brandolini
Rethinking Enterprise Software - Brandolini
 
Introduction To Domain Driven Design
Introduction To Domain Driven DesignIntroduction To Domain Driven Design
Introduction To Domain Driven Design
 
Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)
 
It's not simple at all
It's not simple at allIt's not simple at all
It's not simple at all
 
Strategic design using ddd
Strategic design using dddStrategic design using ddd
Strategic design using ddd
 
Domain Driven Design Up And Running
Domain Driven Design Up And RunningDomain Driven Design Up And Running
Domain Driven Design Up And Running
 
DDDesign Challenges
DDDesign ChallengesDDDesign Challenges
DDDesign Challenges
 
DDD Dirty Harry style
DDD Dirty Harry styleDDD Dirty Harry style
DDD Dirty Harry style
 
Event sourcing
Event sourcingEvent sourcing
Event sourcing
 
Secure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best PracticesSecure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best Practices
 
Domain Driven Design - DDDSydney 2011
Domain Driven Design - DDDSydney 2011Domain Driven Design - DDDSydney 2011
Domain Driven Design - DDDSydney 2011
 
Event based modeling - eng
Event based modeling - engEvent based modeling - eng
Event based modeling - eng
 
Challenges of industry formation
Challenges of industry formationChallenges of industry formation
Challenges of industry formation
 
Politica Y Democracia
Politica Y DemocraciaPolitica Y Democracia
Politica Y Democracia
 
Jp purchasing consultancy 2013
Jp purchasing consultancy 2013Jp purchasing consultancy 2013
Jp purchasing consultancy 2013
 
Logos-AT presentation
Logos-AT presentationLogos-AT presentation
Logos-AT presentation
 
Everything you always wanted to know about Distributed databases, at devoxx l...
Everything you always wanted to know about Distributed databases, at devoxx l...Everything you always wanted to know about Distributed databases, at devoxx l...
Everything you always wanted to know about Distributed databases, at devoxx l...
 
1. qué es un amigo
1. qué es un amigo1. qué es un amigo
1. qué es un amigo
 
Referat schweizerischer samariterbund
Referat schweizerischer samariterbundReferat schweizerischer samariterbund
Referat schweizerischer samariterbund
 
Francisco lopez reyes01
Francisco lopez reyes01Francisco lopez reyes01
Francisco lopez reyes01
 

Similar to Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing

Building a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one weekBuilding a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one weekDr. Felix Raab
 
Consistent Development Environment with Vagrant and Chef
Consistent Development Environment with Vagrant and ChefConsistent Development Environment with Vagrant and Chef
Consistent Development Environment with Vagrant and ChefGerald Villorente
 
Design patterns
Design patternsDesign patterns
Design patternsnisheesh
 
.NET Architecture for Enterprises
.NET Architecture for Enterprises.NET Architecture for Enterprises
.NET Architecture for EnterprisesWade Wegner
 
StackEngine Problem Space Demo
StackEngine Problem Space DemoStackEngine Problem Space Demo
StackEngine Problem Space DemoBoyd Hemphill
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)guestebde
 
Is Serverless The New Swiss Cheese? - AWS Seattle User Group
Is Serverless The New Swiss Cheese? - AWS Seattle User GroupIs Serverless The New Swiss Cheese? - AWS Seattle User Group
Is Serverless The New Swiss Cheese? - AWS Seattle User GroupChase Douglas
 
Agile Development in .NET
Agile Development in .NETAgile Development in .NET
Agile Development in .NETdanhermes
 
10 Tips for Configuring Your Builds with Bamboo Specs
10 Tips for Configuring Your Builds with Bamboo Specs10 Tips for Configuring Your Builds with Bamboo Specs
10 Tips for Configuring Your Builds with Bamboo SpecsAtlassian
 
Latest trends in information technology
Latest trends in information technologyLatest trends in information technology
Latest trends in information technologyEldos Kuriakose
 
Better and Faster: A Journey Toward Clean Code and Enjoyment
Better and Faster: A Journey Toward Clean Code and EnjoymentBetter and Faster: A Journey Toward Clean Code and Enjoyment
Better and Faster: A Journey Toward Clean Code and EnjoymentChris Holland
 
No more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureNo more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureMarco Parenzan
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with BlackfireMarko Mitranić
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the bookCyrille Martraire
 
IPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIIPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIRobert Lemke
 
Angular js mobile jsday 2014 - Verona 14 may
Angular js mobile   jsday 2014 - Verona 14 mayAngular js mobile   jsday 2014 - Verona 14 may
Angular js mobile jsday 2014 - Verona 14 mayLuciano Amodio
 

Similar to Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing (20)

Building a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one weekBuilding a full-stack app with Golang and Google Cloud Platform in one week
Building a full-stack app with Golang and Google Cloud Platform in one week
 
Pie for ai
Pie for aiPie for ai
Pie for ai
 
Consistent Development Environment with Vagrant and Chef
Consistent Development Environment with Vagrant and ChefConsistent Development Environment with Vagrant and Chef
Consistent Development Environment with Vagrant and Chef
 
10 Ways To Improve Your Code
10 Ways To Improve Your Code10 Ways To Improve Your Code
10 Ways To Improve Your Code
 
Design patterns
Design patternsDesign patterns
Design patterns
 
.NET Architecture for Enterprises
.NET Architecture for Enterprises.NET Architecture for Enterprises
.NET Architecture for Enterprises
 
StackEngine Problem Space Demo
StackEngine Problem Space DemoStackEngine Problem Space Demo
StackEngine Problem Space Demo
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
 
Is Serverless The New Swiss Cheese? - AWS Seattle User Group
Is Serverless The New Swiss Cheese? - AWS Seattle User GroupIs Serverless The New Swiss Cheese? - AWS Seattle User Group
Is Serverless The New Swiss Cheese? - AWS Seattle User Group
 
Agile Development in .NET
Agile Development in .NETAgile Development in .NET
Agile Development in .NET
 
The Modlet Pattern
The Modlet PatternThe Modlet Pattern
The Modlet Pattern
 
10 Tips for Configuring Your Builds with Bamboo Specs
10 Tips for Configuring Your Builds with Bamboo Specs10 Tips for Configuring Your Builds with Bamboo Specs
10 Tips for Configuring Your Builds with Bamboo Specs
 
Latest trends in information technology
Latest trends in information technologyLatest trends in information technology
Latest trends in information technology
 
Better and Faster: A Journey Toward Clean Code and Enjoyment
Better and Faster: A Journey Toward Clean Code and EnjoymentBetter and Faster: A Journey Toward Clean Code and Enjoyment
Better and Faster: A Journey Toward Clean Code and Enjoyment
 
No more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureNo more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and Azure
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the book
 
IPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIIPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DI
 
Angular js mobile jsday 2014 - Verona 14 may
Angular js mobile   jsday 2014 - Verona 14 mayAngular js mobile   jsday 2014 - Verona 14 may
Angular js mobile jsday 2014 - Verona 14 may
 

More from Alberto Brandolini

L'illusione dell'ortogonalità
L'illusione dell'ortogonalitàL'illusione dell'ortogonalità
L'illusione dell'ortogonalitàAlberto Brandolini
 
Redesigning everything ITARC Stockholm 2021
Redesigning everything ITARC Stockholm 2021Redesigning everything ITARC Stockholm 2021
Redesigning everything ITARC Stockholm 2021Alberto Brandolini
 
Redesigning everything (avanscoperta meeutp edition)
Redesigning everything (avanscoperta meeutp edition)Redesigning everything (avanscoperta meeutp edition)
Redesigning everything (avanscoperta meeutp edition)Alberto Brandolini
 
Software design as a cooperative game with EventStorming
Software design as a cooperative game with EventStormingSoftware design as a cooperative game with EventStorming
Software design as a cooperative game with EventStormingAlberto Brandolini
 
Reshaping enterrprise software
Reshaping enterrprise softwareReshaping enterrprise software
Reshaping enterrprise softwareAlberto Brandolini
 
Guerrilla portfolio management
Guerrilla portfolio managementGuerrilla portfolio management
Guerrilla portfolio managementAlberto Brandolini
 
Idea stickies green bar - Wroclaw edition
Idea stickies green bar - Wroclaw editionIdea stickies green bar - Wroclaw edition
Idea stickies green bar - Wroclaw editionAlberto Brandolini
 
Why do all my ddd apps look the same - Vienna 2014
Why do all my ddd apps look the same - Vienna 2014Why do all my ddd apps look the same - Vienna 2014
Why do all my ddd apps look the same - Vienna 2014Alberto Brandolini
 

More from Alberto Brandolini (20)

L'illusione dell'ortogonalità
L'illusione dell'ortogonalitàL'illusione dell'ortogonalità
L'illusione dell'ortogonalità
 
Redesigning everything ITARC Stockholm 2021
Redesigning everything ITARC Stockholm 2021Redesigning everything ITARC Stockholm 2021
Redesigning everything ITARC Stockholm 2021
 
What lies beneath
What lies beneathWhat lies beneath
What lies beneath
 
Redesigning everything (avanscoperta meeutp edition)
Redesigning everything (avanscoperta meeutp edition)Redesigning everything (avanscoperta meeutp edition)
Redesigning everything (avanscoperta meeutp edition)
 
Extreme DDD modelling
Extreme DDD modellingExtreme DDD modelling
Extreme DDD modelling
 
The gordian knot
The gordian knotThe gordian knot
The gordian knot
 
Software design as a cooperative game with EventStorming
Software design as a cooperative game with EventStormingSoftware design as a cooperative game with EventStorming
Software design as a cooperative game with EventStorming
 
La fatina dei denti
La fatina dei dentiLa fatina dei denti
La fatina dei denti
 
50.000 orange stickies later
50.000 orange stickies later50.000 orange stickies later
50.000 orange stickies later
 
The alignment
The alignmentThe alignment
The alignment
 
Chasing elephants
Chasing elephantsChasing elephants
Chasing elephants
 
Transactions redefined
Transactions redefinedTransactions redefined
Transactions redefined
 
Optimized for what
Optimized for whatOptimized for what
Optimized for what
 
Reshaping enterrprise software
Reshaping enterrprise softwareReshaping enterrprise software
Reshaping enterrprise software
 
Guerrilla portfolio management
Guerrilla portfolio managementGuerrilla portfolio management
Guerrilla portfolio management
 
The precision blade
The precision bladeThe precision blade
The precision blade
 
Idea stickies green bar - Wroclaw edition
Idea stickies green bar - Wroclaw editionIdea stickies green bar - Wroclaw edition
Idea stickies green bar - Wroclaw edition
 
Why do all my ddd apps look the same - Vienna 2014
Why do all my ddd apps look the same - Vienna 2014Why do all my ddd apps look the same - Vienna 2014
Why do all my ddd apps look the same - Vienna 2014
 
Managing debt remastered
Managing debt remasteredManaging debt remastered
Managing debt remastered
 
The sweet spot
The sweet spotThe sweet spot
The sweet spot
 

Recently uploaded

Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Spring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdfSpring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdfAnna Loughnan Colquhoun
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.francesco barbera
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 

Recently uploaded (20)

Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Spring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdfSpring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdf
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 

Loosely Coupled Complexity - Unleash the power of your Domain Model with Command Query Responsibility Segregation and Event Sourcing

Editor's Notes

  1. And that&amp;#x2019;s the company I started one year ago.
  2. Disclaimer: this is second-hand talk. 99% of the ideas come from these three guys. In the last couple of years a little revolution has being going on in the DDD community: Udi Dahan (left) and Greg Young (right) have brought new ideas in the DDD landscape.
  3. Ok, let&apos;s start from a familiar architecture, what&apos;s wrong with that?
  4. Ok, if that&amp;#x2019;s the answer... If you really like that and think that&amp;#x2019;s the best possible world... then I don&amp;#x2019;t have so much to tell you.
  5. On the other hand, if you really think about it, there are a few things in your familiar architecture that you&amp;#x2019;ve been probably too used to. Enough to forget that there might be a different way.
  6. Let&amp;#x2019;s try again, with a clear mind.
  7. Here are some of the things we might not like.
  8. Here are some of the things we might not like.
  9. Here are some of the things we might not like.
  10. Here are some of the things we might not like.
  11. Here are some of the things we might not like.
  12. Here are some of the things we might not like.
  13. And here are some of the questions we might ask ourselves
  14. And here are some of the questions we might ask ourselves
  15. And here are some of the questions we might ask ourselves
  16. And here are some of the questions we might ask ourselves
  17. And here are some of the questions we might ask ourselves
  18. And here are some of the questions we might ask ourselves
  19. Ok, let&amp;#x2019;s start from the anaemic domain model: in the picture red is where the logic is. As you might see, there&amp;#x2019;s not so mouch in the Order class...
  20. How did we get there? Well sometimes it&amp;#x2019;s just a matter of features that came for free, like a tool that allows you to reverse engineering your database to create domain classes.
  21. Ok, but anaemic domain model is probably the dominant pattern throughout the world, so it must have some advantages: let&amp;#x2019;s dig into them.
  22. Ok, but anaemic domain model is probably the dominant pattern throughout the world, so it must have some advantages: let&amp;#x2019;s dig into them.
  23. Ok, but anaemic domain model is probably the dominant pattern throughout the world, so it must have some advantages: let&amp;#x2019;s dig into them.
  24. Let&amp;#x2019;s look at the drawbacks instead... in two words it provides all the architetural complexity of an OOP system with the advantages in maintenance of a procedural one. :-P
  25. Let&amp;#x2019;s look at the drawbacks instead... in two words it provides all the architetural complexity of an OOP system with the advantages in maintenance of a procedural one. :-P
  26. Let&amp;#x2019;s look at the drawbacks instead... in two words it provides all the architetural complexity of an OOP system with the advantages in maintenance of a procedural one. :-P
  27. Let&amp;#x2019;s look at the drawbacks instead... in two words it provides all the architetural complexity of an OOP system with the advantages in maintenance of a procedural one. :-P
  28. So what should we do instead?
  29. So what should we do instead?
  30. So what should we do instead?
  31. So what should we do instead?
  32. So what should we do instead?
  33. So what should we do instead?
  34. So what should we do instead?
  35. So what should we do instead?
  36. I think this is a really sensible resolution :-)
  37. ... you got the point ;-) Let&amp;#x2019;s try to be a little more constructive
  38. For example, Mr. Eric Evans has something really interesting to say about how should we implement a Domain Model:
  39. For example, Mr. Eric Evans has something really interesting to say about how should we implement a Domain Model:
  40. For example, Mr. Eric Evans has something really interesting to say about how should we implement a Domain Model:
  41. For example, Mr. Eric Evans has something really interesting to say about how should we implement a Domain Model:
  42. For example, Mr. Eric Evans has something really interesting to say about how should we implement a Domain Model:
  43. What does it mean to &amp;#x201C;put behaviour in the domain model&amp;#x201D;? Here is our starting point: all the logic is in the service class.
  44. In a &amp;#x201C;Rich&amp;#x201D; Domain Model (I really don&amp;#x2019;t know why is Rich vs Anaemic, maybe &amp;#x201C;bloody domain model&amp;#x201D; or &amp;#x201C;poor domain model&amp;#x201D; weren&amp;#x2019;t ok for the job) le logic is &amp;#x201C;where it belongs&amp;#x201D; according to Single Responsibility Principle (Martin) or Information Expert (Larman). It&amp;#x2019;s not spread equally... Customer doesn&amp;#x2019;t do much, while Money for example looks like a pure data type, but has a lot of math-related behaviour in it.
  45. Interestingly, TDD and DDD form a perfect match: DDD needs TDD for many of the key practices, while TDD naturally enforces DDD-like coding styles. It&amp;#x2019;s just perfect.
  46. The next key DDD building block is Aggregates. The Domain Model isn&amp;#x2019;t flat. Some links are stronger than others (and UML doesn&amp;#x2019;t really help much in rendering it). If we start considering consistency and behaviour as the primary drivers for modeling our domain we&amp;#x2019;ll end up with something quite different from a 1-1 projection of the data model.
  47. The next key DDD building block is Aggregates. The Domain Model isn&amp;#x2019;t flat. Some links are stronger than others (and UML doesn&amp;#x2019;t really help much in rendering it). If we start considering consistency and behaviour as the primary drivers for modeling our domain we&amp;#x2019;ll end up with something quite different from a 1-1 projection of the data model.
  48. For example, in this case we&amp;#x2019;ll notice some duplication, related to customer. But lifecycles of the customer and of the order are different. If a customer moves, we don&amp;#x2019;t want to have all of our past orders changed, at the same time if an order needs to be canceled, we don&amp;#x2019;t want the user to get down the sink as well. A little duplication is what allows aggregate lifecycles to be independent.
  49. Some data-driven analyst are probably really good in spotting these problems just out of their experience.
  50. But really, this part of modeling is our everyday work, and should be easy as walking back home in a sunny day.
  51. Shouldn&amp;#x2019;t really have to rely on the experience of some rarely available guy that knows all the traps and hidden perils of data modeling.
  52. But here&amp;#x2019;s something to think about: this modeling style enforces loose coupling between aggregates. As a side effect, queries tend to be a lot simpler and focused. In many situations, this opens the door for some alternative persistence strategy.
  53. Ok, so let&amp;#x2019;s see how DDD can improve our application architecture.
  54. Not so many things are happening at the service layer, just basic coordination. Bounded contexts are enforced, and aggregate boundaries within them. But other portions of the architecture don&amp;#x2019;t change that much. ... is there anything else that we can do?
  55. Not so many things are happening at the service layer, just basic coordination. Bounded contexts are enforced, and aggregate boundaries within them. But other portions of the architecture don&amp;#x2019;t change that much. ... is there anything else that we can do?
  56. Not so many things are happening at the service layer, just basic coordination. Bounded contexts are enforced, and aggregate boundaries within them. But other portions of the architecture don&amp;#x2019;t change that much. ... is there anything else that we can do?
  57. Not so many things are happening at the service layer, just basic coordination. Bounded contexts are enforced, and aggregate boundaries within them. But other portions of the architecture don&amp;#x2019;t change that much. ... is there anything else that we can do?
  58. Not so many things are happening at the service layer, just basic coordination. Bounded contexts are enforced, and aggregate boundaries within them. But other portions of the architecture don&amp;#x2019;t change that much. ... is there anything else that we can do?
  59. Not so many things are happening at the service layer, just basic coordination. Bounded contexts are enforced, and aggregate boundaries within them. But other portions of the architecture don&amp;#x2019;t change that much. ... is there anything else that we can do?
  60. Using DO in the UI seemed like a good idea (I confess I hated the abuse of DTOs so much that I tried it myself), but then you run into objects which are potentially inconsistent. A common solution is to have every DO in 2 possible states: valid and invalid, and valid state must be enforced before any business method is invoked on the object. So why not make it mandatory, with aspects or template method pattern. Why not make this solution available/mandatory to all the domain classes? ... well ...No.
  61. Using DO in the UI seemed like a good idea (I confess I hated the abuse of DTOs so much that I tried it myself), but then you run into objects which are potentially inconsistent. A common solution is to have every DO in 2 possible states: valid and invalid, and valid state must be enforced before any business method is invoked on the object. So why not make it mandatory, with aspects or template method pattern. Why not make this solution available/mandatory to all the domain classes? ... well ...No.
  62. Using DO in the UI seemed like a good idea (I confess I hated the abuse of DTOs so much that I tried it myself), but then you run into objects which are potentially inconsistent. A common solution is to have every DO in 2 possible states: valid and invalid, and valid state must be enforced before any business method is invoked on the object. So why not make it mandatory, with aspects or template method pattern. Why not make this solution available/mandatory to all the domain classes? ... well ...No.
  63. Using DO in the UI seemed like a good idea (I confess I hated the abuse of DTOs so much that I tried it myself), but then you run into objects which are potentially inconsistent. A common solution is to have every DO in 2 possible states: valid and invalid, and valid state must be enforced before any business method is invoked on the object. So why not make it mandatory, with aspects or template method pattern. Why not make this solution available/mandatory to all the domain classes? ... well ...No.
  64. Using DO in the UI seemed like a good idea (I confess I hated the abuse of DTOs so much that I tried it myself), but then you run into objects which are potentially inconsistent. A common solution is to have every DO in 2 possible states: valid and invalid, and valid state must be enforced before any business method is invoked on the object. So why not make it mandatory, with aspects or template method pattern. Why not make this solution available/mandatory to all the domain classes? ... well ...No.
  65. Using DO in the UI seemed like a good idea (I confess I hated the abuse of DTOs so much that I tried it myself), but then you run into objects which are potentially inconsistent. A common solution is to have every DO in 2 possible states: valid and invalid, and valid state must be enforced before any business method is invoked on the object. So why not make it mandatory, with aspects or template method pattern. Why not make this solution available/mandatory to all the domain classes? ... well ...No.
  66. Ok, question for the audience: two Stories, hitting different portions of the application, triggered by the same external event. How would you model them? I must admit that in a similar situation I spent some time wondering: &amp;#x201C;Is it better to have order.purchase(customer, ...) or customer.purchase(order, ...)?&amp;#x201D; or many other variation on the theme.
  67. That&amp;#x2019;s the very specific Greg Young&amp;#x2019;s definition. I like it.
  68. Domain Events as a communication means between aggregates really simplify things a lot, even at the conceptual level. - Do they really belong to the same transaction? - Would you want the order to roll-bak if you are unable to process the discount for the next order bu the same customer? ... but really, how the two things should be related, is a business choice! We just have more and more possibilites in our arsenal.
  69. There&amp;#x2019;s been a never ending debate in the SOA community (and many dollars and euros wasted) about &amp;#x201C;service granularity&amp;#x201D;. A good read of the blue book could have helped a lot, the solution was already there...
  70. Let&amp;#x2019;s start to bite something bigger
  71. Which one is the right shoe for you? Well ...it depends :-) each one serves a particular use. We change shoes according to what we want to do.
  72. So why should we have only one architecture?
  73. CQS existed before DDD and was part of the DDD toolkit collection, basically at the class design level. It really enhances scalability and maintainability.
  74. But CQRS promotes the same concept at the architectural level. Commands and quesries have different needs.
  75. When we ask, there is generally no behavior involved. Just data.
  76. So one first step might be to evolve the &amp;#x201C;classical&amp;#x201D; DDD architecture...
  77. ... into something more specialized: the domain model is used only in the command side, while the query side is definitely thinner.
  78. Let&amp;#x2019;s dive into the query side. Udi Dahan pointed out that sometimes the biggest source of optimization is to have a look at what the users are really doing: capturing user intent might surprise you.
  79. Also, the fact that we can sometimes provide real time data, doesn&amp;#x2019;t really mean that we must alway provide them. Most of the time a little of delay is absolutely acceptable. Sometimes requirements are not even coming from the business, it&amp;#x2019;s just IT people showing off...
  80. Wow, that is a kind of shock for DDD zealots. Objects are there for the behavior. The domain model is an efficient way to represent behavior. If there&amp;#x2019;s no behavior then there&amp;#x2019;s no real need for objects as well. Did I mention that we could get rid of some of our assumptions? ;-)
  81. How would you optimize a Query Only architecture? - we could just use some of the tools vendor provide us to manage straight data. - we could have a specialized model for the view, with different table structure, eventually updated by a background process. - ... and many other cool ideas!
  82. Also, even stale data could be a great help in managing pleliminary validation of the commands. We can still perform validation on the presentation layer and make sure that most of the commands simply won&amp;#x2019;t fail.
  83. Let&amp;#x2019;s see the consequences on the command side. More trust means less burden, and a little less synchronicity, meaning less load.
  84. Commands are a lot closer to user intent. It&amp;#x2019;s not just editing data. Is ding it with a purpose.
  85. ... so why should show entities in the presentation layer?
  86. The domain model turns out to become even simpler: it&amp;#x2019;s write only. Classes are always in a consistent state and a command issued to the class, triggers an action and/or a state transition. Just that.
  87. Let&amp;#x2019;s get back to the gorilla... what do we need to persist? and How? What&amp;#x2019;s the most efficient strategy for persisting a domain model?
  88. Let&amp;#x2019;s shake things a little bit more :-)
  89. The next little revolution is to have 2 different persistence storage: one optimized fopr working with the domain model? the other one optimized for the Query Only model. The two are eventually consistent. Just think about how many locking issues are blown away by separating the two...
  90. The next little revolution is to have 2 different persistence storage: one optimized fopr working with the domain model? the other one optimized for the Query Only model. The two are eventually consistent. Just think about how many locking issues are blown away by separating the two...
  91. The next little revolution is to have 2 different persistence storage: one optimized fopr working with the domain model? the other one optimized for the Query Only model. The two are eventually consistent. Just think about how many locking issues are blown away by separating the two...
  92. The next little revolution is to have 2 different persistence storage: one optimized fopr working with the domain model? the other one optimized for the Query Only model. The two are eventually consistent. Just think about how many locking issues are blown away by separating the two...
  93. Objects are tiny now. No collections, no mapping. Intersting things might happen...
  94. Surprisingly, but Udi Dahan and Greg Young in their speeches at last DDDx put the paper-based system at the center of their concern. If a complex system could work without computers ...there must be a reason for that. Some times computers just loeded the systems with more unnecessary complexity.
  95. Let&amp;#x2019;s now face another assumption...
  96. You might also want to have a look to Alistair Cockburn exagonal architecture, you might find quite a few similarities in the problem setting.
  97. There might be inconsistencies in the data or between the data and the paper. In many system (especially those data-entry based) the paper used to be the Single Source of Truth, but larger integrated systems Events are probably a better candidate.
  98. There might be inconsistencies in the data or between the data and the paper. In many system (especially those data-entry based) the paper used to be the Single Source of Truth, but larger integrated systems Events are probably a better candidate.
  99. So Events are passing from the command side to the Query side in a publish-subscribe fashion, they need to ba made persistent as well
  100. In such a model, what&amp;#x2019;s the best way to model an entity? Our aggregates are receiveng entities and updating state, can we achieve the same result with a more efficient strategy?
  101. The Specification pattern turns out really useful for that, but also note that entities are a little less mutable than they used to be.
  102. This might be a blast! Think about the amount of opportunities
  103. Ok, this one is a picture I really like, and reuse over and over... DDD has a lot to do with learning. But Event sourcing is a learning tool as well! Only, stop assuming that Business People know everything about the business, there&amp;#x2019;s a lot more to learn for them also! Why not doing it together?
  104. Surprisingly, googling &amp;#x201C;land of opportunity&amp;#x201D; leads to Arkansas. But I like this picture... :-)
  105. One important lesson: you don&amp;#x2019;t need all of this at once. But every little step brings an improvement, and it&amp;#x2019;s worth taking.
  106. despite how cool this stuff looks ...be pragmatic.
  107. Ok, time for some useful link