Skip to content

Top 30 CQRS Interview Questions and Answers [2026]

October 12, 2026 12 min read
CQRS interview guide by Second Talent
TL;DR: CQRS (Command Query Responsibility Segregation) means using one model to change data and a different model to read it. Interviewers test when it is worth the cost, how read models stay in sync, and how to handle the lag. It does not require two databases or event sourcing.

Martin Fowler's CQRS entry, dated July 14, 2011, carries a warning most summaries leave out: "for most systems CQRS adds risky complexity." Fifteen years on, that sentence is still the best interview filter.

Strong candidates can say when they would not use CQRS. The tooling moved in 2025 and 2026: MediatR went commercial, and KurrentDB added indexes that replace some read models.

Key takeaways
  1. 1Fowler credits Greg Young as the first person he heard describe CQRS. It grew out of Bertrand Meyer's command-query separation.
  2. 2A projection must store its checkpoint in the same transaction as its rows, or a crash replays events twice.
  3. 3MediatR 13 moved to a dual commercial license on July 2, 2025. It is free only for companies under $5 million in revenue.
  4. 4Marten 9, released May 21, 2026, dropped runtime code generation and can be published ahead of time.

CQRS Basics

1. What is CQRS?

CQRS splits a system's model in two. The command side takes requests that change state, checks business rules and saves the result. The query side answers reads from data shaped for each screen or API.

In Fowler's words, "you can use a different model to update information than the model you use to read information." The two models can share one database or live in separate stores. The point is that neither has to bend to suit the other.

Grid of three paths through a CQRS service: the command path loads the aggregate and writes the model and outbox in one transaction, the projection skips applied positions and writes the read table with its checkpoint, and the query path reads with plain SQL and writes nothing.

2. How is CQRS different from CQS?

CQS, command-query separation, is Bertrand Meyer's rule for methods. A method either changes state or returns data, never both. stack.pop() breaks it.

CQRS applies the same split to whole models and often to whole data stores. CQS is a coding habit. CQRS is an architecture decision with real running costs.

3. When is CQRS worth it?

When reads and writes differ a lot. Signs:

  • Writes enforce complex rules, but reads are flat lists and dashboards.
  • Reads outnumber writes by orders of magnitude and need their own scaling.
  • Screens join data that the write model keeps apart.
  • Many users work on the same data at once, so contention matters.

Fowler adds that it fits parts of a system, a bounded context, rather than the whole. For a CRUD app it adds cost with nothing to show for it.

Two by two grid of when CQRS pays off, by business rule complexity and the difference between reads and writes: plain CRUD when both are low, one rich model when rules are complex but reads simple, read models only for heavy screens over CRUD writes, and full CQRS when both are high.

4. Does CQRS need two databases?

No. The simplest CQRS uses one database. Commands write normalized tables through the domain model. Queries read from the same tables, or from views, with plain SQL into DTOs.

Separate stores come later, when reads need a different engine, such as a search index, or must scale on their own. Each extra store adds a sync process to build and watch.

5. Does CQRS need event sourcing?

No. They pair well, because events are a natural way to feed read models. But a command side can store current state in ordinary tables and still have separate read models. Greg Young's CQRS documents (2010) treat them as separate patterns.

Candidates who say "CQRS means event sourcing" usually learned both from one framework.

6. Does CQRS mean eventual consistency?

Only if the read model is updated after the write commits. If the command handler updates the read table in the same transaction, reads are consistent at once. That works well inside one database.

Same transaction
  • Reads are current at once
  • Only within one database
  • Slow read updates slow every write
After commit
  • Reads lag behind writes
  • Read stores can be any engine
  • Needs checkpoints and lag alerts

Async updates buy independence and scale, and cost a lag. The team must decide how long a lag the business can accept, and design the UI for it.

The Command Side

7. What does a good command look like?

It names one business intent in the imperative, such as ChangeShippingAddress or CancelOrder. It carries only the data for that intent, plus an ID for idempotency. It is immutable.

A generic UpdateCustomer that carries every field hides the intent. The handler cannot tell a move from a typo fix. Task-based commands need a task-based UI, which is often the harder change.

8. Should a command return data?

Not query data. A command can return an acknowledgment: success or a rejection reason, the new entity's ID, and often the new version number.

Returning the version is useful. The client can then ask the read side for "version 7 or later" and know when its own change is visible. Returning a full view model couples the command to one screen.

9. Where is a command validated?

In two steps. Shape checks, such as required fields and formats, run before the handler and fail fast.

Business rules, such as "cannot cancel a shipped order," run inside the domain model, which is the only place that sees the current state.

Checking business rules against the read model is a trap. It may be stale, so the check can pass when it should fail.

10. How do you make command handling idempotent?

Give each command a unique ID from the client. The handler records processed IDs in the same transaction as the state change. A repeat with a known ID returns the first result and changes nothing.

Some commands are naturally idempotent, such as "set status to shipped." Others, such as "add 10 to the balance," are not, and need the ID check.

11. Two users change the same order at once. What happens?

Use optimistic concurrency. Each command carries the version the user loaded. The write succeeds only if the stored version still matches.

synchronized void append(String stream, long expectedVersion, List<Event> events) {
  List<Event> current = streams.computeIfAbsent(stream, k -> new ArrayList<>());
  if (current.size() != expectedVersion)
    throw new ConcurrencyException("expected v" + expectedVersion + ", found v" + current.size());
  current.addAll(events);
}

We ran this in-memory store on Java 25. Two users loaded version 1. The first deposit saved; the second failed with expected v1, found v2. The client can reload and retry, or show a conflict.

12. How do you enforce a rule that needs other data, such as a unique username?

Not by querying the read model first; two commands can both see "free." Use a constraint the write side controls. A unique index in the command database is the simplest.

In an event-sourced system, a small reservation table or a stream per username does the same job.

A good candidate also asks how bad a rare duplicate would be. Sometimes a later cleanup is cheaper than a hard guarantee.

13. Do you need a mediator or command bus?

No. A command bus routes a command to its handler and runs shared steps around it, such as logging, validation and transactions. That is useful with many handlers. A direct method call on a handler class works too.

Many .NET teams equate CQRS with MediatR. It is one dispatch library, not the pattern. See question 26 for why teams are rethinking it.

The Query Side

14. What is a projection?

A projection is code that listens to changes on the write side and updates a read model. The read model is the stored result, such as an order_summary table shaped for one screen.

Read models are disposable. If one is wrong, fix the code and rebuild it from the source of truth.

15. How do read models stay up to date?

Three common ways:

  • Same transaction: the command handler updates the read table too. Consistent at once, but only within one database.
  • Events after commit: the write side stores events or an outbox row, and a relay publishes them to projections.
  • Change data capture: a tool such as Debezium reads the database log and streams changes out.

Publishing to a broker straight from the handler, outside the transaction, loses events when the process dies between the two writes.

16. The user saves, then sees old data. How do you handle that?

Pick by how much the lag matters:

  • Return the new version from the command, and have the query wait until the read model reaches it.
  • Update the UI from the command's own data, then refresh later.
  • Push a notification when the projection catches up.
  • For the few screens that must be exact, read from the write side.

The worst option is doing nothing and hoping the lag stays under a second.

17. How do you make a projection safe to replay?

Store a checkpoint, the position of the last applied event, in the same transaction as the read model rows. On restart, continue after the checkpoint. Skip anything at or below it.

void handle(Recorded r) {
  if (r.position() <= checkpoint) return;      // already applied: safe to replay
  switch (r.event()) {
    case AccountOpened e -> balances.put(e.accountId(), 0L);
    case Deposited e -> balances.merge(e.accountId(), e.cents(), Long::sum);
  }
  checkpoint = r.position();                   // save with the row, in one transaction
}
Tested. We ran this projection on Java 25 and fed it the same two events twice. The balance stayed at 5,000 cents, not 10,000, and the checkpoint stayed at 2.

If the checkpoint lives somewhere else, such as a broker offset, a crash between the two writes applies an event twice.

18. How do you rebuild a read model without downtime?

Build the new version next to the old one. Create a new table, run the projection from position zero into it, and let it catch up to live. Then switch queries to the new table and drop the old one.

For large histories, plan for hours, not minutes. Rebuild speed is a real design limit: batching writes and turning off indexes during the rebuild both help.

19. How do you choose a store for a read model?

By the query it serves. A relational table for filtered, sorted lists. A search engine such as OpenSearch for full-text and facets. A key-value store for lookups by ID. A document store for nested views read in one go.

Start with a table in the same database. Add a second engine only when a query needs it, since each one is another thing to run and rebuild.

20. How is a read model different from a cache?

A cache is a copy of answers that can vanish at any time and be refetched from the source. A read model is a maintained view that queries depend on. It is built by the projection, not filled on a cache miss.

So a read model needs what a cache does not: a checkpoint, a rebuild process and monitoring of its lag.

21. Can one read model combine data from several services?

Yes. A projection can subscribe to events from several services and build one view, such as an order page with customer and shipping status. That keeps the screen to one query.

Each source arrives with its own lag and order. The view must handle an order event that arrives before the customer it points to, often by storing a placeholder.

With Event Sourcing

22. How does event sourcing fit with CQRS?

In event sourcing, the write side stores every change as an event, and current state is rebuilt by replaying them. The event log then feeds projections for free.

It also gives a full history, so a new read model can be built from all past events. The cost is that the log is hard to query directly, which is why event-sourced systems almost always use CQRS.

23. What are snapshots, and when do you need them?

A snapshot saves an aggregate's state at some version. Loading starts from the snapshot and replays only newer events.

Most aggregates never need one. Streams with a few hundred events load fast. Add snapshots only when a long-lived stream's load time shows up in measurements. A long stream can also mean the aggregate is too big.

24. How do you delete personal data from an append-only event store?

Common approaches:

  • Crypto-shredding: encrypt personal fields with a key per person. Delete the key, and the data becomes unreadable.
  • Keep personal data out of events: store it in a normal table and put only an ID in the event.
  • Rewrite the stream: some stores allow replacing events. Marten 8 added CompletelyReplaceEvent(), for example.

Read models must be rebuilt or cleaned too. A candidate who says "events are immutable, so we can't" has not worked under GDPR.

25. What goes wrong when teams adopt CQRS?

  • Applying it to the whole system instead of the one area that needs it.
  • Separate databases on day one, with no one watching projection lag.
  • Business checks against the read model, which may be stale.
  • No rebuild plan, so a projection bug means a manual data fix.
  • Commands that mirror CRUD, such as UpdateOrder, so the split buys nothing.

Our event-driven architecture guide covers the messaging side: outbox, idempotent consumers and schema evolution.

What Changed Recently

Jul 2, 2025
MediatR 13 requires a license key.
Oct 16, 2025
KurrentDB 25.1 adds secondary indexes and multi-stream appends.
Nov 21, 2025
Spring Modulith 2.0 reworks the event publication lifecycle.
Jan 16, 2026
KurrentDB 26.0 adds user-defined indexes.
May 21, 2026
Marten 9 drops runtime code generation.

26. MediatR now needs a license. Do you still need it for CQRS in .NET?

MediatR 13.0.0, released July 2, 2025, requires a license key and moved from Apache 2.0 to a dual commercial and open-source license.

The free Community license covers companies under $5 million in revenue that have raised no more than $10 million. Earlier versions keep their open-source license.

A strong answer weighs the options: pay, stay on MediatR 12 without updates, switch to the MIT-licensed Mediator source generator, use a framework such as Wolverine, or call handlers directly.

As question 13 says, CQRS never needed a mediator.

27. Do KurrentDB's secondary indexes replace read models?

For some reads. KurrentDB 25.1 added default indexes by category and event type, and atomic appends to several streams in one write. Version 26.0 added user-defined indexes built from event content, such as "orders by country."

That removes projections whose only job was to build lookup streams. It does not replace a read model shaped for a screen, with joins, totals or full-text search. The ad hoc SQL query page in 25.1 needs a paid license.

28. What changed in Marten 9?

Marten 9.0.0, released May 21, 2026, targets .NET 9 and 10 and removes runtime code generation. Compiled queries use a source generator, and apps can be published ahead of time.

It also changed defaults toward speed: a faster event append mode, System.Text.Json as the default serializer, and lighter sessions. RestoreV8Defaults() brings the old ones back.

An upgrade that skips reading the defaults can change behavior silently.

29. How does Spring Modulith 2.0 stop in-process projections from losing events?

Its event publication registry stores an entry for each transactional listener when an event is published, in the same transaction. The 2.0 docs add a lifecycle: PUBLISHED, PROCESSING, COMPLETED, FAILED and RESUBMITTED.

A staleness monitor marks stuck entries as failed, and FailedEventPublications can resubmit them. For a Spring monolith that updates read models in-process, this gives outbox-style delivery without a broker.

The docs say the lifecycle exists so crash recovery does not treat in-progress entries as failed.

30. Which CQRS tools should a candidate know in 2026?

Enough to compare, not a list to recite. In .NET, Marten and Wolverine on PostgreSQL, plus EF Core for plain CQRS without events. In Java, Axon Framework 5 and Spring Modulith. KurrentDB as a dedicated event store.

Kafka or RabbitMQ to carry events between services.

The better signal is whether they can build a small CQRS flow without any framework: a handler, a version check and a projection with a checkpoint. Our DDD guide covers Axon 5 and aggregates in more depth.

Signs of a Strong Answer

  • They give a case where they would not use CQRS, and say why.
  • They start with one database and add stores only for a named query.
  • They store the projection checkpoint with the read model, and can explain the crash case.
  • They never validate commands against the read model.
  • They plan rebuilds and watch projection lag as a metric.

Hiring CQRS Developers

CQRS work needs engineers who understand both domain modeling and distributed data. Second Talent matches companies with pre-vetted back-end engineers and software architects across Asia, in .NET and Java.

See rates in our backend developer cost guide, or tell us about the role and we send a shortlist within 24 hours.

Ready to hire? Hire Software Architects: vetted AI-native talent, with first profiles in 24 hours.

Get developers who ship with AI agents. Starts at $25/Hour.

Start Hiring $0 cost until you hire