Description
Each microservice's persistent data is private to that service and accessible only via its API. This ensures loose coupling.
Where to use
- Microservices autonomy. \n
- Choosing the right DB for the job.
Real World Example
Order Service uses PostgreSQL. Catalog Service uses MongoDB. Recommendation Service uses Neo4j. They cannot access each other's DBs directly.
Code Example
class DatabaseperMicroservice:
def __init__(self):
pass
def execute(self):
print('Executing Database per Microservice')
