Top Banner
Command Query Responsibility Segregation In Babysteps @talboomerik
49
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cqrs in babysteps

Command Query Responsibility Segregation

In Babysteps

@talboomerik

Page 2: Cqrs in babysteps

Founder of Software craftsmanship guild Belgium

@talboomerik

Page 3: Cqrs in babysteps

Thanks to

@yreynhout @alastairs

@sandromancuso @adibolb

Page 4: Cqrs in babysteps

And a special thanks to@StefanBilliet

Page 5: Cqrs in babysteps

ENTRY LEVEL INTRODUCTION

@talboomerik

Page 6: Cqrs in babysteps

WHERE DID IT COME FROM?A little history

@talboomerik

Page 7: Cqrs in babysteps

Command and Query Separation

It states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both. In other words, asking a question should not change the answer. More formally, methods should return a value only if they are referentially transparent and hence possess no side effects.

Wikipedia - Bertrand Meyer

@talboomerik

Page 8: Cqrs in babysteps

IF YOU HAVE A RETURN TYPE, YOU SHOULD NOT CHANGE STATE

Query

@talboomerik

Page 9: Cqrs in babysteps

IF YOU CHANGE STATE YOUR RETURN TYPE SHOULD BE VOID

Command

@talboomerik

Page 10: Cqrs in babysteps

BASICALLY CQRS IS CQS SPLIT IN DIFFERENT OBJECTS

The simple definition

@talboomerik

Page 11: Cqrs in babysteps

QUERY OBJECTS OVER QUERY SERVICES / REPOSITORIES

http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/@talboomerik

Page 12: Cqrs in babysteps

WHAT IS THIS ALL ABOUT?What’s the fuss

@talboomerik

Page 13: Cqrs in babysteps

YOUR TYPICAL N-TIER ARCHITECTURE

@talboomerik

Page 14: Cqrs in babysteps

http:

//co

deof

rob.

com

/ent

ries/

cqrs

-is-t

oo-c

ompl

icat

ed.h

tml

Page 15: Cqrs in babysteps

REMEMBER WHAT UNCLE SANDRO SHOWED US?

Page 16: Cqrs in babysteps
Page 17: Cqrs in babysteps

FEELS FAMILIAR?

@talboomerik

Page 18: Cqrs in babysteps

WE CAN MAKE THIS SIMPLER

@talboomerik

Page 19: Cqrs in babysteps

http:

//co

deof

rob.

com

/ent

ries/

cqrs

-is-t

oo-c

ompl

icat

ed.h

tml

Page 20: Cqrs in babysteps

REMOVING QUERIES FROM YOUR DOMAIN MODEL

@talboomerik

@sandromancuso

Page 21: Cqrs in babysteps

@sandromancuso

Page 22: Cqrs in babysteps

LET’S TAKE IT ONE STEP FURTHERIf needed

@talboomerik

Page 23: Cqrs in babysteps

http:

//co

deof

rob.

com

/ent

ries/

cqrs

-is-t

oo-c

ompl

icat

ed.h

tml

Page 24: Cqrs in babysteps

OR EVEN FURTHERIf applicable

@talboomerik

Page 25: Cqrs in babysteps

http:

//co

deof

rob.

com

/ent

ries/

cqrs

-is-t

oo-c

ompl

icat

ed.h

tml

Page 26: Cqrs in babysteps

HOW TO SYNCHRONIZE READ/WRITE?

@talboomerik

Page 27: Cqrs in babysteps

DOMAIN EVENTSA cool pattern

@talboomerik

Page 28: Cqrs in babysteps

LET’S HAVE A LOOK AT SOME CODE

@talboomerik

Page 29: Cqrs in babysteps

TAKING IT TO ANOTHER LEVELEvent sourcing

@talboomerik

Page 30: Cqrs in babysteps

FOCUSING ON BEHAVIOR INSTEAD OF STATE

@talboomerik

Page 31: Cqrs in babysteps

http:

//co

deof

rob.

com

/ent

ries/

cqrs

-is-t

oo-c

ompl

icat

ed.h

tml

Page 32: Cqrs in babysteps

SOME MISCONCEPTIONS ABOUT CQRS

@talboomerik

Page 33: Cqrs in babysteps

CQRS <> DDDIt’s not the same

@talboomerik

Page 34: Cqrs in babysteps

CQRS <> EVENT SOURCINGThey just go well together

http://lostechies.com/jimmybogard/2012/08/22/busting-some-cqrs-myths/ @talboomerik

Page 35: Cqrs in babysteps

CQRS CAN HAVE AN IMMEDIATE CONSISTENT READ STORE

http://lostechies.com/jimmybogard/2012/08/22/busting-some-cqrs-myths/ @talboomerik

Page 36: Cqrs in babysteps

CQRS DOES NOT FORCE YOU TO USE A BUS

http://lostechies.com/jimmybogard/2012/08/22/busting-some-cqrs-myths/ @talboomerik

Page 37: Cqrs in babysteps

COMMANDS DO NOT NEED TO BE FIRE-AND-FORGET

Accepting the request vs Fulfilling the request

http://lostechies.com/jimmybogard/2012/08/22/busting-some-cqrs-myths/ @talboomerik

Page 38: Cqrs in babysteps

WHY IS THIS A GOOD IDEA?Pros and cons

@talboomerik

Page 39: Cqrs in babysteps

SIMPLER DOMAIN MODELBy splitting

@talboomerik

Page 40: Cqrs in babysteps

BETTER SEPARATION OF CONCERNS AND RESPONSIBILITIES

@talboomerik

Page 41: Cqrs in babysteps

SCALABILITYTechnical and team

@talboomerik

Page 42: Cqrs in babysteps

COMPLETE REBUILD OF THE APPLICATION STATE THROUGH EVENT SOURCING

http://martinfowler.com/eaaDev/EventSourcing.html@talboomerik

Page 43: Cqrs in babysteps

TEMPORAL QUERYINGReplay history

http://martinfowler.com/eaaDev/EventSourcing.html@talboomerik

Page 44: Cqrs in babysteps

AUDIT LOGI see you

http://martinfowler.com/eaaDev/EventSourcing.html@talboomerik

Page 45: Cqrs in babysteps

IT DOES REQUIRE “SOME” WORK UPFRONT

Set up infrastructure

@talboomerik

Page 46: Cqrs in babysteps

IT WORKS BEST WITH TASK-BASED UI

Delivery mechanism and domain architecture need to collaborate

Page 47: Cqrs in babysteps

IT IS NOT EASYIt’s a big shift from what we are used to

@talboomerik

Page 48: Cqrs in babysteps

HOW CAN WE GET THIS DONE?Code, show us code

@talboomerik

Page 49: Cqrs in babysteps

THANK YOUThat’s all folks

@talboomerik