Top Banner
digital craftsmanship CQRS and Event sourcing stefan van Raaphorst
15
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
  • 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

  • Disclaimer - the experts Greg Young - http://goodenoughsoftware.net/

    Udi Dahan - http://www.udidahan.com/ (The Software Simplist)

  • 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

  • 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]

  • Command-Query Responsibility Segregation DefinedDefinition

    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/

  • Single model

    !

    !Source: http://martinfowler.com/bliki/CQRS.html

  • CQRS model

    Mindset: Eventual Consistency

    Data is out-of-date/stale the moment a user sees it on the screen

    in a collaborative environment.

    !

  • 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.

  • Commands and events

    Mindset: Intent in action

    Are you correcting an address or do you move someone to a different address

  • Event sourcing

    State History

  • Event sourcingCapture 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

  • Event sourcing

    Mindset:

    Creating new reports and views for historical data

  • 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

  • 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)

  • 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/