Skip to content
System Design Lab
Microservice Patterns

Database per Service

Give each service exclusive ownership of its data, so teams change schemas and scale storage independently — and one service's heavy queries cannot take down another.

Beginner 4 min read· Updated 2026-11-18

What you will learn

  • Explain the runtime and design-time coupling of a shared database.
  • Decide what "owning" data means: schema, tables or a whole server.
  • Get data across services through APIs and events instead of joins.
  • Handle reporting and cross-service queries without a shared database.

Overview

Flatmates who share one fridge argue about space, and one person's party clears it out for everyone. Give each flatmate their own fridge and nobody needs to coordinate. Services sharing a database have the same problem.

With database per service, each service is the only one allowed to read and write its data. Other services ask through its API or listen to its events. The database can be a separate server, a separate schema or just a set of private tables — what matters is that no other service touches them directly.

What goes wrong with a shared database

  • Runtime coupling: one service's expensive queries or locks consume connections, CPU and I/O that every other service needs.
  • Design-time coupling: renaming a column requires coordinating every team whose code reads it — the schema becomes everybody's API.
  • No independent scaling: the busiest workload decides the size and type of the database for everyone.

Run it

At t = 10 s the finance team runs many heavy reports. Compare Orders failed in both scenarios: in A the reports exhaust the shared connection pool; in B only reports slow down.

Loading simulation…

Working across services without joins

NeedWithout a shared database
Show order with customer nameCall the Customers API, or keep a local copy of the name updated by CustomerRenamed events.
Business transaction across servicesA Saga of local transactions.
Reports across many servicesStream events or CDC into a reporting store / data warehouse built for analytics.
Complex read viewsCQRS read models fed by events.

Enforcing ownership

One schema and one login per service (PostgreSQL)
CREATE SCHEMA orders;
CREATE ROLE orders_svc LOGIN PASSWORD '***';
GRANT USAGE, CREATE ON SCHEMA orders TO orders_svc;
REVOKE ALL ON SCHEMA orders FROM PUBLIC;

CREATE SCHEMA inventory;
CREATE ROLE inventory_svc LOGIN PASSWORD '***';
GRANT USAGE, CREATE ON SCHEMA inventory TO inventory_svc;
REVOKE ALL ON SCHEMA inventory FROM PUBLIC;
-- orders_svc cannot even see inventory.* — the only way in is the Inventory API.

Advanced Separate schemas on one server fix design-time coupling cheaply but still share CPU, memory and I/O (the noisy-neighbour problem in scenario A). Move a service to its own server when its load or availability needs differ. Ownership also allows polyglot persistence: a search service on Elasticsearch, a session service on Redis.

Trade-offs

BenefitsCosts
IsolationA heavy workload hurts only its owner.More databases to operate, back up and monitor.
AutonomyTeams change schemas without coordination.Cross-service queries need APIs, events or a reporting store.
ConsistencyEach service keeps its own invariants.No ACID transactions across services; use sagas and eventual consistency.

Production considerations

  • Migrate gradually: first stop new cross-service table access, then move tables one service at a time.
  • Treat events and APIs as the contracts that replaced the shared schema — version them.
  • Give analytics its own store; never let BI tools query service databases directly.

Further reading

Related topics