Microservices Design Patterns Tutorial
Selected Reading
- Discussion
- Useful Resources
- Quick Guide
- Blue Green Deployment
- Circuit Breaker
- Service Discovery
- External Configuration
- Health Check
- Distributed Tracing
- Performance Metrics
- Log Aggregation
- Event Sourcing
- Aysynchronous Messaging
- Saga
- Command Query Responsibility Segregator
- Shared Database per Service
- Database per Service
- Branch
- Chain Of Responsibilities
- Client Side UI Composition
- Proxy
- Aggregator
- API Gateway
- Decompose by Strangler
- Decompose by Subdomain
- Decompose by Business Capability
- Microservices Design Patterns - Overview
- Microservices Design Patterns - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Shared Database per Service
Shared Database per Service
Problem Statement
Microservice architecture structures an apppcation as a set of loosely coupled microservices and each service can be developed independently in agile manner to enable continous depvery/deployment. What should be the database structure/architecture in microservices based apppcation.
Solution
We can use a database which is shared among microservices. Each service is free to use data accessible to other services. Database will maintain the ACID transactions.
![Shared Database per Service Microservices Design Pattern](/microservices_design_patterns/images/shared_database_per_service_pattern.jpg)
In this pattern, each service should use transaction management of underlying database so the ACID property of the database can be utipzed. Conside the following pseudocode −
BEGIN TRANSACTION … SELECT * FROM ORDERS WHERE CUSTOMER_ID = ? … SELECT CREDIT_LIMIT FROM CUSTOMERS WHERE CUSTOMER_ID = ? … INSERT INTO ORDERS ... WHERE ORDER_LIMIT < CREDIT_LIMIT … COMMIT TRANSACTION
Here order service uses database transaction to ensure that during order, credit pmit of the customer is checked.
Advertisements