Database per Service: A Core Principle in Microservice Architecture
By Misbahul Munir3 min read596 words

Database per Service: A Core Principle in Microservice Architecture

Software Architecture
microservices

When transitioning from a monolith to microservices, the focus is often on decomposing services and enabling independent deployments. But there's one subtle — yet critical — principle that truly unlocks the power of microservices: Database per Service.

In this article, we’ll explore what this principle means, why it’s essential, real-world examples, and the trade-offs you need to understand to implement it effectively.


What Is "Database per Service"?

In microservice architecture, each service should have its own private database — isolated from other services. No other service is allowed to query, update, or access that database directly. Data sharing must occur only via APIs or asynchronous messaging.

This principle allows services to remain autonomous, loosely coupled, and independently deployable — the foundation of microservice scalability.


Real-World Motivation: An Insurance System Gone Wrong

Let’s imagine an insurance company moving from a monolithic application to a microservice-based architecture. They split the system into services like:

  • Policy Purchasing Service
  • Claims Service
  • Customer Service
  • Reporting Service

Initially, all these services access a shared database, thinking it’s efficient for performance. But here's what happens:

ScenarioWhat Goes Wrong
Policy Service switches to NoSQLReporting Service fails — it relied on relational schema
Claims Service renames table columnsBoth teams must coordinate schema changes and redeploy together
Customer Service adds complex security rulesThose rules leak into Reporting Service, increasing complexity and coordination

Despite splitting the monolith, the teams are still tightly coupled at the data layer. This slows down deployments, increases bugs, and destroys autonomy.


What Database per Service Solves

Now imagine that each service owns its own database:

  • Policy Purchasing
    → NoSQL
  • Claims
    → Relational DB
  • Customer
    → PostgreSQL with strict access controls
  • Reporting
    → Calls other services via APIs instead of reading their databases

Suddenly:

  • Each team can evolve independently
  • Security concerns are isolated
  • Schema changes don’t ripple across systems
  • No one needs to "sync" database migrations anymore

Another Example: E-commerce Architecture

Here’s a typical e-commerce setup using the Database per Service principle:

MicroserviceDatabase Technology
User Service
PostgreSQL
Order Service
MySQL
Inventory Service
MongoDB

When

Order Service
needs user data, it makes an API call to
User Service
.

No direct database queries.

No shared schemas.

No fragile inter-service contracts.

This is the heart of polyglot persistence — every service picks the database that fits its own needs.


Trade-offs You Must Consider

While powerful, Database per Service isn’t free of drawbacks:

1. Performance Overhead

APIs are slower than direct SQL joins.

Mitigation: Use caching, denormalization, or eventually consistent replicas.

2. No SQL Joins Across Services

Need to combine order and user data?

You’ll have to fetch separately and join in application code.

3. No Multi-Service Transactions

Atomic transactions across multiple services aren’t practical.

Use patterns like:

  • Saga
  • Event Sourcing
  • Outbox Pattern

Best Practices

To make Database per Service work, follow these rules:

  • Never access another service’s database directly
  • Expose all data through APIs or message queues
  • Use API versioning to support schema evolution without tight coupling
  • Cache foreign data cautiously — source of truth should always remain in the owning service
  • Plan for eventual consistency — it's the trade-off for autonomy

Final Thoughts

Database per Service may feel inconvenient at first — especially when you're used to monolithic convenience like cross-table joins and global transactions.

But it’s a small price to pay for:

  • Independent deployments
  • Resilient systems
  • Autonomous teams
  • Scalable architectures

“In microservices, shared databases feel efficient — until every change becomes a negotiation.”

If you’re adopting microservices, make Database per Service one of your non-negotiables.