How it works · 17 of 49 Core
Why does each microservice get its own database?
And the shared-database trap
Database per service: Database per service means each service keeps its data private and everyone else reaches it only through that service's API. With one shared database, a column renamed by one team breaks another team's code that never changed, usually in a job nobody is watching. The private database lets each team change its tables freely; the price is that a join across services becomes code (a batch call or a local copy fed by events) and a transaction across them needs a saga (E4).
Loading the animation…
Say it like this Database per service means each service's tables are private and others go through its API, so one team can change its schema without breaking another; the price is that joins across services become batch calls or copies.
Under the hood — for builders
- The sources, in their words
- Microsoft ("Data considerations for microservices"): "Two services shouldn't share a data store"; "If the data schema changes, the change must be coordinated across every service that relies on that database." Richardson ("Database per service"): "Keep each microservice's persistent data private to that service and accessible only via its API."
- Private doesn't mean a server each
- Schema: the named set of tables and columns a database holds. Microsoft: "Services can safely share the same physical database server. Problems occur when services share the same schema." Richardson lists three levels:
- Run here: the rename
- SQLite, 1,000 customers. Orders renames phone to mobile. Billing's three queries (one lookup, one join, one count):
- Run here: the price of a join
- API call: a request to another service over the network; each assumed to cost 1 ms. Reading 1,000 invoices with each customer's phone:
- Local copy
- Billing keeps its own copy of the few customer fields it needs, updated from Orders' events. Fast to read, but seconds old: Microsoft calls this eventual consistency.
- Measure it
- Tables read or written by more than one service · schema changes that need another team's sign-off · cross-service calls per page.
- Watch out
- Richardson: "Implementing business transactions that span multiple services is not straightforward" (that is E4, sagas). Saving and announcing a change safely is D5, the outbox.
- Sources
- Microsoft, "Data considerations for microservices", Azure Architecture Center · Chris Richardson, "Pattern: Database per service", microservices.io · both read in session · toy runs, Python and SQLite, 19 Nov 2026.
What happens in the database per service animation, step by step?
- Two services, one database: Orders and Billing both reach into the same customers table.
- Orders renames a column for its own reasons: phone becomes mobile. Its own tests pass.
- At 3 a.m. Billing's nightly job looks for phone. Billing never changed a line, and no reminders go out.
- Your turn: tap the fridge to give each cook their own, with a hatch between them.
- Orders can change anything in its own fridge. Billing only sees the hatch, the API, and that shape is a promise.
- The price: no joins across fridges. Billing asks in one batch, or keeps a copy fed by Orders' notes, which can lag. Next: copies that go stale.
What everyday example explains database per service?
Two cooks, one fridge, one relabelled jar. Give each cook a fridge and a serving hatch: what comes through the hatch is a promise, what sits in your fridge is your business.
Why should a team care about database per service?
A shared database is the most common cuff in a split system (C6), and it fails silently, at night, in someone else's service. Deciding who owns each table, and what the API promises, is the decision that makes services independent.