Tutorial/Learning Event Modeling with Event Sourcing, in C# dotnet with Eventuous, EventStoreDB and optionally MongoDB for read-models/views/projections

Sharing my “Learning and Getting started to apply Event Modeling – for design and documentation, with Event Sourcing – for storage, in C# dotnet with Eventuous, EventStoreDB and optionally MongoDB for read-models/views/projections

A short introduction to Event Modeling and Event Sourcing in Swedish is available here

Note: If you don’t do C# and dotnet, I still recommend having a look at Event Modeling, Event Sourcing and Event Store DB, you don’t need to use them but it’s good to know there are more than one way of doing things – and you can implement them with other tech stacks than dotnet.

My code is available in https://github.com/JimiSweden/eventuous-dotnet-sample/tree/Order_processing (it builds on top of a fork from https://github.com/Eventuous/dotnet-sample)

My Event Modeling “getting started template” with the example used for implementation of purchase order process – including explained code examples – https://miro.com/app/board/o9J_lrFQov0=/?moveToWidget=3458764527760600530&cot=14

Note that the board and the code are work in progress and will change, this a playground and some things should be refactored or remodeled; however, it’s good enough to follow along and see how it works, hopefully it will also help you getting started – or at least it is an eye opener.

The miro bord contains the following three sections.
1. The Event Model describing the system to build.
2. Eventuous implementation explained in short with code examples (you should also read the docs, linked below)
3. Example of commands executed from Postman ending up as events in Event Store and displayed in the UI. And swagger for API overview.

Big picture - Event Model Template (simple starter) - OrderProcessing overview
Big picture - Order Processing Event Model (see the miro board for a detailed view, and selected images in the bottom)

This is a summary of what, why and how.

Event Modeling is “just” a concept/methodology for documenting (software) systems

  • It’s not a product although products* are built around the concept, with code generators etc.
    *(see “Tools” in the Event Modeling Resources page)
  • It helps you build and maintain a visual blueprint of your system – before and during development.
  • It goes hand in hand with Event Sourcing but can be used to describe any type of system (even manual/analog systems)
  • It is in my opinion an incredible powerful/comprehensive way to explain how a system should and does work.

You will use it as a collaborative space where you can design, present and talk about the system workflow with different types of stakeholders – It doesn’t require technical skills to understand, it’s basically describing the process or workflow with business rules and most people will understand the basics in 15 minutes.

You can f ex use it to

  • onboard new people
  • talk with business about business rules, how the system works now and the effects of applying new or changing requirements.
  • guide the team and developers in what to implement, with a small design upfront.
  • visualize integrations and dependencies with subsystems and external systems
  • have visual discussions around what is needed and should or could be built
  • see opportunities from what you already have on your “map”
  • divide work in slices or sections of slices for teams or people.

https://eventmodeling.org/resources/#intro-videos also contains a full mini workshop video if you want an introduction and listen to discussions and feedback around a really short workshop. (note that in the middle of the workshop you will need to jump/fast forward from the part where the breakout rooms are created until the participants are back in the main room).

More on what Event Modeling is – https://eventmodeling.org/posts/what-is-event-modeling/
And where it stems from – https://eventmodeling.org/about/

My “getting started template” with the example used for implementation of a purchase order process – https://miro.com/app/board/o9J_lrFQov0=/?moveToWidget=3458764527760600530&cot=14

Event Sourcing – the source of truth
If you are new to Event Sourcing you might want to read

Also, search for videos on the topic, there are plenty but you might want to look at something presented by Greg Young to ensure you get a fair introduction.

Eventuous – only if you are doing dotnet/.NET
Read the docs and start here – https://eventuous.dev/docs/prologue/introduction/#what-is-eventuous
What is Eventuous and why you want to use it for implementing an event-sourced system with .NET or .NET Core?
Eventuous is a (relatively) lightweight library, which allows building production-grade applications using the Event Sourcing pattern.

For me it helps to use this Library when learning to implement Event Sourcing, although there is a small learning curve to use it, because it takes care of things in the communication with EventstoreDB and guides me to how to do things in a way that builds on long experience in the industry from Alexey

If you don’t know what it is or need a refresher – read https://zimarev.com/blog/event-sourcing/cqrs/

EventStoreDB – Database built for event sourcing, available as on-premise and in Azure.

https://www.eventstore.com/ – click on “learning” for plenty of useful information on getting started with Event Store, Event Sourcing and CQRS.
MongoDB – a document database used in this example to build read models (projections of current state of an order). This is optional, you can also read everything from the EventStore but in many cases you might want to have “in memory projections”, since EventStore builds the state from events in history, or if you want to have projections containing some of the information from the events such as a “My Orders View” containing only some details of all the customer orders.

Worth to know is that Adam (Event Modeling) mentioned they are testing out only using EventStore for read models/views; for this to be fast enough, for you system, you need good understanding and monitoring of your application as well as how to configure projections and checkpoints in EventStore – read more at https://developers.eventstore.com/server/v21.10/projections.html#introduction

For a small application or a lab like this “getting started” there will be no problem to read from f ex the built in stream “by category” (you can, conceptually, think of category as an aggregate or entity like “Account” or “Order” and the stream contains all of those) – read more at 

Selected images from Blueprint, implementation and result

See the miro board for the full picture

the blueprint - Small part of the Order process Event Model
the implementation - code example, commandApi and CommandService
Event Store Stream - Order events
the result in the database - exempel of one Orders events as they appear in the Event Store UI

Brett erbjudande och hög IT-kompetens!

Genom ett långsiktigt partnerskap kan vi sätta långsiktiga mål vilket, enligt vår erfarenhet, leder till bäst resultat.