
Steven Stout
Staff .NET Engineer | AI-Assisted Development with Quality Gates | 12 Years Full Stack .NET, 7 Fully Remote
· first posted on LinkedIn · 7 min read
My site has 67 kinds of request, and one word in each name says if it can change anything.
The site is TheYard, a used-car auction I build in C# and .NET as my portfolio. Claude writes most of its code, and I decide what goes live.
CQRS stands for command query responsibility segregation. It sounds harder than it is. Every request a program answers either asks a question or asks for something to change. Asking which cars are for sale is a question. Placing a bid is a change. CQRS means you write those two kinds of request as two kinds of code:
- A query asks a question. It reads and changes nothing.
- A command asks for a change. It may answer with what it did.
- A handler is the one class that answers one request.
TheYard uses partial CQRS. The code is split into queries and commands, but both read and write the same database. There is no separate read database, no events copying data from one side to the other and no event sourcing. Section 5 explains why.
The site has 45 queries, 22 commands and 67 handlers, and not one class named Service. Those counts come from the site's CQRS practices page, and a test checks them against the code on every build, so they cannot drift. Here are five lessons from the change that got it there on October 23, 2026, written so you can use them in your own project tomorrow.
1. Let the name say what the code can do
Before the change, TheYard had 27 handlers, and none of their requests said what kind of request they were. They had loose names like PlaceBid, VehicleSearch and BlogOpen. To learn whether a piece of code could change anything, you had to open it and read it.
I wanted one word to answer that question for every request on the site.
In release 1.0.4.39 every request became a small record named for what it does, ending in Query when it reads and Command when it changes something. Each one got exactly one handler, named the same with Handler in place of the last word. The whole mechanism is two C# interfaces in Requests.cs, IQueryHandler and ICommandHandler, with no library between a route and the code it runs.
Here are two real ones from the blog you are reading now, in BlogHandlers.cs:
public sealed record ReadPostQuery(string Slug);public sealed record SavePostCommand(BlogPost Post);
ReadPostQuery opens this post. SavePostCommand saves one, and only the site's operator can send it. You can tell which is which from the name, before you open the file.
2. Give a question read-only access
The blog stored its posts behind one interface, IBlogStore, which carried the reads and the writes together. So the query that lists the blog's posts was handed SaveAsync, the method that saves one. Nothing used it that way, but nothing stopped a later change from using it. That was my design.
A question should not be able to change anything, even by mistake, so the fix had to take the write away from the query rather than trust everyone to leave it alone.
I split the interface in two in BlogStore.cs. IBlogReader holds the reads. IBlogStore extends it and adds the three writes:
public interface IBlogReader { ... }public interface IBlogStore : IBlogReader { Task<int> SaveAsync(...); ... }
Every query now takes IBlogReader, and only the commands take IBlogStore. The same split went into the accounts and the link tracking. The query that lists posts has no way to save a post, whatever someone types into it later.
That is the payoff of the split. A query can only read, and a command is the only path to a write, so reads and writes don't leak into each other, and a whole kind of bug is ruled out before anyone writes it.
If this looks familiar, it is the I in SOLID, interface segregation. CQRS turned it from a habit into a rule.
3. Split the service that does everything
BidService had grown to 502 lines across four files. It placed bids, reset them and read the standings. Beside it sat InventoryService in five files and MarketService, which runs the simulated auction room, and a class called Auction held all three. Every bid handler and every vehicle handler took Auction, so any read on the site could reach every write the three services had.
I needed each job to stand on its own, so a read could only reach reads.
Each job became its own handler. The shared data the handlers need became three parts in AuctionParts.cs, the stock, the bids and the room, each with a reading interface and a writing interface. The catalog query SearchVehiclesHandler takes the reading side only. The bid command PlaceBidHandler reads the vehicle the same way, then writes through IBidWriter and nothing else.
Auction and the three services are gone, and nothing in that code is named Service today. The change touched 121 files, wide and shallow: mostly renames.
I know I'm not alone here. Anyone who has opened a 500-line service class knows this one.
4. Let a test hold the rule
Nobody should have to remember the rule. I wanted the build to catch a broken one before a reviewer had to.
CqrsTests.cs holds six checks, and each reads the compiled C# on every build:
- every handler is exactly one query handler or one command handler, named for its request
- every query and every command has exactly one handler, and is handled as what its name says
- a query handler is handed no store and no writer
- a query handler is handed nothing with a method that starts with Save, Write, Delete, Add, Remove or a similar verb, whatever the interface is called
- no class in that code is named Service
- the counts on the practices page match the code
The tests went red on the old code before the change, which proved they could fail. Two days later, on October 25, I tightened the fourth check to read what an interface can do instead of trusting its name. To prove it, I planted one write method on a reader interface, and the build went red at once with the handler's name and the method it could reach.
5. Split the code, not the database
The CQRS articles I found first spent their time on separate read and write databases, events that keep the two in step, and event sourcing. I had to decide how much of that TheYard needs.
I started with the people who wrote about it first. Martin Fowler's CQRS article, July 14, 2011, warns that the full pattern adds risky complexity to most systems and belongs in the parts that need it. Microsoft's CQRS pattern page, updated February 21, 2025, calls one shared database the basic form and lists what separate stores cost: keeping them in step, and reads that can be behind the writes. Greg Young's CQRS Documents trace the idea to Bertrand Meyer's command-query separation and treat event sourcing as a good pairing but an optional one.
So TheYard stops at partial CQRS: the queries and the commands read and write the same database. The site does run two databases, Azure SQL and Cosmos DB, but that is a different choice. Neither one is a read copy of the other, and each serves the queries and the commands for its own data, with no queue or bus between a read side and a write side. A bid's new price has to be readable by the buyer the moment it lands, and a second store for reads would put that at risk for a speed the site does not need. If a read ever gets too slow for the store that holds the writes, that is the day to add a second one.
More from the same change
- Opening a page can be a command. When you open a blog post, the site keeps a count of the read. That makes the request a command,
RecordReadCommand, even though it feels like a read. Name a request by what it does, not by what it feels like. - No mediator library. I looked at MediatR and a hand-written dispatcher and kept neither. Each feature maps its route straight to its handler, so "go to definition" on a route lands on the code that runs.
- The rest followed the same evening. The 24 reads behind the site's admin pages became 21 queries and 3 commands in release 1.0.4.43.
- It sits inside two earlier rules. CQRS here is one rule inside the site's onion layers and its vertical slices: the onion and SOLID and the onion cut into vertical slices. Jimmy Bogard's Vertical Slice Architecture, April 19, 2018, makes the same point: organize code by request, and each request is already a command or a query.
The full decision, with what was weighed and what was left out, is ADR-115: A request is a query or a command.
A simple way to remember:
- Name → Query or Command
- Question → read-only access
- Big service → one handler per job
- Rule → a test holds it
- Database → one, for reads and writes
Which class in your code can change data when it only needs to read it?
References
- CQRS, Martin Fowler, martinfowler.com, July 14, 2011
- Command Query Separation, Martin Fowler, martinfowler.com, December 5, 2005
- CQRS pattern, Azure Architecture Center, Microsoft Learn, updated February 21, 2025
- CQRS Documents, Greg Young, uploaded November 2010
- Vertical Slice Architecture, Jimmy Bogard, April 19, 2018
- CQRS, the practices, TheYard, read November 16, 2026 at release 1.0.5.52
8 reads on TheYard0 this week
