Giter VIP home page Giter VIP logo

cqrs-best-practices's Introduction

CQRS/ES best practices

Best practices, guidance, and anti-patterns to avoid when building an application following CQRS/ES principles.

Guidance

Define a schema for commands and events

Services share schema and contract, not class.

Don't share types (i.e. .NET classes compiled into assemblies) as a way to express contracts in a messaging system.

Do define and share a schema and contract. Publish it for consumers to build their own internal representation of your data.

Examples

Further reading

Value objects in domain events

Do use simple types in domain events (strings, numbers, lists).

Don't use value objects in events as events are immutable, whereas value objects may change over time.

Use integration events between services, not domain events

Don't expose domain events outside of the service, or bounded context, that creates them.

Do use integration events. An event that occurred in the past within an bounded context which may be interesting to other domains, applications or third party services. The purpose of integration events is to explicitly propagate committed transactions and updates to additional subsystems. You may convert and publish a domain event to external services, as an integration event, after it has been committed.

This makes is easier to change internal domain events, while allowing external integration events to provide a stable API to consumers. It also allows a service to only expose a subset of its domain events as integration events. Integration events can be enriched with additional data, such as from a read model projection, that is relevant to external uses.

Futher reading

Read model

Autonomous read model projections

Don't share data between projections.

Do use autonomous projectors responsible for their own data. Projectors should run independently, allowing them to track their own progress and be rebuilt as required.

Further reading

Projectors should never crash

Don't enforce consistency rules in your read model projection.

Do follow Postel's robustness principle:

Be conservative in what you send, be liberal in what you accept.

Versioning

Further reading

Data migration

Further reading


Contributing

Pull requests gladly accepted for your best practices, advice, and guidance.

cqrs-best-practices's People

Contributors

slashdotdash avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.