
Introduction
When building enterprise applications, we often start with a simple CRUD approach. It works fine until it faces some issues and system grows more we may encounter several challenges.
As systems grow, business rules become complex, read traffic increases, and scalability becomes critical the traditional “one model for everything” approach starts to show cracks.
That’s where CQRS (Command Query Responsibility Segregation) comes in and resolves these issues.
In this article, I’ll walk you through:
What CQRS really means in simpler way
Why it matters in real-world systems
How to implement it using MediatR in .NET 10
Clean project structure
Practical tips from production experience
What is CQRS (Command Query Responsibility Segregation)?
CQRS is a design pattern that separates read operations (queries) from write operations (commands) in an application.
Instead of using the same model for both reading and writing data, CQRS splits them into two different models:
Command Model → Handles writes (Create, Update, Delete)
Query Model → Handles reads (Fetch, Search, Get)
This improves scalability, maintainability, and clarity in complex systems.
CQRS separates read operations from write operations. We never mix command and queries.
Basic Idea
Traditional CRUD approach:
Controller → Service → Repository → DatabaseCQRS approach:
Command → Command Handler → Domain → Database
Query → Query Handler → Read Model → DatabaseVisual Understanding

Why Use CQRS?
Let’s think practically. In most applications:
Reads happen far more than writes.
Reads need performance.
Writes need validation and business rules.
Trying to optimize both using the same model leads to complexity.
CQRS allows:
Separate scaling of reads & writes
Optimized read models
Cleaner business logic
Better testability
Clear architectural boundaries
If you’re already using Clean Architecture CQRS fits naturally.
1. Clear Separation of Concerns
Reads and writes have different responsibilities.
2. Scalability
Read traffic can scale independently
Write side can have complex business logic
Read side can use caching or projections
3. Performance Optimization
Read models can be optimized for UI
Write models focus on business rules
4. Works Great with:
Clean Architecture (which you’re already using)
MediatR
Event Sourcing
Microservices
Where MediatR Fits In
MediatR is a lightweight mediator library that helps implement CQRS cleanly.
Instead of controllers directly calling services:
Controller → Service → Repository
We do:
Controller → MediatR → Handler
Each request (command/query) has exactly one handler.
This removes tight coupling and improves maintainability.
Project Structure (.NET 10 Web API)
A clean CQRS structure typically looks like:
Application
├── Commands
├── Queries
├── Handlers
Domain
Infrastructure
API (Controllers)
This aligns perfectly with Clean Architecture principles.
Step-by-Step: CQRS with MediatR in .NET 10
Create a new WebAPI project in .NET 10 or you can you your existing project and implement CQRS with MediatR in .NET 10
Then you will follow the below.
Install Required Packages
dotnet add package MediatR
dotnet add package MediatR.Extensions.Microsoft.DependencyInjection
dotnet add package Microsoft.EntityFrameworkCore.SqlServerRegister MediatR in Program.cs

Join the conversation! Your thoughts help the community grow.