Skip to main content
SEMastery

Design Patterns

Explore design patterns topics and best practices in the .NET ecosystem.

Level:
42 articles

Simple Messaging in .NET with Redis Pub/Sub: A Beginner's Guide

Learn Redis Pub/Sub in .NET with StackExchange.Redis using simple words, a real-life analogy, clean async C# code, diagrams, and when to use it safely.

13 minredis · pub-sub

Refactoring a Modular Monolith Without MediatR in .NET

Learn to remove MediatR from a .NET modular monolith using plain handlers and a tiny dispatcher, with CQRS, pipeline behaviors, and clear module boundaries.

13 minmodular-monolith · mediatr

CQRS Pattern with MediatR in .NET: A Friendly Guide

Learn the CQRS pattern with MediatR in .NET using simple words, clear diagrams, and real C# code. Beginner friendly, with pitfalls and licensing notes.

13 minCQRS · MediatR

Lightweight In-Memory Message Bus Using .NET Channels

Build a fast, thread-safe in-memory message bus in .NET using System.Threading.Channels, with a friendly pub/sub design, full code, and the safety warnings you need.

15 minChannels · message bus

Scaling the Outbox Pattern in .NET: From Hundreds to Billions of Messages

Scale the Outbox Pattern in .NET to billions of messages a day with batching, indexes, SKIP LOCKED, and parallel workers — explained simply with diagrams.

13 minoutbox pattern · scalability

CQRS Pattern in .NET: The Way It Should Have Been From the Start

A friendly, hands-on guide to the CQRS pattern in .NET 10. Learn commands, queries, handlers, diagrams, and when to actually use it.

12 mincqrs · dotnet

Specification Pattern in EF Core: Flexible Data Access Without Repositories

Learn the Specification pattern in EF Core to build reusable, testable, composable queries without piling up repository methods or hiding IQueryable.

13 minspecification pattern · EF Core

Building a Better MediatR Publisher With Channels (and Why You Shouldn't)

Build a custom MediatR INotificationPublisher using System.Threading.Channels for background events in .NET, then learn why a queue this simple can quietly lose your data.

11 minMediatR · Channels

Using MassTransit with RabbitMQ and Azure Service Bus in .NET

Learn how MassTransit lets one set of .NET code run on both RabbitMQ and Azure Service Bus, with simple consumers, publishers, and config examples.

12 minmasstransit · rabbitmq

Event-Driven Microservices with Azure Service Bus in .NET

A friendly, step-by-step guide to building event-driven microservices in .NET using Azure Service Bus topics, subscriptions, and the ServiceBusProcessor.

12 minazure service bus · microservices

Implementing the Saga Pattern With Wolverine in .NET

Learn the saga pattern in .NET with Wolverine: stateful sagas, Start and Handle methods, timeouts, and compensation. Simple words, examples, and diagrams.

13 minWolverine · saga pattern

CQRS Validation with MediatR Pipeline and FluentValidation in .NET

Learn centralized CQRS validation in .NET using a MediatR pipeline behavior and FluentValidation. Simple words, clear diagrams, and real C# code.

12 minCQRS · MediatR

When Your Use Case Half-Succeeds: Designing for Partial Failure in .NET

Learn how to design .NET use cases that survive partial failure using outbox, saga, idempotency and compensation patterns, explained simply.

13 mindotnet · resilience

Messaging Made Easy with Azure Service Bus

A simple, friendly guide to Azure Service Bus messaging in .NET — queues, topics, dead-letter queues, sessions, and clean producer and consumer code.

13 minazure service bus · messaging

Decorator Pattern in ASP.NET Core: A Friendly Guide

Learn the Decorator pattern in ASP.NET Core with simple examples, Scrutor, caching and logging decorators, and clear diagrams for beginners.

12 mindecorator pattern · ASP.NET Core

Implementing the Saga Pattern with Rebus and RabbitMQ in .NET

Learn the Saga pattern in .NET using Rebus and RabbitMQ with simple real-life examples, diagrams, correlation, compensation, and full C# code you can copy.

13 minsaga pattern · Rebus

The Result Pattern in .NET: Error Handling Without Exceptions

Learn the Result pattern in .NET for clean, explicit error handling. Replace hidden exceptions with type-safe return values using simple examples, railway-oriented diagrams, code, and clear advice on when to use it.

11 minresult pattern · error handling

How to Replace Exceptions with the Result Pattern in .NET

Learn how to replace exceptions with the Result pattern in .NET for clearer, faster, and safer error handling. Simple guide with C# examples.

12 minresult-pattern · error-handling

How to Publish MediatR Notifications in Parallel in .NET

Learn how to publish MediatR notifications in parallel using a custom INotificationPublisher in .NET, with Task.WhenAll, error handling, and clear examples.

13 minMediatR · notifications

Implementing the Saga Pattern with MassTransit in .NET

Learn the Saga pattern in .NET with MassTransit state machines — states, events, correlation, persistence, retries, and compensation, explained in simple, friendly steps.

14 minsaga · masstransit

Stop Conflating CQRS and MediatR: They Are Not the Same Thing

CQRS and MediatR are two different ideas. Learn what each one really does, why people mix them up, and how to use CQRS in .NET with or without MediatR.

12 minCQRS · MediatR

Implementing Idempotent REST APIs in ASP.NET Core

Learn to build idempotent REST APIs in ASP.NET Core with idempotency keys, an endpoint filter, and a safe store so retried requests never run twice.

15 minidempotency · ASP.NET Core

MassTransit Outbox Pattern with EF Core and MongoDB in .NET

Learn the transactional outbox pattern in .NET using MassTransit with EF Core and MongoDB so your database and message broker never fall out of sync.

13 minMassTransit · Outbox Pattern

The Inbox Pattern in .NET: Handle Each Message Exactly Once

Learn the Inbox Pattern in .NET to stop duplicate messages from causing double charges and double emails. Simple real-life examples, EF Core code, diagrams, and how it pairs with the Outbox Pattern.

11 mininbox pattern · idempotent consumer

How to Use Domain Events to Build Loosely Coupled Systems in .NET

Learn how domain events keep .NET code loosely coupled. A simple analogy, full C# examples, diagrams, timing tips, and common mistakes explained for beginners.

13 mindomain events · DDD

Getting Started with Event Sourcing in .NET with Marten and PostgreSQL

Learn event sourcing in .NET using Marten and PostgreSQL. Store events, build aggregates and projections, and read state the easy, beginner-friendly way.

14 minevent-sourcing · marten

The Idempotent Consumer Pattern in .NET (And Why You Need It)

A friendly .NET guide to the idempotent consumer pattern: stop duplicate messages from double-charging customers using message ids, transactions, and EF Core.

17 minmessaging · idempotency

Event-Driven Architecture in .NET with RabbitMQ: A Beginner's Guide

Learn event-driven architecture in .NET with RabbitMQ using simple words, real-life examples, exchanges, queues, and clean async C# code you can copy.

13 minrabbitmq · event-driven

Message Ordering in .NET, Solved From First Principles

Learn message ordering in .NET from scratch: why messages arrive out of order, and how partition keys, sessions, and single consumers fix it.

14 minmessage ordering · messaging

Orchestration vs Choreography in .NET: A Friendly Guide

Orchestration vs choreography explained simply for .NET developers — events, commands, sagas, trade-offs, and when to pick each, with clear C# examples.

13 minorchestration · choreography

Building a Custom Domain Events Dispatcher in .NET (No MediatR Needed)

Build your own domain events dispatcher in .NET with EF Core. Simple analogy, full C# code, diagrams, and timing tips — no paid MediatR license required.

14 mindomain events · DDD

Implementing the Unit of Work Pattern in EF Core

Learn the Unit of Work pattern in EF Core with simple C# examples, diagrams, transactions, and when DbContext alone is already enough for you.

14 minunit of work · EF Core

MassTransit with RabbitMQ and Azure Service Bus: Is It Worth a Commercial License?

MassTransit went commercial in v9. See how it works with RabbitMQ and Azure Service Bus, what the new license costs, and whether it is worth paying for.

12 minmasstransit · rabbitmq

The Outbox Pattern in .NET: Never Lose a Message Again

Learn the Outbox Pattern in .NET with simple, real-life examples. Save your data and your messages in one transaction so a broker outage can never lose an event. Includes EF Core code, diagrams, and best practices.

12 minoutbox pattern · messaging

MediatR and MassTransit Going Commercial: What This Means for You

MediatR and MassTransit are now commercially licensed. Learn what changed, who pays, who stays free, and how to plan your .NET project calmly.

12 minMediatR · MassTransit

Getting Started With NServiceBus in .NET: A Beginner's Guide

Learn NServiceBus in .NET from scratch: endpoints, commands, events, handlers, retries, and pub-sub. Simple words, real-life examples, code, and diagrams.

15 minNServiceBus · messaging

Request-Response Messaging Pattern With MassTransit in .NET

Learn the request-response messaging pattern with MassTransit in .NET using IRequestClient, timeouts, and multiple response types with simple examples.

11 minmasstransit · messaging

The Repository Pattern in .NET: A Friendly, Complete Guide

Learn the Repository Pattern in .NET with simple real-life examples, EF Core code, diagrams, and honest advice on when to use it and when to skip it.

11 minrepository pattern · EF Core

Idempotent Consumer: Handling Duplicate Messages in .NET

Learn the Idempotent Consumer pattern in .NET to safely handle duplicate messages, prevent double charges, and build reliable message-driven systems.

14 minmessaging · idempotency

Complete Guide to Amazon SQS and Amazon SNS with MassTransit

A friendly, step-by-step guide to messaging in .NET using Amazon SQS, Amazon SNS, and MassTransit — queues, topics, consumers, retries, and dead-letter handling.

13 minamazon sqs · amazon sns

Outbox Pattern for Reliable Microservices Messaging in .NET

Learn the Outbox Pattern in .NET to stop losing messages between microservices. Simple analogy, EF Core code, diagrams, and best practices for reliable messaging.

13 minoutbox pattern · microservices

Event Sourcing for .NET Developers: A Simple Introduction

Learn event sourcing in .NET from scratch. Store every change as an event instead of just the current state, with a real-life bank-passbook analogy, diagrams, code, aggregates, projections, and when to use it.

11 minevent sourcing · CQRS