Git Product home page Git Product logo

cqrs-clean-eventual-consistency's Introduction

Guaraci Clean Architecture CQRS with Derived Data

CQRS, using Clean Architecture, multiple databases and Eventual Consistency

Build Status

๐Ÿ“‘ Detailed information

I also keep more detailed information in my blog, and I going to release weekly to clarify my ideas:

๐Ÿ’พ How do I use it?

You need some of the following tools:

  • Docker
  • Visual Studio 2019
  • .Net Core 3.0

๐ŸŽฏ Clean Architecture

Here's the basic architecture of this microservice template:

  • Respecting policy rules, with dependencies always pointing inward
  • Separation of technology details from the rest of the system
  • SOLID
  • Single responsibility of each layer

cqrs-clean

โœ‚๏ธ CQRS

Segregation between Commands and Queries, with isolated databases and different models

โฌ‡๏ธ Command Stack

Has direct access to business rules and is responsible for only writes in the application.

Below you can find a basic interaction between components in the Command Stack:

โฌ†๏ธ Query Stack

Responsible to provide data to consumers of your application, containing a simplified and more suitable model for reading, with calculated data, aggregated values and materialized structures.

The image contains the basic interaction between components in the Query Stack:

๐Ÿ“š DDD

This example contains a simplified Domain Model, with entities, aggregate roots, value objects and events, which are essential to synchronize the writing with reading database.

โœ”๏ธ TDD

The project contains a well-defined IoC structure that allow you unit test almost every part of this service template, besides technology dependencies.

Inside the main layers you going to find Interfaces which are essential for the application, but with their implementations inside their own layers, what allow Mocking, Stubbing, using test doubles.

There's a simple example using Mother Object Pattern and Builder to simplify unit tests and keep it maintainable and clean.

๐Ÿ“Š Data Intensive Microservice

This microservice template comes with SRP and SOC in mind. Given the own nature of CQRS, you can easily scale this application tuning each stack separately.

๐Ÿ“„ Derived Data

Having multiple data stores makes this system a Derived Data system, which means, you never lose data, you can always rebuild one store from another, for example, if you lose an event which sync data between the write and read database you can always get this data back from the write database and rebuild the read store.

Domain Model is materialized to Query Models using view materializer. Keeping this as separed component in the query stack allows fully control to mapped properties and fully testable.

โœ‰๏ธ Message Broker

Given the physical isolation of data stores, Command Stack and Query Stack must communicate to synchronize data. This is done here using a Message Broker.

Every successful handled command creates an event, which is published into a Message Broker. A synchronization background process subscribes to those events and is responsible for updating the reading database.

๐Ÿ•‘ Eventual Consistency

Everything comes with some kind of down side. The case of CQRS with multiple databases, to maintain high availability and scalability we create inconsistencies between databases.

More specifically, replicating data between two databases creates an eventual consistency, which in a specific moment in time, given the replication lag they are different, although is a temporary state and it eventually resolves itself.

๐Ÿ“‹ References

Here's a list of reliable information used to bring this project to life.

cqrs-clean-eventual-consistency's People

Contributors

azure-pipelines[bot] avatar fals 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.