Meaning
A Database per Service pattern assigns each microservice its own dedicated database. It isolates data ownership, preventing cross‑service data coupling and reducing the blast radius of schema changes. It is used when services need independent scaling, deployment, or strict data encapsulation.
Primary Function
Database architecture
Communicative Purpose
Ensures each microservice manages its own data store, avoiding shared‑database contention and accidental data coupling.
Pattern
service → dedicated database → isolated data management
Core Structure
service_id → database_instance
Função primária
Database architecture
Propósito comunicativo
Ensures each microservice manages its own data store, avoiding shared‑database contention and accidental data coupling.
Situações de gatilho
Microservices: a new service requires its own schema and independent scaling; Domain‑driven design: bounded contexts need isolated persistence
Contextos
Microservice architectures, cloud‑native applications, containerized deployments, service‑oriented backends
Padrão
service → dedicated database → isolated data management
Estrutura central
service_id → database_instance
Colocados típicos
- service
- database
- schema
- connection pool
- migration
Substituições comuns
- Shared database with schema per tenant (simpler ops but tighter coupling)
- multi‑tenant single database (resource efficient but riskier isolation)
Erros comuns
Creating a separate DB for every tiny service → operational overhead; Forgetting to configure migrations per service → schema drift; Using the same connection string across services → accidental data sharing
Similar / contraste
Shared Database (multiple services share one DB) – higher coupling; Multi‑tenant Database (single DB with tenant discriminator) – shared resources but logical isolation
Interferências
Coming from monolithic Java: assuming a single DataSource can be reused across services – leads to transaction leakage in microservices
Família do chunk
- Database per Service
- Database per Tenant
- Shared Database
- Multi‑tenant Architecture
Nuance
Do not use when the team is small and operational cost outweighs benefits; Extra databases increase connection and resource usage, impacting performance; Schema migrations must be coordinated per service to avoid version mismatches
Efeito pragmático
Reduces risk of cascading failures due to schema changes and enables independent deployment pipelines
Dica de memória
Think of each microservice as a house with its own backyard garden; the garden (database) belongs only to that house.
Nota
Database per Service often pairs with container orchestration tools that provision databases dynamically (e.g., Kubernetes Operators).
Upgrade path
Shared Database with schema segregation for low‑traffic services
Log in to save chunks.