Shared Database per Service
Problem Statement
Microservice architecture structures an application as a set of loosely coupled microservices and each service can be developed independently in agile manner to enable continous delivery/deployment. What should be the database structure/architecture in microservices based application.
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.
In this pattern, each service should use transaction management of underlying database so the ACID property of the database can be utilized. 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 limit of the customer is checked.
Advertisements