Database per Service
5 min read Quiz at the end
Each service owns its database — no shared DB, best DB per use case, eventual consistency across services.
Database per Service Pattern
# Each service picks the best DB for its needs
user-service -- PostgreSQL (relational, ACID)
product-service -- MongoDB (flexible schema)
session-service -- Redis (fast, TTL)
search-service -- Elasticsearch (full-text)
analytics-svc -- ClickHouse (columnar)
# Anti-pattern: shared database
# order-service reads users table (belongs to user-service)
# This creates schema coupling!
# Data consistency across services:
# 1. Saga pattern -- compensating actions
# 2. Outbox pattern -- reliable event publishing
# 3. Eventual consistency -- accept lag
Topic Quiz · 1 questions
Test your understanding before moving on
1. Why does each microservice need its own database?
💡 Shared databases create tight coupling — one service changing its schema can break other services.