SlideShare a Scribd company logo
Stuff About CQRS

       Jak Charlton
            @JakCharlton
        jak@thinkddd.com
Disclaimer:
This Isn’t All About
Command Query
  Responsibility
   Segregation
does anyone here even
 know what CQRS is
 anyway, or were the
  other sessions full?
Another Disclaimer:
There won’t be any code,
    I don’t do code,
      just opinions
My Objective Today
My Objective Today
is to Make You Think
My Objective Today
is to Make You Think
 “Maybe There Is
  A Better Way?”
Why Don’t We Talk Like
“Normal” People Do?
Why Don’t We Talk Like
“Normal” People Do?
Developers are usually
techy
Why Don’t We Talk Like
“Normal” People Do?
Developers are usually
techy
Business people usually
don’t understand “techy”
Why Don’t We Talk Like
“Normal” People Do?
Developers are usually
techy
Business people usually
don’t understand “techy”
So why do we try to
make them think like we
do?
Why Does Language
 Matter So Much?
Why Does Language
    Matter So Much?
Without language, we
cannot convey meaning
Why Does Language
     Matter So Much?
Without language, we
cannot convey meaning
But when we talk
different languages, we
lose in the translation
Why Does Language
     Matter So Much?
Without language, we
cannot convey meaning
But when we talk
different languages, we
lose in the translation
Let’s agree on one
How Do “Normal” People
    See the World?
How Do “Normal” People
    See the World?
People don’t think in
terms of “data”
How Do “Normal” People
    See the World?
People don’t think in
terms of “data”
People think “tasks”
How Do “Normal” People
    See the World?
People don’t think in
terms of “data”
People think “tasks”
People are objective
based, only computers
work on data
Otherwise Known As
   “Grid Abuse”
Otherwise Known As
     “Grid Abuse”
Grids are a UI problem
created by developers
Otherwise Known As
      “Grid Abuse”
Grids are a UI problem
created by developers
People don’t see
information in columns
and rows
Otherwise Known As
      “Grid Abuse”
Grids are a UI problem
created by developers
People don’t see
information in columns
and rows
Even Excel doesn’t force
you to think that way
If People Don’t Think In Grids,
 Why Force Data Into Grids?
If People Don’t Think In Grids,
 Why Force Data Into Grids?
 Developers are ingrained
 with RDBMS Rows and
 Columns
If People Don’t Think In Grids,
 Why Force Data Into Grids?
 Developers are ingrained
 with RDBMS Rows and
 Columns
 Business information
 doesn’t come in rows and
 columns
If People Don’t Think In Grids,
 Why Force Data Into Grids?
 Developers are ingrained
 with RDBMS Rows and
 Columns
 Business information
 doesn’t come in rows and
 columns
 We forced them to store
 and use it that way
Thinking About
NoSQL Databases
Thinking About
     NoSQL Databases
If users think about
things like
“my documents” maybe
we should just store
stuff that way?
Thinking About
      NoSQL Databases
If users think about
things like
“my documents” maybe
we should just store
stuff that way?
NoSQL databases let us
concentrate on what to
store, not how
Quick Summary
Quick Summary

People need to
communicate
Quick Summary

People need to
communicate
People think Tasks
Quick Summary

People need to
communicate
People think Tasks
People think “stuff” or
“documents” or “things”
What Does This Have to Do
     With CQRS ???
What Does This Have to Do
     With CQRS ???
Not much ...
What Does This Have to Do
     With CQRS ???
Not much ...
Yet...
What Does This Have to Do
     With CQRS ???
Not much ...
Yet...
One more step...
now we get a bit
techy
CAP Theory
CAP Theory
Consistency: The client perceives that a set of
operations has occurred all at once.
CAP Theory
Consistency: The client perceives that a set of
operations has occurred all at once.
Availability: Every operation must terminate in
an intended response.
CAP Theory
Consistency: The client perceives that a set of
operations has occurred all at once.
Availability: Every operation must terminate in
an intended response.
Partition tolerance: Operations will complete,
even if individual components are unavailable.
CAP Theory
Consistency: The client perceives that a set of
operations has occurred all at once.
Availability: Every operation must terminate in
an intended response.
Partition tolerance: Operations will complete,
even if individual components are unavailable.
You cannot have all three
ACID
ACID

Atomic, Consistent, Isolated, Durable
ACID

Atomic, Consistent, Isolated, Durable

In CAP Theory terms ACID gives you:
ACID

Atomic, Consistent, Isolated, Durable

In CAP Theory terms ACID gives you:
Consistency and Availability
ACID

Atomic, Consistent, Isolated, Durable

In CAP Theory terms ACID gives you:
Consistency and Availability
But Sacrifices Partition Tolerance
BASE
BASE

Basically Available, Soft state, Eventually
consistent
BASE

Basically Available, Soft state, Eventually
consistent
In CAP Theory BASE gives you:
BASE

Basically Available, Soft state, Eventually
consistent
In CAP Theory BASE gives you:
Availability and Partition Tolerance
BASE

Basically Available, Soft state, Eventually
consistent
In CAP Theory BASE gives you:
Availability and Partition Tolerance
But Sacrifices Consistency
Command Query
Responsibility Segregation
Command Query
Responsibility Segregation
Bertrand Meyer principle of CQS:
every method should either be a command that
performs an action, or a query that returns data to
the caller
Command Query
Responsibility Segregation
Bertrand Meyer principle of CQS:
every method should either be a command that
performs an action, or a��query that returns data to
the caller
At an architectural level this means:
either issue commands, or issue queries, but
never both
Command Query
Responsibility Segregation
Bertrand Meyer principle of CQS:
every method should either be a command that
performs an action, or a query that returns data to
the caller
At an architectural level this means:
either issue commands, or issue queries, but
never both
And, query from a separate source from your
domain commands
CQRS and BASE
CQRS and BASE
CQRS gives us BASE at an architectural
level
CQRS and BASE
CQRS gives us BASE at an architectural
level
We may not always be consistent
CQRS and BASE
CQRS gives us BASE at an architectural
level
We may not always be consistent
But most data isn’t consistent in reality
anyway, we just think it is
CQRS and BASE
CQRS gives us BASE at an architectural
level
We may not always be consistent
But most data isn’t consistent in reality
anyway, we just think it is
Eventually our architecture will be
consistent
CQRS in a Picture
                                 Client


             Command



                                                                    Queries
        Domain                            Event Handlers
                                           Event Handlers
                       Publish                                      (synchronous no bus)


             Persist                       Update




Domain Persistence                                          Read Model
CQRS in a Simpler Picture

    Domain              Events             Read Model
             Co




                                      Os
               m
              m




                                    DT
               an
                   ds




                           Client
What Did All That Beginning
Stuff Have to Do With CQRS ???
What Did All That Beginning
Stuff Have to Do With CQRS ???
 The way people think matters
What Did All That Beginning
Stuff Have to Do With CQRS ???
 The way people think matters
 CQRS splits actions from queries
What Did All That Beginning
Stuff Have to Do With CQRS ???
 The way people think matters
 CQRS splits actions from queries
 And people think about asking
 people to do things or asking
 them for information
Benefits of CQRS
Benefits of CQRS
Simplified Architecture
Benefits of CQRS
Simplified Architecture
Closer Alignment with Users
Benefits of CQRS
Simplified Architecture
Closer Alignment with Users
Performance
Benefits of CQRS
Simplified Architecture
Closer Alignment with Users
Performance
Scalability
Benefits of CQRS
Simplified Architecture
Closer Alignment with Users
Performance
Scalability
Eliminates a leaky abstraction
My Objective Today
was to Make You Think
My Objective Today
was to Make You Think
 “Maybe There Is A
   Better Way?”
My Objective Today
was to Make You Think
 “Maybe There Is A
   Better Way?”
I Hope I Succeeded
DeveloperDeveloperDeveloper! Events would not be possible
      With out the generous support from our sponsors…
     We would like to thank the following for their support:

More Related Content

Stuff About CQRS

Editor's Notes

  1. CQRS is a technical approach that solves a lot of problems But it requires something more, a better way of working So this presentation is more about how to think differently
  2. You don’t ring your bank and say “I want you to view my customer record, edit the address fields and save it to your database” You do call your bank and say “I would like to change my correspondence address”
  3. You don’t ring your bank and say “I want you to view my customer record, edit the address fields and save it to your database” You do call your bank and say “I would like to change my correspondence address”
  4. You don’t ring your bank and say “I want you to view my customer record, edit the address fields and save it to your database” You do call your bank and say “I would like to change my correspondence address”
  5. Users think of lists of information ... my tweets, my bank account transaction, my facebook wall, my auctions, my Documents This abuse extends to many areas of a business - we have abused users into talking our way, not theirs
  6. Users think of lists of information ... my tweets, my bank account transaction, my facebook wall, my auctions, my Documents This abuse extends to many areas of a business - we have abused users into talking our way, not theirs
  7. Users think of lists of information ... my tweets, my bank account transaction, my facebook wall, my auctions, my Documents This abuse extends to many areas of a business - we have abused users into talking our way, not theirs
  8. Store data in a loose fashion Only store what you need In the format you want
  9. Store data in a loose fashion Only store what you need In the format you want