---
topic: system-design
author: Crashtech Editorial
published: Nov 14, 2026 · read: 5 min
---

Microservices Data Patterns: Database per Service, Saga, Outbox and CQRS

Once each service owns its data, transactions and queries break. Four patterns that put them back, with the failure each one prevents and the cost it adds.

– –

The first week after a monolith is split goes well. The second week someone asks how to place an order that charges a card, reserves stock and sends an email across three services, and nobody can put it inside a transaction. The patterns below are the standard answers.

Three problems microservices introduce

ProblemWhy it appears
Data consistencyData lives in many stores, so a business operation spans several, and they can briefly disagree
Attack surfaceMore services and endpoints to authenticate and protect (a gateway and mutual TLS help)
Database bottlenecksThe app tier scales out easily, but a shared or poorly partitioned data tier does not

This article covers the data side, which is where most of the pain lives.

Pattern 1: database per service

Each service owns its data and exposes it only through its API or events. No service reads another’s tables.

What you gain independence
Change a schema without a cross-team meeting. Pick the right store per service. Scale a hot service’s database alone.
What you lose the easy stuff
No joins across services, no ACID across them, and reporting needs a plan. Data duplicated between services must be kept in sync by events.

You can enforce it softly (separate schemas with separate credentials in one server) or hard (separate servers). Start with the soft version if operations are a concern, as long as nothing reaches across the boundary.

Pattern 2: saga, for operations that span services

Take “place an order”: reserve stock, charge the card, confirm the order. No single transaction covers all three, so a saga runs them as a sequence of local transactions, each followed by an event, with an undo step for each.

Order created
  -> Inventory: reserve stock           (undo: release stock)
  -> Payment:   charge card             (undo: refund)
  -> Order:     confirm                 (undo: cancel)

If Payment fails:  run undo for Inventory, then mark the order cancelled

Two coordination styles:

StyleHow it worksGood forWatch out for
ChoreographyServices react to each other’s events, no central brainFew steps, simple flowsFlow hard to see, cyclic dependencies
OrchestrationA coordinator tells each service what to do and tracks stateMany steps, complex branchingThe orchestrator becomes a component to own and keep available
Sagas are not rollback

A compensating action is a new business operation, not a database undo. Refunds take time, emails cannot be unsent, and in between, other users can see the intermediate state. Design the steps and the compensations as part of the product, including what the customer sees while it runs.

Pattern 3: transactional outbox, so events are not lost

Sagas depend on publishing events reliably. The trap is the dual write.

1. UPDATE orders SET status='paid'     <- succeeds
2. publish OrderPaid to the broker     <- process crashes before this

The database changed, nobody heard. Reverse the order and you can announce something that never committed. The outbox makes both facts atomic:

  1. Write the event in the same transaction

    Insert the event into an outbox table in the same database and the same transaction as the business change. Both commit or neither does.

  2. Relay it afterwards

    A separate process reads new outbox rows and publishes them to the broker, either by polling or by reading the database change log. It marks them as sent.

  3. Consume idempotently

    The relay can publish twice after a failure, so consumers must handle duplicates. Give every event a unique id and record which ones were processed.

Advertisement

Pattern 4: CQRS, so reads get their own model

Command Query Responsibility Segregation separates the model that handles writes (commands, with all the validation rules) from the models that serve reads (queries, shaped for screens). Updates flow from the write side to the read side by events.

It earns its keep when:

  • A screen needs data from several services at once. Build a read model that joins them ahead of time, since a runtime join across services is not available.
  • Read and write loads differ by orders of magnitude and should scale independently.
  • Reporting or search queries would otherwise hammer the transactional store.

The cost is eventual consistency: after a write, the read model lags by a short time. Show the user their own change immediately, or read your own writes from the command side, so it does not feel broken.

Choosing, honestly

You faceUseDo not bother if
Teams blocked by a shared schemaDatabase per serviceYou have one team and one deployable
An operation touches several servicesSagaOne service can own the whole operation
Lost or phantom eventsOutboxYou do not publish events
A query needs data from many services, or reads dwarf writesCQRS read modelA single service query is fast enough

Do

Make every handler idempotent, give events unique ids, log saga state so stuck operations can be found, and define the compensation for every step before building the forward path.

Don't

Reach for two-phase commit across services, share a database “just for now”, or adopt all four patterns on day one. Each pattern adds moving parts that need monitoring and an owner.

Takeaway

Microservices trade one transaction for many independent ones, and these four patterns are how you earn coherence back: a clear data boundary, sagas for multi-step operations, an outbox for reliable events, and CQRS for queries that cross boundaries. Each costs consistency and complexity, so adopt them one at a time, driven by a failure you can name.

Advertisement

Frequently asked questions

Why should each microservice have its own database?

So services can change schema, scale and deploy independently, and so no other team can couple to your tables. Shared databases turn into a distributed monolith: any change needs coordination. The cost is that cross-service transactions and joins no longer exist and must be rebuilt with patterns.

What is the saga pattern?

A way to complete a business operation that spans several services without a distributed transaction. Each service does its local transaction and publishes an event. If a later step fails, earlier steps are undone by compensating actions, such as refunding a payment, so the system returns to a consistent state.

What problem does the transactional outbox solve?

Writing to your database and publishing a message are two separate operations, so a crash between them loses the event or publishes one for data that was never saved. The outbox writes the event to a table in the same local transaction, and a relay publishes it afterwards.

When is CQRS worth the complexity?

When read and write needs differ sharply: heavy reporting or search views, very different scaling, or complex write rules. It separates the model that changes data from the models that serve queries, at the price of eventual consistency between them. For simple CRUD it is over-engineering.

Sources & further reading

/* Comments */