Data

Database per Microservice

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:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing Database per Microservice')