CQRS in .NET: The Most Overengineered Solution for Simple Problems
What is CQRS and Why Do People Choose It?
As software systems grow in complexity, we often reach for architectural patterns that promise to solve our problems. Command Query Responsibility Segregation (CQRS) is one such pattern that’s gained significant popularity in the .NET ecosystem.
However, before we dive into why it might be overengineered for many scenarios, let’s understand what it actually is and how it’s typically implemented.
What is CQRS and Why Do People Choose It?
At its core, CQRS separates an application’s read and write operations into different models. The principle comes from Bertrand Meyer’s Command-Query Separation (CQS) principle, which states that every method should either be a command that performs an action, or a query that returns data, but not both.
Let’s look at a basic implementation that most tutorials will show you:
- Traditional Approach [ Everything in one place ]
// Traditional approach - Everything in one place
public class ProductService
{
private readonly ApplicationDbContext _context;
public async Task<Product> GetProduct(int id)
{
return await…