Skip to content
BENIBIX Learn

Event Sourcing vs CQRS

Event sourcing and CQRS are often used together, so people mix them up, but they solve two different problems. Event sourcing is about how data is stored. Every change is kept as an event. CQRS is about how code is split. One side changes data, and another side reads it. Either one works fine without the other.

Development🏗️ Architecture

Event Sourcing

Save each change as an event. Build the present state from them.

Event sourcing stores every change to data as an event, not just the latest value. A shopping cart is saved as item added, item added, item removed, not as its final list. The current state is worked out by replaying the events in order. Nothing is ever written over. So you have the full history. The cost is more storage and more complex code.

Example
Jack's bank app stores each deposit and payment as an event. To show a balance, it adds them up. When a customer asks about a charge from March, it is all there.
Why it matters
You can see exactly how data got to where it is, which helps with audits and bug hunts.
Full entry
Development🏗️ Architecture

Command Query Responsibility Segregation (CQRS)

Splitting the code that changes data from the code that reads it.

CQRS splits the code that changes data from the code that reads it. Commands change things, like place order. Queries only read, like show my orders. Each side can have its own model, and often its own database, shaped for its job. Reads can then be fast and simple even when writes have many rules.

Example
Emma's shop saves orders in a strict database that checks each rule. A second, simpler copy feeds the order history page. That page loads in a blink.
Why it matters
Reads and writes often have very different needs. Splitting them lets each be shaped and scaled on its own.
Full entry

In one line

Event Sourcing
Save each change as an event. Build the present state from them.
Command Query Responsibility Segregation (CQRS)
Splitting the code that changes data from the code that reads it.