0
0
Microservicessystem_design~12 mins

Database per service pattern in Microservices - Architecture Diagram

Choose your learning style9 modes available
System Overview - Database per service pattern

This system uses the Database per Service pattern to ensure each microservice has its own dedicated database. This design isolates data, improves service independence, and allows teams to choose the best database type for their service needs.

Key requirements include data isolation, independent service scaling, and avoiding direct database sharing between services.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +-------------------+-------------------+
  |                   |                   |
Service A           Service B           Service C
  |                   |                   |
DB A                DB B                DB C
  
Components
User
client
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly across API Gateway instances
API Gateway
api_gateway
Routes requests to appropriate microservices and handles authentication
Service A
service
Handles specific business logic and owns its own database DB A
Service B
service
Handles different business logic and owns its own database DB B
Service C
service
Handles another business domain and owns its own database DB C
DB A
database
Stores data exclusively for Service A
DB B
database
Stores data exclusively for Service B
DB C
database
Stores data exclusively for Service C
Request Flow - 8 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayService A
Service ADB A
DB AService A
Service AAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:DB B
Impact:Service B cannot read or write its data, causing failures in that service's features. Other services remain unaffected.
Mitigation:Implement database replication and failover for DB B. Service B can degrade gracefully or use cached data if available.
Architecture Quiz - 3 Questions
Test your understanding
Why does each service have its own database in this pattern?
ATo isolate data and allow independent service scaling
BTo reduce the number of databases needed
CTo allow users to access databases directly
DTo share data easily between services
Design Principle
This pattern emphasizes strong service independence by giving each microservice its own database. This avoids tight coupling and allows teams to choose the best database technology per service, improving scalability and fault isolation.