Quick revision
The short answer
A shared database couples services through their tables: a schema change made for one service can break the others, so deployments have to be coordinated and nobody can change their data freely. Database-per-service means only the owning service touches its data, and everyone else goes through its API or its events. That buys independent schema changes and scaling, but it costs us cross-service joins and transactions and brings data duplication and eventual consistency; separate schemas on one database server are a reasonable first step.
What to remember
In this answer, we saw that a shared database couples services through their tables, so schema changes break other services and deployments become coordinated. Database-per-service gives each service sole access to its data, with others using its API or events, which allows independent schema changes and scaling. In exchange we give up cross-service joins and transactions and accept duplication and eventual consistency. Separate schemas on one server, with access enforced by database users, are a cheap and reasonable first step.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A shared database couples services through their tables: a schema change made for one service can break the others, so deployments have to be coordinated and nobody can change their data freely. Database-per-service means only the owning service touches its data, and everyone else goes through its API or its events. That buys independent schema changes and scaling, but it costs us cross-service joins and transactions and brings data duplication and eventual consistency; separate schemas on one database server are a reasonable first step.
Why this question is asked
Almost every team moving to microservices starts with one database, because that is what the monolith had. The question of whether to keep sharing it decides whether the services can really evolve independently. Interviewers ask about it because the answer shows whether we understand coupling at the data level, which is the strongest kind, and whether we can name the honest costs of the alternative. In this answer, we will see how a shared database couples services, what database-per-service actually requires, what we gain and what we pay, and how to get there in practical steps.
1How a Shared Table Couples Two Services
Imagine an Orders service and a Shipping service that both use the orders table in one PostgreSQL database. Orders writes rows; Shipping reads them to know what to ship. Everything works until the Orders team decides to split the address column into street, city and postcode.
The Orders team changes its code and runs the migration. The next morning Shipping fails, because its query still selects address. The table was effectively a public API of the Orders service, but it had no version, no documentation and no contract test, and the Orders team may not even have known that Shipping read it.
From then on, every schema change needs a meeting between both teams and a joint deployment plan. That is the coupling: the services can no longer change or deploy independently, which is the main thing microservices were supposed to give us. Sharing also couples them at runtime, because a heavy report query from one service can slow down the database for all the others.
2What Database-per-Service Means
Database-per-service means each service owns its data, and only that service reads or writes it. Other services get the data through the owner's API, for example GET /orders/42, or by listening to events the owner publishes, such as OrderPaid, and keeping their own copy of the fields they need.
The word database is about ownership, not about servers. It does not require a separate PostgreSQL server per service. It requires that no other service can reach the data directly. A separate schema per service on a shared server, with database users that can only access their own schema, already enforces the rule.
| Aspect | Shared database | Database-per-service |
|---|---|---|
| Schema change | Coordinated with every reader | Owner decides, keeps its API stable |
| Deployment | Often joint | Independent |
| Scaling and tuning | One size for all | Per service, even a different engine |
| Joins across data | Plain SQL join | API calls or a local copy |
| Transactions across data | One ACID transaction | Saga or outbox, eventual consistency |
| Data copies | One copy | Some duplication |
3What We Gain
The first gain is independent change. The Orders team can split the address column whenever it likes, as long as its API and its events keep their shape, and it can test that with contract tests. The second gain is independent scaling and tuning: a search-heavy catalogue can use a different index strategy, a read replica, or even a different store such as Elasticsearch, without affecting Orders.
There is a quieter gain too: clear responsibility. When one service owns the data, there is one place where its rules are enforced, and one team to ask when something looks wrong.
4What It Costs
The costs are real and we should name them plainly. We lose joins across services: a report that joined orders with shipments in one query now has to call two APIs or read from a reporting store that both services feed. We lose transactions across services: creating an order and reserving stock can no longer be one ACID transaction, so we use a saga, a sequence of local transactions with compensating steps if a later one fails, usually driven by events.
We also accept duplication and eventual consistency. Shipping keeps its own copy of the delivery address, updated when an OrderPaid or AddressChanged event arrives. For a few hundred milliseconds or a few seconds, Shipping's copy may be older than Orders' data. The design must tolerate that, for example by including the address in the event so Shipping always ships to the address that was valid when the order was paid.
5A Practical Path: Separate Schemas First
Moving from one database to many in one step is a big project. A reasonable first step is to keep the single server but give each service its own schema and its own database user, and revoke cross-schema access. That immediately stops new hidden dependencies, makes the existing ones visible (they fail with a permission error in a test environment), and costs almost nothing in infrastructure.
Later, a service that needs different scaling or stronger isolation can move its schema to its own server with little change, because nobody else depends on its tables any more. The thing to watch with a shared server is noisy neighbours: one service's heavy query can still slow the others, so connection limits per user and monitoring per schema help.
6Follow-up questions
Can a read-only reporting database still combine data from many services?
Yes, and it often should. Each service publishes its changes, through events or change data capture, into a reporting store or data warehouse that analysts query. The important difference is that the reporting store is a consumer with its own copy; no service reads it for its operations, and the owning services stay free to change their own schemas.
How do you query data that lives in three services for one screen?
Either compose it at request time, with a gateway or backend-for-frontend that calls the three APIs in parallel, or build a read model that listens to events from the three services and stores the combined view. Composition is simpler and always fresh; the read model is faster and survives outages but is eventually consistent.
Is it ever fine to share a database?
For a small system built by one team, or during a migration, a shared database with clear table ownership can be a pragmatic choice. The problems grow with the number of teams and services. What should never happen is two services writing the same table without one clear owner.
7Conclusion
In this answer, we saw that a shared database couples services through their tables, so schema changes break other services and deployments become coordinated. Database-per-service gives each service sole access to its data, with others using its API or events, which allows independent schema changes and scaling. In exchange we give up cross-service joins and transactions and accept duplication and eventual consistency. Separate schemas on one server, with access enforced by database users, are a cheap and reasonable first step.
Open with
A shared database is a problem because the tables become an undocumented API between services. If the orders service renames or splits a column, the shipping service that reads the same table breaks, so every schema change needs coordination and teams end up deploying together.
Then, if they want more
It also couples them at runtime, since one service's heavy query slows the others. Database-per-service means only the owning service reads and writes its data. Everyone else uses its API or listens to its events and keeps a local copy of what they need.
That lets each team change its schema freely behind a stable API and scale or tune its storage independently. The cost is that we lose joins and ACID transactions across services. A report that joined two services' data needs API composition or a reporting store fed by events, and a business operation across services becomes a saga with compensating steps.
We also accept duplicated data and eventual consistency, so the design must tolerate a copy that is a few seconds old. In practice I would not insist on a separate server per service from day one.
A separate schema per service on the same server, with database users that cannot access other schemas, already enforces ownership and is a good first step.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Cloud documentation, Resilience4j documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Why is a shared database between microservices considered a problem? What is the...": https://scrivio-interview-library.netlify.app/spring-boot/microservice-design/744c56ba64/