liveBook · Manning

Database-per-microservice

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

An architectural pattern in which each microservice has its own separately managed database.

Database-per-microservice assigns each microservice its own separately managed database. Services may share a database server, but they should not share databases or use a database as an integration interface. section 4.5.4 section 4.8

Apply the pattern by:

  • Encapsulating each database behind the microservice that owns its data. section 4.5.4
  • Hosting separate databases on one server initially to reduce cost and operational complexity. section 12.3.6 section 12.8
  • Moving a heavily loaded database to a dedicated server when its workload requires more compute, memory, or storage. section 12.3.6
  • Avoiding shared databases because they create coupling, bottlenecks, fragile integrations, and limits on independent refactoring. section 4.5.4 section 12.3.6

Video-streaming application

A video-streaming microservice uses its own database while a video-storage microservice hides cloud file storage behind an API. Docker Compose can run the services and database during development. section 4.5.5 section 4.8

Figure 12.16 It’s completely okay to have separate databases running on a shared database server (this is often the simplest and cheapest way to get started).

Shows the cost-conscious starting arrangement: separate microservice databases hosted on one shared database server. section 12.3.6

Figure 12.17 As our application grows larger, we can scale it by splitting out large databases into their own independent database servers.

Shows the scaling path from a shared server toward dedicated database servers for databases whose workloads grow. section 12.3.6

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Explains ownership, shared-server deployment, migration to dedicated servers, and database sharing risks; defers deeper scalability details.
Examples
Uses a video-streaming database, MongoDB under Docker Compose, shared database servers, and later dedicated database servers.
What you can do after
Operate/configure separate service databases on a shared server, then move or shard workloads as scaling needs increase.
How it connects
Connects database encapsulation with REST APIs, service communication, horizontal scaling, Docker Compose, and database sharding.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.