Skip to content

Event-driven and CQRS: commands and events, event sourcing, outbox, sagas and when each pattern pays off

The four meanings of event-driven, the difference between commands and events, event sourcing as a bank statement, CQRS without the myths, outbox, sagas and why most systems are fine with CRUD.

Ramon Gomes 12 min read Level: Advanced

Also available in: Español, Français, Português

Few architecture topics produce as much talking past each other as "event-driven architecture". In 2017, Martin Fowler wrote a whole article after a meeting where everyone in the room used the word "event" for something different.

This article separates the concepts, shows when each one is worth the cost and covers the patterns that make it all work in practice: outbox, idempotency, snapshots and event versioning. I checked sources and versions on November 21, 2026.

Old ledger open on a wooden table, with columns of handwritten entries and a fountain pen beside it
The bookkeeper never erases a line. A mistake is fixed with another entry.

Command, Event and Message

First, three words that the book Enterprise Integration Patterns, by Gregor Hohpe and Bobby Woolf, helped tell apart:

What it is Tense Can it be rejected?
Message The envelope that travels between systems
Command A request to do something Imperative: BookRoom Yes
Event The notice that something happened Past: RoomBooked No, it already happened

Think of a coffee shop counter: "make me a coffee" is a command, and the barista can say the machine is broken. "Coffee 42 ready" on the screen is an event; rejecting it makes no sense.

The trap Fowler points out: events that are really orders in disguise, like SendWelcomeEmailRequested. He calls this a "passive-aggressive command". If the publisher expects someone to do something specific, it's a command.

The Four Meanings of "Event-driven"

Four vignettes: an envelope with an id notifies a service, which fetches the rest; an envelope carrying data feeds a local database; an archive keeps events e1 through e6; CQRS branches into a write server and a read screen.
Four different ideas that use the same word.

1. Event Notification

The system announces that something changed and doesn't care who's listening. The event is usually thin: OrderCreated { orderId: 42 }. Anyone who wants details queries the source.

The gain is low coupling. The cost, according to Fowler: the full flow doesn't show up anywhere in the code. When something goes wrong, nobody can say off the top of their head which services react to OrderCreated.

2. Event-carried State Transfer

The event carries the data: CustomerChangedAddress { customerId, street, city, zipCode }. The shipping service keeps a local copy and doesn't need to query the customer service. More resilience and less latency, at the cost of several copies of the same data spread around.

3. Event Sourcing

Every state change is stored as an event, and the event log becomes the source of truth. The current state is calculated from it.

4. CQRS

Separate models for writing and for reading. Fowler makes a point of saying that CQRS isn't strictly about events; it just tends to show up alongside them.

The first two are ways for services to communicate, and the article on message queues covers the infrastructure. The last two are ways to model data, and they're the focus from here on.

Event Sourcing: The Bank Statement

Your bank doesn't store just the balance. It stores every transaction, and the balance is the sum. If there was a mistake, nobody deletes the line: they post a reversal. That's event sourcing.

A timeline shows a deposit of 100, withdrawal of 30, deposit of 50, reversal of 30 and new withdrawal of 20. The chart records balances of 100, 70, 120, 150 and 130. The snapshot stores 150 and replay starts there for the fifth entry: 150 minus 20 equals 130.
The balance is the sum of the entries. The snapshot is the month-end close.
ts
type AccountEvent =
  | { type: 'Deposited'; amount: number }
  | { type: 'Withdrawn'; amount: number }
  | { type: 'WithdrawalReversed'; amount: number };

function balance(events: AccountEvent[]): number {
  return events.reduce((total, e) => {
    switch (e.type) {
      case 'Deposited': return total + e.amount;
      case 'Withdrawn': return total - e.amount;
      case 'WithdrawalReversed': return total + e.amount;
    }
  }, 0);
}

What you gain:

  • Full audit trail: every change, who made it and when.
  • Time travel: what was the state on March 1? Just sum the events up to that date.
  • New views of the past: came up with a report today? It can be calculated over the whole history.

What you pay, and Microsoft's documentation is emphatic about it: it's a complex pattern, migrating to it or away from it is expensive, and "For most systems and most parts of a system, traditional data management is sufficient."

The Details That Bite in Practice

Design the event with intent. Microsoft gives the example: "two seats were reserved" says more than "remaining seats changed to 42". The second is state; the first is a business fact.

Concurrency. Two requests read the same stream with 5 free seats and try to book. The event store rejects the second write because the stream changed since it was read (optimistic concurrency), and that request retries with the updated state.

Snapshots. An account with 50,000 events shouldn't sum everything on every read. Every so often you store a picture of the state, and the sum starts from it. But the snapshot is an optimization, not the truth: the truth is still the log.

Versioning. Events are never edited. When the format changes, the usual technique is upcasting: a function converts the old event to the new format at read time, and the log stays intact.

Three levels: a rack keeps the v1 event with name Ana; a copy passes through the upcaster and gains an empty surname field; the current code screen receives v2. The v1 event and the original event store remain untouched.
The old event is converted on read. The archive doesn't change.

Replay with external side effects. When reprocessing events to rebuild a view, the system can't send the email again or charge the customer a second time. Fowler warned back in 2005 that external systems "don't know the difference between real processing and replays". Turn off integrations during replay and make consumers idempotent.

Personal data. Immutable events and the right to have data deleted under privacy laws like GDPR clash. The options Microsoft mentions: keep personal data outside the event and reference it by ID, or encrypt it with a per-person key and delete the key when the person asks (crypto-shredding).

Kafka is not an event store. Microsoft's documentation spells it out: "Message brokers such as Apache Kafka typically lack per-entity stream queries and optimistic concurrency." They distribute events; they don't replace a database built for the job, like KurrentDB (formerly EventStoreDB), Marten (on top of PostgreSQL) or Axon.

CQRS: Kitchen and Menu

In a restaurant, the kitchen works with rules, stock and ingredients. The menu shows everything ready, organized for whoever is choosing. They're different views of the same business, tuned for different uses. CQRS applies this to code.

Two paths side by side. On the write side, BookRoom checks that the room exists and dates are free, then saves the event. A clock accompanies the route to the read side; the table and query show Room 12 booked. An envelope identifies the RoomBooked event.
The write side applies the rules. The read side gets the ready version, a little later.

Microsoft describes two levels:

  1. Separate models in the same database. The write side uses entities with rules; the read side uses optimized queries that return DTOs ready for the screen. This is the foundational level, and it already solves a lot.
  2. Separate databases. The read side lives in another database (a materialized view, a search index), updated by events. More scale, and with it comes eventual consistency: reads lag a few moments behind writes.
ts
// Write: command with business intent
async function bookRoom(cmd: { hotelId: string; roomId: string; guestId: string }) {
  const room = await repo.load(cmd.roomId);
  room.book(cmd.guestId);   // business rules here
  await repo.save(room);
}

// Read: direct query, no rules, shaped for the screen
async function availableRooms(hotelId: string) {
  return db.query(
    'SELECT number, type, price FROM vw_available_rooms WHERE hotel_id = $1',
    [hotelId],
  );
}

Look at the command name. Microsoft recommends commands as business tasks ("Book hotel room"), not as field changes ("Set ReservationStatus to Reserved").

When CQRS Pays Off

Microsoft's criteria: far more reads than writes, task-based screens, separate teams for each side, a collaborative setting with heavy contention over the same data.

When it doesn't pay off: simple business rules and CRUD screens. And Fowler's 2011 warning still holds: "for most systems CQRS adds risky complexity", and most of the cases he saw went badly. If the problem is just one heavy report, a separate reporting database can solve it without changing the architecture.

Publishing the Event Without Losing Anything: Outbox

A problem shows up as soon as the event leaves the service. You save the order in the database and publish OrderCreated to the broker. If the database write succeeds and the broker fails, the event is lost. If the broker gets it and the database fails, there's an event for an order that doesn't exist. No transaction spans both.

The fix is the transactional outbox: the event is written to a table in the same database, in the same transaction as the order. A separate process reads that table and publishes to the broker.

An isometric database contains order 42 for $120.00 and event e7 OrderCreated in the same transaction. The relay publishes to the broker; a network failure without acknowledgment causes two deliveries of e7. The consumer keeps e7 among processed ids and drops the copy, marked in red.
Order and event saved together. The consumer ignores the copy.
sql
BEGIN;
INSERT INTO orders (id, customer_id, total) VALUES ($1, $2, $3);
INSERT INTO outbox (id, aggregatetype, aggregateid, type, payload)
VALUES (gen_random_uuid(), 'order', $1, 'OrderCreated', $4);
COMMIT;

The publishing process can poll the table or read the database log directly with a CDC tool like Debezium (3.7), which has a ready-made router for this table format.

And the detail that always comes back: the publisher may send the same event twice. The consumer has to be idempotent, storing the IDs it has already processed.

Sagas: A Transaction That Spans Services

When a business process goes through several services (booking a flight, a hotel and a car), you can't use a database transaction. The saga, an idea from a 1987 paper by Garcia-Molina and Salem, splits the process into local transactions; if one fails, compensating transactions undo the previous ones.

There are two styles: choreography, where each service reacts to the others' events, and orchestration, where a coordinator sends commands and decides the next step. The article on modular monolith vs microservices has the animation of a saga undoing its steps.

Cartoon of a bookkeeper trying to erase a line in a ledger with a huge eraser, while a coworker next to him points to the line below, where she wrote a reversal in pen
In event sourcing, there's no eraser. There's the reversal.

Quick check

1. Which of these is an event, not a command?
Show answer

Answer: RoomBooked

An event is in the past tense: something that already happened and can't be rejected.

2. Does CQRS require event sourcing?
Show answer

Answer: No; you can have separate read and write models, even in the same database

Fowler and Microsoft treat them as independent patterns that tend to go together.

3. What problem does the transactional outbox solve?
Show answer

Answer: Writing to the database and publishing the event consistently, without losing or inventing events

Duplicates are still possible. That's why the consumer has to be idempotent.

Frequently Asked Questions

Do I need microservices to use events?

No. A monolith can publish internal events between modules, and it's a great way to reduce coupling without paying the cost of the network.

Which database should I use for event sourcing?

To start, PostgreSQL does the job: an events table with stream, version and payload, and a unique constraint on stream and version for optimistic concurrency. Marten does this for .NET. Dedicated databases like KurrentDB help at high volume.

Will eventual consistency confuse users?

It can. The screen that just saved should show the result of its own command, not reread the read model. The delay is usually milliseconds, but it has to be handled.

Can event sourcing and privacy laws like GDPR coexist?

Yes, with care: personal data outside the event, or encrypted with a key per data subject.

Where should I start?

With domain events inside your own system and a separate read model for the heaviest screen. Event sourcing only when history is a business requirement.

References

Checked on November 21, 2026:

Source: https://ramongomessilva.com.br/blog/event-driven-and-cqrs · Accessed on December 03, 2026

Share Share on LinkedIn Share on X
Cite this article

Ready-made reference, with today as the access date.

ABNT

Brazilian standard (NBR 6023). Use it in theses and academic papers submitted in Brazil.

GOMES, Ramon. Event-driven and CQRS: commands and events, event sourcing, outbox, sagas and when each pattern pays off. Ramon Gomes, 2 dez. 2026. Disponível em: https://ramongomessilva.com.br/blog/event-driven-and-cqrs. Acesso em: 3 dez. 2026.

APA

American Psychological Association style. Common in scientific papers and journals, especially in the social, behavioral and health sciences.

Gomes, R. (2026, December 2). Event-driven and CQRS: commands and events, event sourcing, outbox, sagas and when each pattern pays off. Ramon Gomes. https://ramongomessilva.com.br/blog/event-driven-and-cqrs

BibTeX

Format for LaTeX users (Overleaf, for example). Paste it into your .bib file or import it into Zotero or Mendeley.

@online{gomes2026eventdrivenand,
  author = {Gomes, Ramon},
  title = {{Event-driven and CQRS: commands and events, event sourcing, outbox, sagas and when each pattern pays off}},
  organization = {Ramon Gomes},
  year = {2026},
  month = dec,
  date = {2026-12-02},
  url = {https://ramongomessilva.com.br/blog/event-driven-and-cqrs},
  urldate = {2026-12-03}
}
Found a mistake?

Wrong fact, broken link, outdated information: tell me and I will fix it.

10 to 2,000 characters. If you can, point to the right source.

Only so I can reply. It never shows on any page of the site.

Written by

Ramon Gomes

Software Engineer

Full stack software engineer. I like taking a messy problem, listening to the people who live with it and shipping something that holds up day to day. These days I split my time between my own products, applied AI and client work.

Available for projects

Need Something Like This Built?

I build websites, systems, apps and AI automations, from design to deploy. Tell me what you need or see what I offer.

Related Articles