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

CQRS & Event Sourcing

The Guild
February 27, 2014

CQRS & Event Sourcing

Command-Query Responsibility Segregation by Stefan van Raaphorst

The Guild

February 27, 2014
Tweet

More Decks by The Guild

Other Decks in Programming

Transcript

  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. CQRS model Mindset: Eventual Consistency Data is out-of-date/stale the moment

    a user sees it on the screen in a collaborative environment.
  7. 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.
  8. Commands and events Mindset: Intent in action Are you correcting

    an address or do you move someone to a different address
  9. 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
  10. 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
  11. 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)
  12. 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/