English 中文(简体)
Shared Database per Service
  • 时间:2024-11-03

Shared Database per Service


Previous Page Next Page  

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

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