Course contentsShow
← Cloud and Infrastructure
Lesson 2562 of 2,98955. Microservices on CloudFree lesson

Shared Database Anti-Pattern

Risks of shared databases: tight coupling, deployment coordination, and schema conflicts.

Shared Database Anti-Pattern

What you'll learn: Why sharing a single database across multiple microservices undermines the core benefits of distributed architectures.


The Core Problem

After learning the Database per Service Pattern (lesson 2561), it's critical to understand its opposite—the anti-pattern. A shared database occurs when multiple microservices read from and write to the same database schema. While this might seem simpler initially (no data synchronization needed!), it creates serious architectural problems that negate the independence microservices are supposed to provide.

Three Major Risks

1. Tight Coupling
When services share tables, they become implicitly coupled through the schema. Service A can't change a column without potentially breaking Service B. You've lost the autonomy that Service Boundaries and Decomposition (lesson 2560) aimed to achieve.

2. Deployment Coordination
Need to add a field? You must coordinate releases across all services that touch that table. This forced synchronization eliminates independent deployment—a key microservices benefit from lesson 2556.

3. Schema Conflicts
Different teams managing different services may have conflicting needs for the same data. One service needs denormalized data for performance; another needs normalized data for consistency. These competing requirements create design gridlock.

The Restaurant Analogy

Imagine multiple restaurant kitchens (services) sharing one recipe book (database). If the pasta chef changes a sauce recipe, the pizza chef's dishes might suddenly taste wrong. Each kitchen needs its own recipes to operate independently.

Why It Happens

Teams often share databases to avoid the complexity of Domain-Driven Design Basics (lesson 2559) or implementing proper service communication patterns. Short-term convenience trades away long-term flexibility.

Key Takeaway: The shared database anti-pattern sacrifices microservices' independence, scalability, and deployment flexibility by coupling services through a common schema—always prefer database-per-service boundaries aligned with your domain model.