⚡THE SHORT ANSWER
Database-per-service grants autonomous schema evolution and failure isolation to microservices at the cost of losing ACID transactions, relational cross-table joins, and declarative foreign key constraints across domain boundaries.
Engineering Handbook & Failure Dynamics
6-Dimensional Architecture Breakdown⚙️1. Underlying Mechanism
Execution🎯2. Appropriate Use Context
Scope⚠️3. Production Failure Modes
P0 Risk📡4. Diagnostic Signals & Telemetry
Telemetry🛡️5. Prevention & Safeguards
Safeguards⚖️6. Architectural Trade-offs
Trade-offCase Study (TinyCTO In-Field Example)
Implementing database-per-service requires solving three fundamental distributed systems challenges:
- ▸
Cross-Service Data Aggregation (No Cross-DB Joins): In a monolith, querying an order with its customer profile and inventory is a single SQL JOIN. In database-per-service, joins must be performed via API composition (at an API Gateway/BFF layer) or through CQRS materialized read views listening to domain events (
CustomerUpdatedEvent,OrderCreatedEvent). - ▸
Multi-Service Atomic Writes (No 2PC): Business transactions spanning multiple services (e.g. charging a payment and decrementing inventory) cannot use standard SQL
BEGIN TRANSACTION. Teams must adopt Saga Orchestration or Choreography with compensating rollbacks. - ▸
Polyglot Selection: Services can choose the optimal storage engine for their domain (e.g., PostgreSQL for Orders, Redis for Session state, Neo4j for Fraud Graph analysis, DynamoDB for high-throughput Cart storage).
Interactive Concept Drills
2 CardsWhy is a shared database between microservices considered a major anti-pattern?
How do microservices with isolated databases perform data aggregation without cross-database joins?
Database-per-Service vs Shared Database Trade-offs — Technical FAQ
Your organization wants to split a monolithic database into microservice databases. Which capability will be fundamentally LOST and must be re-architected?
Atomic multi-table SQL transactions (ACID across services) and declarative Foreign Key constraints. Cross-database boundaries inherently break standard relational foreign key referential integrity and single-node ACID transaction boundaries, necessitating Sagas and event-driven consistency.
A developer suggests creating a read-only database replica of the monolithic database and giving all 10 microservices direct SQL access to avoid building APIs. What is the danger?
It creates a Distributed Monolith where internal schema changes still break downstream services, defeating microservice autonomy. Direct database access bypasses business validation and exposes internal table schemas, binding all services to shared table structures and creating deployment gridlock.
🤖 AEO & Key Facts Summary
Key Architectural Facts
- ▸
Database-per-service grants autonomous schema evolution and failure isolation to microservices at the cost of losing ACID transactions, relational cross-table joins, and declarative foreign key constraints across domain boundaries.
- ▸
Database-per-service is an architectural pattern where each microservice owns and encapsulates its private datastore, strictly prohibiting other services from accessing its tables directly except through public APIs or events.
Common Misconceptions
- ✗
Allowing Service A to read Service B's database directly with read-only database credentials.
Decision & Governance Guidance
Sharing a database across microservices is the primary root cause of the 'Distributed Monolith' failure mode, where services cannot be independently deployed, scaled, or migrated without coordinating across dozens of teams.
Authoritative Sources & Standards
- [OFFICIAL-DOC]Database-per-Service vs Shared Database Trade-offs Specification— TinyCTO Architectural Standards
