Database Per Service Pattern
What you'll learn: Why each microservice should own its data store and what benefits arise from keeping databases private.
In microservices architecture, the Database Per Service Pattern means each service manages its own dedicated database that no other service can access directly. If Service A needs data from Service B, it must request it through Service B's API—never by querying Service B's database directly.
Why Own Your Data?
Think of microservices like independent businesses on a street. Each shop maintains its own inventory records. The bookstore doesn't let the café peek into its stockroom database—instead, the café calls and asks, "Do you have this book in stock?" This keeps each business autonomous.
When a service owns its data store:
Autonomy: Teams can change schemas, upgrade database technology, or optimize queries without coordinating with other teams. Service B can switch from PostgreSQL to MongoDB without breaking Service A.
Evolution: You can refactor internal data models freely. If your User service needs to split a name field into firstName and lastName, that's purely internal—your API remains stable.
Encapsulation: Implementation details stay hidden. Other services depend on your contract (API), not your data structure. This reduces coupling dramatically.
Independent Scaling: A high-traffic service can scale its database separately. Your Order service might need a bigger database than your Notification service.
The Trade-off
This pattern introduces challenges like distributed transactions and data consistency across services (addressed in later patterns), but the independence gained is worth managing these complexities at the microservices level—where the Single Responsibility Principle and Bounded Contexts already demand clear separation.
Key Takeaway: Database Per Service Pattern gives each microservice full control over its data, enabling independent evolution, deployment, and scaling while enforcing proper service boundaries through API-only access.