Your SlideShare is downloading. ×
0
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
CQRS In An Hour Or So
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

CQRS In An Hour Or So

2,983

Published on

Presentation by John Nuechterlein (a.k.a. Jdn) for the Chicago ALT.NET user group on January 2010.

Presentation by John Nuechterlein (a.k.a. Jdn) for the Chicago ALT.NET user group on January 2010.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,983
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. CQRS in an hour or so<br />1<br />
  • 2. Who is jdn?<br />Me, aka John Nuechterlein<br />Blog: http://www.blogcoward.com<br />Operations Manager – Developer – Architect -Raging Douchebag<br />eCom then Finance hopefully ecom again background<br />Ph.D. in Philosophy (University of Miami at the age of 25)<br />HI JEREMY!!!!!!!<br />2<br />
  • 3. Sources<br />Greg Young<br />http://codebetter.com/blogs/gregyoung/archive/2009/08/13/command-query-separation.aspx<br />UdiDahan<br />http://www.udidahan.com/2009/12/09/clarified-cqrs/<br />Mark Nijhof<br />http://elegantcode.com/2009/11/11/cqrs-la-greg-young/<br />3<br />
  • 4. CQRS<br />CQRS = “Command Query Responsibility Segregation”<br />Huh?<br />A design – pattern -architecture – Framework – Principle – Something<br />Makes stuff better<br />Huh?<br />4<br />
  • 5. CQS Defined<br />Bertrand Meyer (via Wikipedia)<br />“Command Query Separation”<br />“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.”<br />5<br />
  • 6. CQRS defined<br />Meyer:    Separate command methods that change state from query methods that read state.<br />Greg Young:    Separate command messages that change state from query messages that read state.<br />Can have significant architectural implications<br />6<br />
  • 7. Nihjof #1<br />7<br />
  • 8. Nihjof #2<br />8<br />
  • 9. Nihjof Categories<br />1 – Queries <br />2 – Commands <br />3 – Internal Events <br />4 – External Events <br />9<br />
  • 10. UDI #1<br />10<br />
  • 11. Queries<br />‘Reporting’ <br />Misleading description (Greg’s fault), but makes some sense<br />Simple Query Layer<br />Simple views or sprocs or selects from denormalized tables<br />Simple DTOs, no mapping needed<br />Don’t go through the Domain Model, as it pollutes it<br />ViewModel per query perhaps<br />Why should the data come across 5 layers through 3 model transformations to populate a screen? (Udi)<br />‘Traditional Reporting’<br />Can (almost always will) have its own Model as well (and perhaps/probably its own data source)<br />Synchronous, no messaging needed<br />Eventual Consistency (more later)<br />11<br />
  • 12. Queries<br />No mapping code, don’t even bother getting a domain object at all, e.g.:<br />public class ModelDetailBrickDTOMapper : IMapper&lt;Model, ModelDetailBrickDTO&gt;<br /> {<br />public ModelDetailBrickDTO Map(Model m)<br /> {<br /> return new ModelDetailBrickDTO(m.ID, m.Name, m.Description, m.Details, m.ShippingMessage, m.GetPrice(&quot;Current&quot;), m.GetPrice(&quot;MSRP&quot;), m.Sizes, m.Images, DisplayProductBrick.GetRelatedDisplayProductBricksByModel(m));<br /> }<br />}<br />12<br />
  • 13. Queries<br />Data store<br />Cache it (it’s already stale)<br />Why not on web-tier?<br />Why relational?<br />Horizontal scalability<br />If you cache, add a new server to handle it<br />13<br />
  • 14. Commands<br />Commands capture intent, DTOs don’t<br />CustomerDTOvsCustomerChangedAddressCommand<br />Part of the ‘Ubiquitous’ Language<br />Handler per command<br />Can be validated outside of domain entities<br />This is why no getters/setters on domain entities, their state is updated by processing commands according to the rules of the business<br />This is why domain entities are never invalid, commands that would produce invalid state are rejected<br />14<br />
  • 15. Commands<br />Separate Data Modification<br />Make preferred<br />Change address<br />Delinquent payment event example<br />Comes in 1 ms after make preferred event<br />What to do?<br />A generic DTO could do these things, of course, but after the fact, how do you know what actually happened?<br />UI Implications<br />Excel-like screens don’t work<br />Commands require specific intent<br />15<br />
  • 16. Commands<br />Commands can be queued<br />Split into separate queues<br />Scale where needed<br />Commands don’t have to be handled by the domain<br />16<br />
  • 17. Internal Events<br />Triggered by commands<br />Can be persisted<br />Could be RDBMS, ODBMS, Document DB, etc.<br />Event sourcing (big topic, punting)<br />Can be replayed<br />Production support benefit<br />Snapshots can also be created & persisted<br />Don’t delete original events<br />Domain can accept command or reject it<br />Raise event either way<br />17<br />
  • 18. Internal Events<br />Write-only<br />“Accountants don’t use erasers”<br />Compensating Actions/Events<br />Instead of rolling back a transaction, you compensate for some failure<br />Automatic audit log<br />You have all the events that happened<br />No more ‘impedence mismatch’<br />You are persisting events, not rows<br />Data mining<br />Like I said, you have all the events that happened<br />18<br />
  • 19. External Events<br />Publishing<br />Typically, message bus<br />Could use views or ETL to process in a ‘simpler’ architecture<br />Data stores can subscribe<br />Only process when a read request comes in (GY)<br />19<br />
  • 20. External Events<br />Publishing external events and persisting internal events done in a transaction<br />Eventual Consistency<br />Latency is almost always okay<br />Question is, how much?<br />Availability trumps correctness<br />Acting on incomplete data is normal<br />Event handler per view model, perhaps<br />20<br />
  • 21. Why not CQRS?<br />It’s new, it’s different, I’m stupid<br />Multiple data stores<br />Operational Complexity<br />Losing ACID/Transactions is scary<br />Lots of Commands and Events and Handlers and Lions and Tigers and Bears oh my! to Code<br />21<br />
  • 22. Questions?<br />22<br />

×