Microservices Pattern: Database per Service
Status:: ๐ฉ
Links:: 30_Knowledge/Microservices @Richardson.2017.TransactionalOutboxPattern
Metadata
Authors:: Richardson, Chris
Title:: Microservices Pattern: Database per Service
Date:: 2017
URL:: http://microservices.io/patterns/data/database-per-service.html
DOI::
Richardson, C. (2017). Microservices Pattern: Database per Service. Microservices.Io. http://microservices.io/patterns/data/database-per-service.html
A service's database is private to that service
Notes & Annotations
Color-coded highlighting system used for annotations
๐ Annotations (imported on 2024-03-05#11:00:28)
Keep each microserviceโs persistent data private to that service and accessible only via its API. A serviceโs transactions only involve its database.
There are a few different ways to keep a serviceโs persistent data private. You do not need to provision a database server for each service. For example, if you are using a relational database then the options are: Private-tables-per-service โ each service owns a set of tables that must only be accessed by that service Schema-per-service โ each service has a database schema thatโs private to that service Database-server-per-service โ each service has itโs own database server.
Private-tables-per-service and schema-per-service have the lowest overhead. Using a schema per service is appealing since it makes ownership clearer. Some high throughput services might need their own database server
The FTGO application is an example of an application that uses this approach. Each service has database credentials that only grant it access its own (logical) database on a shared MySQL server. For more information, see this blog post.