Full answer
Benefits:
- A service can change its schema without coordinating with others.
- Each can choose a fitting store and scale independently.
- Ownership is clear.
Problems and common answers:
- Cross-service queries ('orders with customer names'): keep a local copy of the needed customer fields updated from events, or compose in an API layer.
- Multi-step business processes (reserve stock, charge card, create shipment): a saga runs each step as a local transaction and, on failure, runs compensating steps (release stock, refund).
- Reporting: stream all services' changes into a warehouse.
- Consistency: data is eventually consistent; screens must tolerate brief disagreement.
A shared database used by several services is simpler at first but becomes a coupling point where one team's migration can break others. A pragmatic middle path is one database server with a schema per service and no cross-schema access.
Key points
- Own database per service for independence
- No cross-service joins or transactions
- Local copies via events for queries
- Sagas with compensation for workflows
- Warehouses for cross-service reporting
Common mistakes
- Services reading each other's tables
- Expecting ACID across services
Follow-ups
- How does a saga handle a failed payment?
- When is a shared database acceptable?
Tips
- Name the lost capabilities