CQRS and MediatR in .NET: Separating Commands and Queries

9 min readFebruary 9, 2026
CQRS .NETMediatRCommand Query Separation.NET mediator patternCQRS tutorialMediatR handlersEvent sourcing .NET.NET architecture patterns

# CQRS and MediatR

CQRS separates write operations (commands) from read operations (queries). In .NET, MediatR is often used to organize this flow with explicit handlers and pipeline behaviors.

Why Teams Adopt CQRS

  • Different optimization needs for reads vs writes
  • Clearer intent in complex business workflows
  • Better alignment with event-driven and domain-centric systems
  • Applying MediatR Effectively

    Commands

  • Change system state
  • Validate business invariants
  • Return minimal results (often IDs or status)
  • Queries

  • Retrieve data optimized for read scenarios
  • Project directly to read models/DTOs
  • Avoid side effects
  • Pipeline Behaviors

  • Cross-cutting concerns like validation, logging, and transaction boundaries
  • Keep handlers focused on core behavior
  • When CQRS Is Overkill

  • Small CRUD apps with simple logic
  • Teams without clear architectural ownership
  • Systems where read/write complexity is nearly identical
  • Conclusion

    CQRS with MediatR can dramatically improve clarity in complex domains, but it should be introduced for real complexity, not as default ceremony.

    I can help evaluate whether CQRS fits your domain and rollout strategy.

    Related Articles

    Have a Flutter Project?

    I build high-performance Flutter applications for iOS, Android, and web.

    Get in Touch