Microservice pattern demos (Saga, EventSourcing, CQRS...) running on .NET Aspire
Microservice pattern demos (Saga, EventSourcing, CQRS...) running on .NET Aspire
This repository is a set of focused, production-inspired demos showing how to implement complex microservice patterns on .NET using .NET Aspire.
The goal is simple:
Strip away domain noise and framework boilerplate so you can clearly see
what each pattern does, why you need it, and how to implement it.
If you care about high-quality microservice architecture on .NET, this repo is for you.
Most examples of microservices either:
This project takes a different approach:
Use it as a learning lab, a reference implementation, or a starting point for your own experiments.
Problem:
How do you query data efficiently when it lives in multiple distributed stores, and reads start to outnumber writes?
What this demo shows:
Problem:
How do you model complex aggregates and still keep updates atomic, auditable, and easy to reason about?
What this demo shows:
Problem:
How do you implement a business transaction spanning multiple microservices without using distributed transactions?
What these demos show:
Orchestration-based Sagas
Choreography-based Sagas
You’ll see how to handle success, failure, retries, and compensation across services.
Problem:
How do you ensure that when a service updates its database and publishes an integration event, either both happen or neither do?
What this demo shows:
This pattern underpins reliable event-driven communication between services.
Problem:
How do you build event-driven integrations where external systems subscribe to your events instead of you polling them?
What this demo shows:
This is the backbone for “notify me when X happens” style integrations.
Standardizing event envelopes using the CloudEvents specification makes it much easier to:
The demos show how to emit and consume events using the CloudEvents format.
To reduce tight coupling between parts of your system, this repo includes a Mediator implementation with the same goals as libraries like MediatR, but with a fresh implementation (after MediatR’s license change).
You’ll see how to:
Distributed systems fail in messy ways.
The Circuit Breaker demos show how to:
This is one of the most important patterns for resilient microservices.
At a high level:
MicroservicePatterns.AppHost
The .NET Aspire AppHost project that wires everything together and orchestrates the services.
patterns/
The individual pattern demos (CQRS, Event Sourcing, Saga, etc.).
Each pattern is organized to keep the focus on the pattern itself, not on an over-engineered domain.
EventBus, EventBus.Kafka
Infrastructure for publishing/consuming integration events.
Includes a Kafka-based implementation to show how patterns play with a real event bus.
Mediator
The custom Mediator implementation used by the demos.
MicroservicePatterns.Shared, MicroservicePatterns.ServiceDefaults, MicroservicePatterns.DatabaseMigrationHelpers
Shared abstractions, defaults, and helpers to keep the pattern demos clean and readable.
You can browse the patterns/ folder and open the pattern you’re interested in; each is built to be read in isolation.
Clone the repo:
git clone https://github.com/daohainam/microservice-patterns.git
cd microservice-patternsRestore and build:
dotnet restore
dotnet buildStart the Aspire app host:
dotnet run --project MicroservicePatterns.AppHostOpen the Aspire dashboard (if enabled) and explore the running services and patterns.
From there, pick a pattern, follow the comments in the code, and run through typical scenarios (success paths, failures, compensations, etc.).
This repository is designed to be used together with detailed video explanations:
Pattern deep dives (CQRS, Event Sourcing, Saga, Outbox, Webhook, etc.) Playlist: https://www.youtube.com/playlist?list=PLRLJQuuRRcFlOIjMY9w5aoCf6e368oxez
Getting started with .NET Aspire via a Core Banking (fake) exercise A practical intro to building on Aspire, which helps when navigating this repo: https://youtu.be/QVPYhhp-Nkg
Watch a video, then jump into the corresponding pattern in this repo and step through the code.
.NET developers who want to go beyond basic Web APIs and understand real microservice patterns.
Architects and tech leads evaluating .NET Aspire for microservice platforms.
Learners and teachers looking for clean, focused examples to explain advanced patterns.
If you use this repo in a talk, workshop, or course, feel free to link back and share how you’re using it.
This project is deliberately opinionated and minimal, not a full production system. It’s meant as a reference and teaching tool.
If you find bugs, have questions, or want to propose improvements to the demos, contributions and discussions are very welcome via issues and pull requests.
No open issues yet, or sync has not completed.