Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CQRS & Event Sourcing

D1b1ae7d58da3d0cb7db07e308758e9e?s=47 The Guild
February 27, 2014

CQRS & Event Sourcing

Command-Query Responsibility Segregation by Stefan van Raaphorst


The Guild

February 27, 2014


  1. d i g i t a l c r a

    f t s m a n s h i p CQRS  and  Event sourcing ! ! stefan van Raaphorst
  2. Disclaimer - the experts • Greg Young - http://goodenoughsoftware.net/ •

    Udi Dahan - http://www.udidahan.com/ (The Software Simplist)
  3. Disclaimer by the experts • NO it's not a silver

    bullet nor a Golden Hammer • Yes a lot of best practices and well known patterns are involved
  4. CQS - Command-query separation Definition Separate command methods that change

    state from query methods that read state ! ! A principle Source: http://en.wikipedia.org/wiki/Command-query_separation [Bertrand Meyer]
  5. Command-Query Responsibility Segregation Defined Definition Separate command messages that change

    state from query messages that read state. ! As Design - Architecture - Pattern from Domain Driven Design Source: http://codebetter.com/gregyoung/2009/08/13/command-query-separation/
  6. Single model ! ! Source: http://martinfowler.com/bliki/CQRS.html

  7. CQRS model Mindset: Eventual Consistency Data is out-of-date/stale the moment

    a user sees it on the screen in a collaborative environment.
  8. Write and Read model Mindset This brings the notion of

    write models are different to read models and querying "search engine style" is a whole separate thing.
  9. Commands and events Mindset: Intent in action Are you correcting

    an address or do you move someone to a different address
  10. Event sourcing State History

  11. Event sourcing Capture meta-data Intent - "Update" address was this

    Correcting a address or did this person move (so we can do some marketing) ! History/behavior - Shopping cart with two items or added 3 items and removed one
  12. Event sourcing Mindset: Creating new reports and views for historical

  13. So what is the use? • Capture business changes in

    a lossless manner • Audit trail • It makes it easy to test, replay (business logic) failures in from the field
  14. What are the benefits? • The ability to partition on

    a domain level and keep the model simple • Optimize for a single model (read/write) • To have choice in technology used (e.g. not one DB to tackle all issues)
  15. d i g i t a l c r a

    f t s m a n s h i p ! ! stefan van Raaphorst http://www.thedeveloperday.com/tag/cqrs/