1.

Is it a good idea to share a common database across multiple microservices?

Answer»

In a microservices architecture, each microservice shall own its private DATA which can only be accessed by the outside world through owning service. If we START sharing microservice’s private datastore with other services, then we will violate the principle of Bounded Context. 

Practically we have three approaches -

  1. Database server PER microservice - Each microservice will have its own database server instance. This approach has the overhead of maintaining database instance and its replication/backup, hence its rarely used in a practical environment. 
  2. SCHEMA per microservice - Each microservice owns a private database schema which is not accessible to other services. Its most preferred approach for RDMS database (MySql, Postgres, ETC.)
  3. Private Table per microservice - Each microservice owns a set of tables that must only be accessed by that service. It’s a logical separation of data. This approach is mostly used for the hosted database as a service solution (Amazon RDS).


Discussion

No Comment Found