DEV Community

Alex Georghiou
Alex Georghiou

Posted on Edited on

CQRS Is Not Two Databases

CQRS Is Not Two Databases

CQRS is often introduced as a picture with two databases and a message bus. That picture is one possible implementation, not the definition.

The useful idea is that writes and reads have different concerns. A write enforces invariants and changes state. A read answers a question efficiently. You can separate those models in code long before adding infrastructure.

For instance, a checkout command may require strict validation around available credit. A reporting query may join several read-only tables and return a flat projection. Making both travel through the same generic repository because "everything is an entity" can be needlessly restrictive.

HTTP request
  |-- command --> invariants --> persistence
  |-- query   --> projection --> response
Enter fullscreen mode Exit fullscreen mode

Separate databases become interesting when read scale, data shapes, or availability needs justify eventual consistency. They also introduce lag, replay, operational tooling, and new failure states. A dashboard showing stale information may be fine. A payment authorization using stale limits probably is not.

Start by separating intent. Add physical separation only after measuring a real need. Architecture diagrams are cheaper than operating distributed state.

Top comments (0)