• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Cqrs 101  all your base belong to us
 

Cqrs 101 all your base belong to us

on

  • 621 views

An intro into CQRS I gave for the Belgian Visual studio User group in March 2012

An intro into CQRS I gave for the Belgian Visual studio User group in March 2012

Statistics

Views

Total Views
621
Views on SlideShare
621
Embed Views
0

Actions

Likes
3
Downloads
19
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Cqrs 101  all your base belong to us Cqrs 101 all your base belong to us Presentation Transcript

    • CQRS 101All your BASE belong to usFirst dive into CQRS by Tom JanssensMarch 6th, 2012Hosted for VISUG.be by AE NV - Leuven, Belgium
    • Tom Janssens● Tom@corebvba.be● ToJans@twitter● http://www.corebvba.be/blog● http://github.com/ToJans● Fun Fact: 10 startups in one yearFreelance problem solver - contact me !
    • Y U NO CQRS ?● Occasionally disconnected client app● Google Groups Forum DDD/CQRS● CQRS articles on blog● OSS CQRS frameworks/libs:Scritchy & MinimalisticCQRS● Member of MS P & P CQRS advisory boardA.K.A. my CQRS background and - experience
    • OverviewTalk the talk● What● Why● WhenWalk the walkDemo BankAccount● MinimalisticCQRS● Uniqueness● Account transfer
    • WHAT: complexity evolutionSpaghetti approachUI Data layer
    • WHAT: complexity evolutionLasagna approach *:* Can contain additional layersUI App layer Data layerDomain layer
    • Command: change state - push data (state changes)Query: query state - pull dataWHAT: complexity evolution* Command-Query separation - Bertrand Meyer"Asking a question should not change the answer"CQS approach *:UI App layer Data layerAdvantages: Scaling, risk, impactUI App layer Data layerDomain layer
    • WHAT: complexity evolutionCQRS: Command Query Responsibility Segregation@Kellabyte on twitterThis is #CQRS http://bit.ly/zR2VuVThats it, thats all. What you put in behindthose is entirely up to you.
    • WHAT: complexity evolution// CQS (Command-Query Separation)// Bertrand Meyer devised the CQS principle// [deleted for brevity]public class CustomerService{// Commandsvoid MakeCustomerPreferred(CustomerId)void ChangeCustomerLocale(CustomerId, NewLocale)void CreateCustomer(Customer)void EditCustomerDetails(CustomerDetails)// QueriesCustomer GetCustomer(CustomerId)CustomerSet GetCustomersWithName(Name)CustomerSet GetPreferredCustomers()}
    • WHAT: complexity evolution// CQRS (Command-Query Responsibility Segregation)// Defined by Greg Young.// [deleted for brevity]public class CustomerWriteService{// Commandsvoid MakeCustomerPreferred(CustomerId)void ChangeCustomerLocale(CustomerId, NewLocale)void CreateCustomer(Customer)void EditCustomerDetails(CustomerDetails)}public class CustomerReadService{// QueriesCustomer GetCustomer(CustomerId)CustomerSet GetCustomersWithName(Name)CustomerSet GetPreferredCustomers()}
    • Thats all folks !!! The End !... Or not ?
    • Command: change state - push data (state changes)Query: build/query state - pull dataWHAT: complexity evolution* Command-Query Responsibility Segregation- Greg Young, Udi DahanCQRS approach *:"The creation of 2 objects where there previously was one"EventsUI Data layerUI Domain layerCommandsEventsbuildquery
    • What: messagesCommand● DoStuff !● Imperativevoid DoStuff( ... ){if (somethingtrue)apply(StuffDone);}Event● StuffDone● Past tensevoid Handle(StuffDone){SomeState = true;}IMPORTANT!!An event handler should ALWAYShave an immutable execution path,i.e. no logic !!
    • Command: change state - push data (state changes)Query: build/query state - pull dataWHAT: complexity evolutionCQRS approach *:Example code : Scritchy exampleEventsUI Data layerUI Domain layerCommandsEventsbuildquery
    • Why ?Clear separation of concernsDomainQuery sideUICommandsEventsupdateviewmodels"Circular architecture"Evolution of AlisterCockburns hexagonalarchitecture; no moreadapters needed
    • WhyClear separation of concerns● Requires different knowledge/other devs● Testability● Ubiquitous language● New business requirements
    • WhyEvent-driven architecture and the cloud:CAP theorem: pick 2ConsistencyAvailability Partitionability
    • Why: events & the cloudACID : Consistency & Availability● AtomicityAll operations complete, or none● Consistency(During a transaction)● IsolationEvery operation behaves as it is the only one● DurabilityFinished tx will not be reversed
    • Why: events & the cloudBASE : Availability & Partitionability● BasicallyAvailable● Soft state● Eventually consistent=> CLOUD !!!=> Solution for the consistency boundariesDDD: ARs & sagas
    • Why: events & the cloud
    • Why: events & the cloud
    • Why: events & the cloud
    • Why: events & the cloud
    • When to use CQRS ?Only apply it to the parts of your problemdomain that offer you a competitive advantage.Indicator for Complexity/uniqueness:=> T-shirt categories (Greg Young)CRUD - tell what cant be doneDDD - tell what can be doneref: free eBook "DDD quickly","What is DDD?"Works really well with DDD/ES=> When your problem domains are not fixed
    • BreakUp next - demo live coding
    • ConclusionWhat:Two objects where there previously was oneRemove layers and abstractionsCircular architecture=> Fire and forget
    • ConclusionWhy:Separation of concernsEvent driven architectureFlexibility, ScalabilityTestability
    • ConclusionWhen:ComplexityUniquenessCompetitive advantageParts of your problem domain
    • ThanksCQRS folks - for being such an avid community@YReynhout and @Abdullin for reviewVISUG.be and AE NV for hosting the event
    • Questions & feedback ?Twitter: @ToJans