Home / Learn Secure SQL / Microservices: Database per Service

Microservices: Database per Service

Why sharing one database across many services undermines isolation.

The gistWhy sharing one database across many services undermines isolation.

The idea, explained simply

Shared database vs database per serviceOne shared databaseAny service can touch anytable directlyUndermines service boundariesand least privilegeDatabase per serviceEach service's data isisolated by constructionOther services access it onlythrough defined APIs
Shared database vs database per service

In plain terms

The "database per service" pattern gives each microservice its own dedicated database (or at minimum, its own schema and account), rather than many services all reading and writing one shared database directly.

Why we use it

A shared database lets any service touch any other service's data directly, which undermines both the service-boundary isolation microservices are meant to provide and the least-privilege, per-service accounts covered earlier in this course.

Under the hood

Give each microservice its own database (or schema) and its own least-privilege account, and have services communicate through defined APIs/events rather than by directly querying another service's tables.

Real-world use

  • Web application code review
  • Backend development
  • Database administration

This is primarily an architectural decision made early in a system's design, reinforcing (rather than replacing) the least-privilege, per-service-account ideas from the "Least privilege and access control" part of this course.

Quick quiz

1. Database-per-service mainly reinforces...