What is CQRS - separating reads and writes, and when not to use it?
CQRS explained through commands, handlers, queries, read models, eventual consistency, and the situations where separating reads and writes is unnecessary.
What is CQRS - separating reads and writes, and when not to use it?
Many applications are using the same object model for changing data and displaying data. This is a reasonable starting point, but over time the read screen may need joins and calculated fields while the write operation is needing strict business rules and validation. One model is then becoming stretched between two different responsibilities.
Command Query Responsibility Segregation (CQRS) separates commands which change state from queries which read state. In this article, we are going to see the idea, a worked news article example, the trade-offs and when CQRS is not the right choice.
TL;DR Summary
- A command asks the system to change state and may have side effects.
- A query returns information and should not change state.
- CQRS can use different models or stores for writes and reads.
- Separation helps when read and write workloads or models are genuinely different.
- Eventual consistency means a read model may lag behind a successful command.
- Do not use CQRS for every CRUD screen, because the extra flow creates operational cost.
Challenges
Read and write conflict
A write model must protect invariants, while a read model wants convenient projections. If one Entity Framework entity is used for both, a display requirement can expose persistence details or weaken the write boundary. This creates a slow ripple effect whenever the screen changes.
Different scale
A news site may receive many article reads for each editorial update. Scaling one model for both workloads can be inefficient. Separating the paths may help, but only if the measured load justifies another deployment and synchronization process.
Consistency expectations
After an editor publishes an article, a query model may update a short time later. If the user immediately searches and cannot see the article, the product must explain or avoid that inconsistency. Eventual consistency is not only a technical term, it is a customer behaviour decision.
What is CQRS?
CQRS is an architectural pattern which separates the model used to perform state-changing commands from the model used to execute read queries.
In simple terms, a command is “publish article 42”, while a query is “show all published articles for topic markets”. The command protects the rule and the query returns a shape convenient for the screen. They may share a database at first, separate stores are optional.
Why CQRS is important?
The separation makes different reasons to change explicit. A report can add a calculated column without changing the aggregate which protects a business invariant. A high-read workload can use a denormalized read model, while writes remain normalized and controlled.
The following diagram depicts a command producing state and a read model being updated for queries,

Commands and queries
Command
A command expresses an intention to change state. It should be named with a verb such as PublishArticle or ApproveFund. The handler validates permission, loads the domain object, applies the rule and commits the change.
public sealed class PublishArticle
{
public int ArticleId { get; set; }
public string Editor { get; set; }
}
The command should be safe to retry only when its handler is idempotent or has a deduplication key. If the handler publishes an article and sends a message, a retry must not create duplicate notifications.
Query
A query asks for information and should not change state. It can return a DTO designed for the caller rather than an entity designed for persistence.
public sealed class ArticleListItem
{
public int Id { get; set; }
public string Title { get; set; }
public DateTime PublishedOn { get; set; }
}
The query can use a read-optimized SQL statement or projection. It should not call a command as a side effect, because the caller expects a read to be safe and repeatable.
Eventual consistency
A command may save the write model and publish an event such as ArticlePublished. A projector consumes that event and updates a read table. Between these actions, the read table can be behind. We should expose the state honestly and monitor the processing delay, otherwise users may think the publish action failed.
Use a correlation identifier to trace the command, event and projection. Keep failed events visible and retryable. If the business cannot tolerate any lag, a separate read model may not be appropriate for that operation.
Worked command and query code
Find below a command which is expressing an intention,
public sealed class PublishArticleCommand
{
public int ArticleId { get; set; }
public string Editor { get; set; }
}
public sealed class PublishArticleHandler
{
private readonly IArticleRepository repository;
private readonly IUnitOfWork unitOfWork;
public PublishArticleHandler(
IArticleRepository repository,
IUnitOfWork unitOfWork)
{
this.repository = repository;
this.unitOfWork = unitOfWork;
}
public void Handle(PublishArticleCommand command)
{
Article article = repository.Find(command.ArticleId);
if (article == null)
throw new InvalidOperationException("Article was not found");
article.Publish(command.Editor);
unitOfWork.SaveChanges();
}
}
The command is loading the aggregate and applying the business rule, it is not returning a screen model. A retry should be safe when Publish is checking the current state or when a command identifier is being recorded.
The query is having a read model which is designed for the list screen,
public sealed class ArticleListItem
{
public int Id { get; set; }
public string Title { get; set; }
public string AuthorName { get; set; }
public DateTime PublishedOn { get; set; }
}
public sealed class ArticleListQuery
{
private readonly NewsDbContext context;
public ArticleListQuery(NewsDbContext context)
{
this.context = context;
}
public IList<ArticleListItem> Execute(string topic)
{
return context.Articles
.Where(x => x.Topic == topic && x.Status == "Published")
.Select(x => new ArticleListItem
{
Id = x.Id,
Title = x.Title,
AuthorName = x.Author.Name,
PublishedOn = x.PublishedOn.Value
})
.ToList();
}
}
It is not mandatory that the query is using another database from day one. We can first separate the code and use the same EF6 database, then add a projection when read scale or shape is requiring it.
When not to use CQRS?
Find below some cases where CQRS is becoming overhead,
- A simple administration form is only creating, reading, updating and deleting one record.
- The read and write shape is almost identical and is not changing independently.
- The team is not having monitoring for event delivery or projection lag.
- The business requires an immediate read-after-write result for every operation.
- There is no measured scale or change pressure to justify another model.
In these cases, use an application service with EF6 and keep the code clear. CQRS is not a replacement for good domain design, and an event bus is not making a CRUD screen more mature. We should be using it when it is removing a real problem, otherwise it is adding a new operational blind spot.
Must Do and Don’ts
- Must Do: Make commands explicit and validate authorization before state change.
- Must Do: Track projection lag and failed messages when reads are asynchronous.
- Don’t: make a query change state as a hidden side effect.
- Don’t: promise immediate read model consistency when the system is eventually consistent.
- Be mindful: Separate command and query code first, separate databases only when the evidence is requiring it.
Without a separate understanding of reads and writes, we are reacting to every report change breaking a write rule. CQRS can make the boundary proactive, but it is also creating projection lag and operational work. In our case, we should use the pattern only when the read and write pressure is demonstrated, otherwise a simple application service is giving the better trade-off.
When should we not use CQRS?
Do not use CQRS for a simple Create, Read, Update and Delete (CRUD) administration screen which creates, edits and lists a small record with the same shape. Two models, handlers, events and deployment processes will add ceremony without removing a real pain. Start with a clear application service and Entity Framework 6, then revisit when the read/write difference is demonstrated.
CQRS also does not automatically solve poor domain design. If the command contains no rules and the query only hides an inefficient join, the pattern has renamed the problem. Measure response time, read/write volume, change frequency and operational cost before splitting stores.
How should we introduce it?
Start with separate command and query interfaces while keeping one database. Add a read projection for one screen which genuinely needs a different shape. Introduce asynchronous events only when the team can monitor and repair the projection. This incremental approach keeps the trade-off visible.
Wrap up
In this article, we have looked at CQRS, commands, handlers, queries, read models, eventual consistency and when not to use the pattern. Thanks for reading this article. In the next article, I will walk you through Single Page Application architecture with AngularJS and Web API.
Related Posts
Monolith vs Microservices - should we start with microservices?
Monoliths and microservices compared through modular boundaries, extraction signals, scaling, team ownership, distributed failure, and practical starting criteria for growing teams.
Event Sourcing - storing the history, not just the state
Event Sourcing explained through state versus event history, commands, aggregates, append-only stores, projections, snapshots and versioned events for practical guidance.
Microservices - Part 1
Microservices Part 1 explains Conway's Law, modular monoliths, service ownership, distributed data, deployment independence and the hidden costs of service boundaries.