0
0
Microservicessystem_design~12 mins

Shared database anti-pattern in Microservices - Architecture Diagram

Choose your learning style9 modes available
System Overview - Shared database anti-pattern

This system shows a microservices architecture where multiple services directly access the same database. This is called the shared database anti-pattern. It causes tight coupling between services and can lead to data conflicts and scaling problems.

The key requirement is to understand why sharing a database among microservices is problematic and how it affects system reliability and scalability.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +-------------------+-------------------+
  |                   |                   |
Service A           Service B           Service C
  |                   |                   |
  +-------------------+-------------------+
              |
              v
          Shared Database
              |
              v
          Cache Layer
Components
User
user
End user who sends requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Routes requests to appropriate microservices
Service A
service
Microservice handling a specific business domain
Service B
service
Another microservice handling a different business domain
Service C
service
Third microservice handling another business domain
Shared Database
database
Single database accessed directly by all microservices
Cache Layer
cache
Caches frequently accessed data to reduce database load
Request Flow - 9 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayService A
Service AShared Database
Shared DatabaseCache Layer
Service BShared Database
Service BAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Shared Database
Impact:All microservices lose access to data, causing system-wide failures. Writes and reads fail, leading to downtime and inconsistent data state.
Mitigation:Implement database replication and failover to a standby database. Use service-level caching to serve stale data during outages. Consider decoupling services with separate databases to reduce impact.
Architecture Quiz - 3 Questions
Test your understanding
Why is sharing a single database among microservices considered an anti-pattern?
AIt improves data consistency and reduces latency
BIt creates tight coupling and data conflicts between services
CIt allows services to scale independently
DIt simplifies service deployment
Design Principle
This architecture demonstrates the shared database anti-pattern where multiple microservices tightly couple by accessing the same database. This leads to scaling challenges, data conflicts, and single points of failure. Proper microservices design favors database per service to ensure loose coupling and independent scalability.