All Projects → andreschaffer → Event Sourcing Cqrs Examples

andreschaffer / Event Sourcing Cqrs Examples

Licence: mit
Event Sourcing and CQRS in practice.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Event Sourcing Cqrs Examples

Goes
Go Event Sourcing made easy
Stars: ✭ 144 (-45.66%)
Mutual labels:  events, event-sourcing, ddd, cqrs, domain-driven-design
delta
DDD-centric event-sourcing library for the JVM
Stars: ✭ 15 (-94.34%)
Mutual labels:  cqrs, ddd, domain-driven-design, event-sourcing, cqrs-es
Rails event store
A Ruby implementation of an Event Store based on Active Record
Stars: ✭ 947 (+257.36%)
Mutual labels:  event-sourcing, cqrs-es, ddd, cqrs, domain-driven-design
Event Sourcing Jambo
An Hexagonal Architecture with DDD + Aggregates + Event Sourcing using .NET Core, Kafka e MongoDB (Blog Engine)
Stars: ✭ 159 (-40%)
Mutual labels:  event-sourcing, cqrs-es, ddd, cqrs, domain-driven-design
Eventflow
Async/await first CQRS+ES and DDD framework for .NET
Stars: ✭ 1,932 (+629.06%)
Mutual labels:  events, cqrs-es, ddd, cqrs, domain-driven-design
Kreta
Modern project management solution
Stars: ✭ 177 (-33.21%)
Mutual labels:  event-sourcing, ddd, cqrs, domain-driven-design
Messagebus
A MessageBus (CommandBus, EventBus and QueryBus) implementation in PHP7
Stars: ✭ 178 (-32.83%)
Mutual labels:  event-sourcing, ddd, cqrs, domain-driven-design
Dotnet New Caju
Learn Clean Architecture with .NET Core 3.0 🔥
Stars: ✭ 228 (-13.96%)
Mutual labels:  event-sourcing, ddd, cqrs, domain-driven-design
All Things Cqrs
Comprehensive guide to a couple of possible ways of synchronizing two states with Spring tools. Synchronization is shown by separating command and queries in a simple CQRS application.
Stars: ✭ 474 (+78.87%)
Mutual labels:  events, ddd, cqrs, domain-driven-design
Kledex
.NET Standard framework to create simple and clean design. Advanced features for DDD, CQRS and Event Sourcing.
Stars: ✭ 502 (+89.43%)
Mutual labels:  events, event-sourcing, ddd, cqrs
CQELight
CQELight is an entreprise grade extensible and customisable framework for creating software with CQRS, DDD & Event Sourcing patterns
Stars: ✭ 21 (-92.08%)
Mutual labels:  events, cqrs, ddd, event-sourcing
OpenSleigh
OpenSleigh is a Saga management library for .NET Core.
Stars: ✭ 198 (-25.28%)
Mutual labels:  events, cqrs, ddd, cqrs-es
Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
Stars: ✭ 162 (-38.87%)
Mutual labels:  event-sourcing, ddd, cqrs, domain-driven-design
OpenCQRS
.NET Standard framework to create simple and clean design. Advanced features for DDD, CQRS and Event Sourcing.
Stars: ✭ 546 (+106.04%)
Mutual labels:  events, cqrs, ddd, event-sourcing
fee-office
A DDD, CQRS, ES demo application
Stars: ✭ 35 (-86.79%)
Mutual labels:  cqrs, domain-driven-design, event-sourcing, cqrs-es
EcommerceDDD
Experimental full-stack application using Domain-Driven Design, CQRS, and Event Sourcing.
Stars: ✭ 178 (-32.83%)
Mutual labels:  cqrs, ddd, domain-driven-design, event-sourcing
Eventflow.example
DDD+CQRS+Event-sourcing examples using EventFlow following CQRS-ES architecture. It is configured with RabbitMQ, MongoDB(Snapshot store), PostgreSQL(Read store), EventStore(GES). It's targeted to .Net Core 2.2 and include docker compose file.
Stars: ✭ 131 (-50.57%)
Mutual labels:  event-sourcing, ddd, cqrs, domain-driven-design
Productcontext Eventsourcing
A practical/experimental Event Sourcing application on Product Bounded Context in an e-commerce
Stars: ✭ 88 (-66.79%)
Mutual labels:  event-sourcing, ddd, cqrs, domain-driven-design
Bifrost
This is the stable release of Dolittle till its out of alpha->beta stages
Stars: ✭ 111 (-58.11%)
Mutual labels:  event-sourcing, ddd, cqrs, domain-driven-design
node-cqrs-saga
Node-cqrs-saga is a node.js module that helps to implement the sagas in cqrs. It can be very useful as domain component if you work with (d)ddd, cqrs, eventdenormalizer, host, etc.
Stars: ✭ 59 (-77.74%)
Mutual labels:  events, cqrs, domain-driven-design, event-sourcing

Build Test Coverage Maintainability Dependabot

Event Sourcing and CQRS Examples

This project aims to provide examples of how to use Event Sourcing and CQRS applied to a minimalistic bank context.

We assume the reader has basic knowledge of Event Sourcing and CQRS concepts.
If you want to brush up on the subject we suggest reading:

Domain overview

In this minimalistic bank, a client can open one or more accounts.
On each account, the client can deposit or withdraw money.
The history of an account's transactions is available to the client as well as a summary of the client's accounts.

Design choices

Architecture overview

  Event Store   Projections
    +----+        +----+
    |    |        |    |
    | DB |        | DB |
    +--+-+        +-+--+
      ^             ^
      |             |
+------------+------------+
|     |      |      |     |
|     |    Events   |     |
|     +------+----+ |     |
|     |      |    | |     |
|     +      |    v +     |
|   Domain   |   Read     |
|   Model    |   Model    |
|            |            |
+------------+------------+
|                         |
|           API           |
|                         |
+-------------------------+ 

Ports and Adapters

For the Domain Model, we chose the Ports and Adapters structure because we wanted to protect the domain logic from all the technical concerns.

For more information about it read here.

Package by Feature

For the Read Models, we chose the Package by Feature structure because we would not benefit from isolating the layers and instead we put all feature related parts close together.

For more information about it read here.

DDD and REST

There has been a myth of DDD and REST being incompatible due to DDD being all about behaviour whereas REST is all about state.
In this project we followed both techniques quite strictly and hope that the result shows that they can be well combined.
Note: We did not include REST hypermedia controls as we believe it is a big subject in itself and didn't want to shift focus from Event Sourcing and CQRS.

Event Sourcing and CQRS (finally!)

We have taken a pragmatic approach when combining Event Sourcing and CQRS. By the book, CQRS proposes a complete separation between the read/query and write/command sides, but that's not what we have here. The approach we've taken instead:

  • The writes/commands are all on the domain model side and processed by aggregates;
  • The reads/queries are both in the domain model side and in the read model side.
    • The queries in the domain model side are only allowed when the data we need is a single aggregate itself. The reason being that we can only query the event store by aggregate id and we can actually fulfill those queries by replaying that single aggregate events.
    • For any other kind of query, we don't want to compromise the domain model. Therefore, we create read models to fulfill those queries. They are basically projections, potentially built from different events and aggregates that can be queried by more appropriate fields.

Events

Events are a thing from the past. It communicates a significant change that happened.

Idempotency when replaying events

When replaying events, we don't want to execute any business logic because we can't change history. We only want to do assignments.
A simple example is with a deposit event: instead of adding the deposited amount to the balance when replaying (business logic), we want the updated balance already available so that we can just assign it. This makes it possible to replay the event multiple times with the same outcome.

Ordering of events

In a distributed world, event timestamps are unreliable for ordering - machines have their own clocks.
Instead we can make the ordering explicit with an event version. In this project we use event versioning in two ways:

  • In the write/command side, we use it for protecting ourselves from race conditions via optimistic locking;
  • In the read/query side, we use it for commutative reasons, meaning events can come out of order and we can still handle them properly.

If you are interested in this topic, we also recommend reading about Lamport timestamps and Vector clocks as alternatives.

Trying it out

Requirements

  • Java 14
  • Maven

Building the application

mvn clean verify

Starting the application

java -jar target/bank-service-1.0-SNAPSHOT.jar server src/environments/development.yml

Examples of use

Create a client

curl -v -X POST -H "Content-Type: application/json" -d '{"name":"Jane Doe", "email":"[email protected]"}' http://localhost:8080/clients

Check the created client in the response's 'Location' header.

Create an account for the client

curl -v -X POST -H "Content-Type: application/json" -d '{"clientId":"{CLIENT_ID}"}' http://localhost:8080/accounts

Check the created account in the response's 'Location' header.

Make a deposit to the account

curl -v -X POST -H "Content-Type: application/json" -d '{"amount":1000000}' http://localhost:8080/accounts/{ACCOUNT_ID}/deposits

Check that you created a millionare!

curl -v http://localhost:8080/accounts/{ACCOUNT_ID}

More operations

Go ahead and check the code! :)

Contributing

If you would like to help making this project better, see the CONTRIBUTING.md.

Maintainers

Send any other comments, flowers and suggestions to André Schaffer and Dan Eidmark.

License

This project is distributed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].