.NET 8 Microservices: DDD, CQRS, Vertical/Clean Architecture

Mehmet Ozkaya
5 min readMar 18, 2024


I have just FULLY RENEWED of my course — .NET 8 Microservices: C# 12, DDD, CQRS, Vertical/Clean Architecture.

This is step-by-step development of reference microservices architecture that include microservices on .NET platforms which used ASP.NET Web API, Docker, RabbitMQ, MassTransit, Grpc, Yarp API Gateway, PostgreSQL, Redis, SQLite, SqlServer, Marten, Entity Framework Core, CQRS, MediatR, DDD, Vertical and Clean Architecture implementation with using latest features of .NET 8 and C# 12.

Get Udemy Course with limited discounted coupon— .NET 8 Microservices: C# 12, DDD, CQRS, Vertical/Clean Architecture.

There is a couple of microservices which implemented E-Commerce Microservices, those are Catalog, Basket, Discount, Ordering, YarpApiGateway microservices and Shopping.Web Client Application.

These microservices data’s will store NoSQL and Relational databases
with communicating over gRPC and RabbitMQ Event Driven Communication and also using Yarp API Gateway for client operations.

Lets deep dive into internal architectures of microservices:

Catalog Microservice

  • Using ASP.NET Core Minimal APIs and latest features of .NET8 and C# 12
  • Vertical Slice Architecture implementation with Feature folders and single .cs file includes different classes in one file
  • CQRS implementation using MediatR library
  • CQRS Validation Pipeline Behaviors with MediatR and FluentValidation
  • Use Marten library for .NET Transactional Document DB on PostgreSQL, so Product microservices database will be PostgreSQL but acting as a Document DB using Marten library
  • Use Carter for Minimal API endpoint definition
  • Cross-cutting concerns Logging, Global Exception Handling and Health Checks
  • Implement Dockerfile and docker-compose file for running Product microservice and PostgreSQL database in Docker environment

Basket Microservice

  • All above Catalog Microservice items into Basket Microservice
  • ASP.NET 8 Web API application, Following REST API principles, CRUD
  • Using Redis as a Distributed Cache over basketdb
  • Implements Proxy, Decorator and Cache-aside patterns
  • Consume Discount Grpc Service for inter-service sync communication to calculate product final price
  • Publish BasketCheckout Queue with using MassTransit and RabbitMQ
  • Containerize Basket Microservices with Redis and PostgreSQL database

Discount Microservice

  • ASP.NET gRPC Service application
  • Build a Highly Performant inter-service gRPC Communication with Discount and Basket Microservice
  • gRPC Communications, Proto files CRUD operations
  • Exposing Grpc Services with creating Protobuf messages
  • SQLite database connection and containerization
  • Entity Framework Core ORM — SQLite Data Provider and Migrations to simplify data access and ensure high performance
  • N-Layer Architecture implementation
  • Containerize Discount Microservices with SQLite database using Docker Compose

Ordering Microservice

  • ASP.NET Core Web Minimal APIs for building fast HTTP APIs-fully functioning REST endpoints for CRUD operations
  • Implementing DDD, CQRS, and Clean Architecture with using Best Practices
  • Apply SOLID Principles, Dependency Injection
  • Raise and handle Domain Events & Integration Events
  • Entity Framework Core Code-First Approach, Migrations, DDD Entity Configurations
  • Clean Architecture implementation on Entity Framework and SQL Server
  • Consuming RabbitMQ BasketCheckout event queue with using MassTransit-RabbitMQ Configuration
  • Containerize Ordering Microservices with SQL Server database

Microservices Async Communication w/ RabbitMQ & MassTransit

  • Async Microservices Communication with RabbitMQ Message-Broker Service
  • Using RabbitMQ Publish/Subscribe Topic Exchange Model
  • Using MassTransit for abstraction over RabbitMQ Message-Broker
  • Publishing BasketCheckout event queue from Basket microservices and Subscribing this event from Ordering microservices
  • Create RabbitMQ EventBus.Messages library and add references Microservices
  • Containerize RabbitMQ Message Queue system with Basket and Ordering microservices using Docker Compose

YarpApiGateway Microservice

  • Develop API Gateways with Yarp Reverse Proxy applying Gateway Routing Pattern
  • Yarp Reverse Proxy Configuration; Route, Cluster, Path, Transform, Destinations
  • Rate Limiting with FixedWindowLimiter on Yarp Reverse Proxy Configuration
  • Containerize YarpApiGateway Microservices using Docker Compose

Shopping Web Client Application

  • ASP.NET Core Razor Web Application with Bootstrap 4 and Razor template
  • Consume YarpApiGateway APIs using Refit Library with Generated HttpClientFactory
  • Bootstrap 4 Theme Implementation
  • ASP.NET Core Razor Tools — View Components, Partial Views, Tag Helpers, Model Bindings and Validations, Razor Sections etc.
  • Containerize Shopping Web Client Application using Docker Compose

Patterns, Principles, Libraries, Communications, Best Practices

  • Implement different architecture styles: DDD, Vertical Slice and Clean Architecture
  • Implement different patterns: SOLID Principles, Dependency Injection principles, CQRS and Mediator Pattern, Options Pattern, Proxy and Decorator Pattern, Publish-Subscribe Pattern, Api Gateway Pattern, Cache-aside Pattern
  • Implements different Database types: NoSQL and Relational: Transactional DocumentDB, PostgreSQL, SQLite, SQL Server, Distributed Caches (Redis) and Message brokers async communication with RabbitMQ and Masstransit library
  • Use Popular .NET libraries: Carter, Marten, MediatR, FluentValidation, Mapster, MassTransit, EF Core, Refit
  • Implement different communication styles: Sync and Async communication between microservices
  • Build a Highly Performant inter-service gRPC Communication with Discount and Basket Microservice
  • Microservices Async Communication Publish Subscribe Pattern w/ RabbitMQ & MassTransit for Checkout Basket Between Basket-Ordering Microservices
  • Building API Gateways with Yarp Reverse Proxy applying Gateway Routing Pattern

Source Code on Live GitHub Repository

You can reach latest EShop Microservices GitHub Repository in this link.

I am also developing aspnetrun repositories on GitHub with latest .NET 8 and create courses from these repositories. So this course is the main repository of the aspnetrun ecosystem and this is a lively course and evolves with repository changes.

Use Limited Discounted Coupon

Get Udemy Course with limited discounted coupon — .NET 8 Microservices: C# 12, DDD, CQRS, Vertical/Clean Architecture.

This course is designed for software developers and architects
and includes:

  • %95 of Hands-on Design and Development Activities
  • Apply best practices with cloud-native microservices design patterns and principles
  • Latest features of C# 12, .NET 8 and ASP.NET 8 like Minimal APIs, primary constructors..

Get Udemy Course with limited discounted coupon — .NET 8 Microservices: C# 12, DDD, CQRS, Vertical/Clean Architecture.



Mehmet Ozkaya

Software Architect | Udemy Instructor | AWS Community Builder | Cloud-Native and Serverless Event-driven Microservices https://github.com/mehmetozkaya