All Projects → oskardudycz → Eventsourcing.netcore

oskardudycz / Eventsourcing.netcore

Licence: mit
Examples and Tutorials of Event Sourcing in .NET Core

Projects that are alternatives of or similar to Eventsourcing.netcore

Akkatecture
a cqrs and event sourcing framework for dotnet core using akka.net
Stars: ✭ 414 (-45.53%)
Mutual labels:  event-sourcing, dotnet-core, cqrs
Kledex
.NET Standard framework to create simple and clean design. Advanced features for DDD, CQRS and Event Sourcing.
Stars: ✭ 502 (-33.95%)
Mutual labels:  event-sourcing, dotnet-core, cqrs
Pitstop
This repo contains a sample application based on a Garage Management System for Pitstop - a fictitious garage. The primary goal of this sample is to demonstrate several software-architecture concepts like: Microservices, CQRS, Event Sourcing, Domain Driven Design (DDD), Eventual Consistency.
Stars: ✭ 708 (-6.84%)
Mutual labels:  event-sourcing, netcore, cqrs
Dotnetcore Microservices Poc
Very simplified insurance sales system made in a microservices architecture using .NET Core
Stars: ✭ 1,304 (+71.58%)
Mutual labels:  dotnet-core, netcore, cqrs
Event Sourcing Jambo
An Hexagonal Architecture with DDD + Aggregates + Event Sourcing using .NET Core, Kafka e MongoDB (Blog Engine)
Stars: ✭ 159 (-79.08%)
Mutual labels:  event-sourcing, dotnet-core, cqrs
Pos
Sample Application DDD, Reactive Microservices, CQRS Event Sourcing Powered by DERMAYON LIBRARY
Stars: ✭ 207 (-72.76%)
Mutual labels:  event-sourcing, netcore, cqrs
Netcoremicroservicessample
Sample using micro services in .NET Core 3.1 Focusing on clean code
Stars: ✭ 403 (-46.97%)
Mutual labels:  event-sourcing, dotnet-core, cqrs
Dotnet Cqrs Intro
Examples of implementation CQRS with Event Sourcing - evolutionary approach
Stars: ✭ 113 (-85.13%)
Mutual labels:  event-sourcing, dotnet-core, cqrs
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 (-82.76%)
Mutual labels:  event-sourcing, dotnet-core, cqrs
Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
Stars: ✭ 162 (-78.68%)
Mutual labels:  event-sourcing, netcore, cqrs
EcommerceDDD
Experimental full-stack application using Domain-Driven Design, CQRS, and Event Sourcing.
Stars: ✭ 178 (-76.58%)
Mutual labels:  cqrs, event-sourcing, netcore
Orleankka
Functional API for Microsoft Orleans http://orleanscontrib.github.io/Orleankka/
Stars: ✭ 429 (-43.55%)
Mutual labels:  event-sourcing, cqrs
Eventstore
The stream database optimised for event sourcing
Stars: ✭ 4,395 (+478.29%)
Mutual labels:  event-sourcing, cqrs
Awesome Elixir Cqrs
A curated list of awesome Elixir and Command Query Responsibility Segregation (CQRS) resources.
Stars: ✭ 467 (-38.55%)
Mutual labels:  event-sourcing, cqrs
Resolve
Full stack CQRS, DDD, Event Sourcing framework for Node.js
Stars: ✭ 460 (-39.47%)
Mutual labels:  event-sourcing, cqrs
Event Store
PHP 7.4 EventStore Implementation
Stars: ✭ 505 (-33.55%)
Mutual labels:  event-sourcing, cqrs
Gofer.net
Easy C# API for Distributed Background Tasks/Jobs for .NET Core.
Stars: ✭ 383 (-49.61%)
Mutual labels:  dotnet-core, netcore
Netcorebbs
ASP.NET Core Light forum NETCoreBBS
Stars: ✭ 483 (-36.45%)
Mutual labels:  dotnet-core, netcore
Eventstore
Event store using PostgreSQL for persistence
Stars: ✭ 729 (-4.08%)
Mutual labels:  event-sourcing, cqrs
Modular Monolith With Ddd
Full Modular Monolith application with Domain-Driven Design approach.
Stars: ✭ 6,210 (+717.11%)
Mutual labels:  event-sourcing, cqrs

Twitter Follow Join the chat at https://gitter.im/EventSourcing-NetCore/community Build status blog

EventSourcing.NetCore

Tutorial, practical samples and other resources about Event Sourcing in .NET Core.

1. Support

Feel free to create an issue if you have any questions or request for more explanation or samples. I also take Pull Requests!

💖 If this repository helped you - I'd be more than happy if you join the group of my official supporters at:

👉 Github Sponsors

2. Prerequisites

For running the Event Store examples you need to have:

  1. .NET 5 installed - https://dotnet.microsoft.com/download/dotnet/5.0
  2. Postgres DB. You can get it by:
  • Installing Docker, going to the docker folder and running:
docker-compose up

More information about using .NET Core, WebApi and Docker you can find in my other tutorials: WebApi with .NET

Watch "Practical Event Sourcing with Marten":

Practical Event Sourcing with Marten (EN)

Slides:

  • Practical Event Sourcing with Marten - EN, PL
  • Ligths and Shades of Event-Driven Design - EN, PL
  • Adventures in Event Sourcing and CQRS - PL

3. Libraries used

  1. Marten - Event Store

  2. MediatR - Message Bus (for processing Commands, Queries, Events)

4. Event Store - Marten

  • Creating event store
  • Event Stream - is a representation of the entity in event sourcing. It's a set of events that happened for the entity with the exact id. Stream id should be unique, can have different types but usually is a Guid.
    • Stream starting - stream should be always started with a unique id. Marten provides three ways of starting the stream:
      • calling StartStream method with a stream id
        var streamId = Guid.NewGuid();
        documentSession.Events.StartStream<IssuesList>(streamId);
        
      • calling StartStream method with a set of events
        var @event = new IssueCreated { IssueId = Guid.NewGuid(), Description = "Description" };
        var streamId = documentSession.Events.StartStream<IssuesList>(@event);
        
      • just appending events with a stream id
        var @event = new IssueCreated { IssueId = Guid.NewGuid(), Description = "Description" };
        var streamId = Guid.NewGuid();
        documentSession.Events.Append(streamId, @event);
        
    • Stream loading - all events that were placed on the event store should be possible to load them back. Marten allows to:
      • get list of event by calling FetchStream method with a stream id
        var eventsList = documentSession.Events.FetchStream(streamId);
        
      • geting one event by its id
        var @event = documentSession.Events.Load<IssueCreated>(eventId);
        
    • Stream loading from exact state - all events that were placed on the event store should be possible to load them back. Marten allows to get stream from exact state by:
      • timestamp (has to be in UTC)
        var dateTime = new DateTime(2017, 1, 11);
        var events = documentSession.Events.FetchStream(streamId, timestamp: dateTime);
        
      • version number
        var versionNumber = 3;
        var events = documentSession.Events.FetchStream(streamId, version: versionNumber);
        
  • Event stream aggregation - events that were stored can be aggregated to form the entity once again. During the aggregation, process events are taken by the stream id and then replied event by event (so eg. NewTaskAdded, DescriptionOfTaskChanged, TaskRemoved). At first, an empty entity instance is being created (by calling default constructor). Then events based on the order of appearance (timestamp) are being applied on the entity instance by calling proper Apply methods.
    • Aggregation general rules
    • Online Aggregation - online aggregation is a process when entity instance is being constructed on the fly from events. Events are taken from the database and then aggregation is being done. The biggest advantage of online aggregation is that it always gets the most recent business logic. So after the change, it's automatically reflected and it's not needed to do any migration or updates.
    • Inline Aggregation (Snapshot) - inline aggregation happens when we take the snapshot of the entity from the DB. In that case, it's not needed to get all events. Marten stores the snapshot as a document. This is good for performance reasons because only one record is being materialized. The con of using inline aggregation is that after business logic has changed records need to be reaggregated.
    • Reaggregation - one of the biggest advantages of the event sourcing is flexibility to business logic updates. It's not needed to perform complex migration. For online aggregation it's not needed to perform reaggregation - it's being made always automatically. The inline aggregation needs to be reaggregated. It can be done by performing online aggregation on all stream events and storing the result as a snapshot.
      • reaggregation of inline snapshot with Marten
        var onlineAggregation = documentSession.Events.AggregateStream<TEntity>(streamId);
        documentSession.Store<TEntity>(onlineAggregation);
        documentSession.SaveChanges();
        
  • Event transformations
  • Events projection
  • Multitenancy per schema

5. Message Bus (for processing Commands, Queries, Events) - MediatR

  • Initialization - MediatR uses services locator pattern to find a proper handler for the message type.
  • Sending Messages - finds and uses the first registered handler for the message type. It could be used for queries (when we need to return values), commands (when we acting).
    • No Handlers - when MediatR doesn't find proper handler it throws an exception.
    • Single Handler - by implementing IRequestHandler we're deciding that this handler should be run asynchronously with other async handlers (so we don't wait for the previous handler to finish its work).
    • More Than One Handler - when there is more than one handler registered MediatR takes only one ignoring others when Send method is being called.
  • Publishing Messages - finds and uses all registered handlers for the message type. It's good for processing events.
    • No Handlers - when MediatR doesn't find proper handler it throws an exception
    • Single Handler - by implementing INotificationHandler we're deciding that this handler should be run asynchronously with other async handlers (so we don't wait for the previous handler to finish its work)
    • More Than One Handler - when there is more than one handler registered MediatR takes all of them when calling Publish method
  • Pipeline (to be defined)

6. CQRS (Command Query Responsibility Separation)

7. Fully working sample application

See also fully working sample application in Sample Project

  • See sample how Entity Framework and Marten can coexist together with CQRS and Event Sourcing

8. Self-paced training Kit

I prepared the self-paced training Kit for the Event Sourcing. See more in the Workshop description.

It's split into two parts:

Event Sourcing basics - it teaches the event store basics by showing how to build your Event Store on Relational Database. It starts with the tables setup, goes through appending events, aggregations, projections, snapshots, and finishes with the Marten basics. See more in here.

  1. Streams Table
  2. Events Table
  3. Appending Events
  4. Optimistic Concurrency Handling
  5. Event Store Methods
  6. Stream Aggregation
  7. Time Travelling
  8. Aggregate and Repositories
  9. Snapshots
  10. Projections
  11. Projections With Marten

Event Sourcing advanced topics - it's a real-world sample of the microservices written in Event-Driven design. It explains the topics of modularity, eventual consistency. Shows practical usage of WebApi, Marten as Event Store, Kafka as Event bus and ElasticSearch as one of the read stores. See more in here.

  1. Meetings Management Module - the module responsible for creating, updating meeting details. Written in Marten in Event Sourcing pattern. Provides both write model (with Event Sourced aggregates) and read model with projections.
  2. Meetings Search Module - responsible for searching and advanced filtering. Uses ElasticSearch as storage (because of its advanced searching capabilities). It's a read module that's listening for the events published by the Meetings Management Module.

9. NuGet packages to help you get started.

I gathered and generalized all of the practices used in this tutorial/samples in Nuget Packages maintained by me GoldenEye Framework. See more in:

  • GoldenEye DDD package - it provides a set of base and bootstrap classes that helps you to reduce boilerplate code and help you focus on writing business code. You can find all classes like Commands/Queries/Event handlers and many more. To use it run:

    dotnet add package GoldenEye.Backend.Core.DDD

  • GoldenEye Marten package - contains helpers, and abstractions to use Marten as document/event store. Gives you abstractions like repositories etc. To use it run:

    dotnet add package GoldenEye.Backend.Core.Marten

The simplest way to start is installing the project template by running

dotnet new -i GoldenEye.WebApi.Template.SimpleDDD

and then creating a new project based on it:

dotnet new SimpleDDD -n NameOfYourProject

10. Other resources

10.1 Various

10.2 Snapshots

10.3 Projections

10.4 Event processing

10.5 Distributed processes

10.6 Modeling

11. Contributors

11.1 Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

11.2 Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

EventSourcing.NetCore is Copyright © 2017-2021 Oskar Dudycz and other contributors 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].