Avoiding Shared Databases
What you'll learn: Why sharing a database between microservices creates hidden dependencies that undermine service independence.
The Core Problem
In the previous lesson, you learned that each microservice should own its database. But why is sharing a database so problematic? When multiple services read and write to the same database, you create three critical issues that defeat the purpose of microservices.
Tight Coupling Through the Database
When services share a database, they become tightly coupled at the schema level. If Service A changes a table structure to meet its needs, Service B might break unexpectedly. You've essentially created a distributed monolith—all the complexity of microservices with none of the independence benefits.
Analogy: Imagine roommates sharing a single notebook for their personal schedules. If one person reorganizes the format, everyone else's entries become confusing or invalid.
Implicit Contracts
With shared databases, service contracts become invisible. There's no explicit API defining what data each service needs or provides. Instead, services rely on direct database access, making it impossible to know which services depend on which tables or columns. Refactoring becomes a minefield.
Coordination Overhead
Database changes require coordinating deployments across all services that touch affected tables. You lose the ability to deploy services independently—a core microservices advantage. Teams must synchronize releases, slowing down development velocity and increasing deployment risk.
Additionally, transaction management across services becomes complex, and you can't choose different database technologies optimized for each service's specific needs (a relational DB for one, a document store for another).
Key Takeaway: Shared databases create tight coupling, hidden dependencies, and coordination overhead that eliminate the independence and flexibility microservices are designed to provide—each service must own and encapsulate its data store.