Every part, twice
On a Monday morning, the quotes a car-parts distributor sends to garages list every part twice: two lines for the brake pads, two for the filter, and a total that has doubled. The quoting app has not been deployed in three weeks. What changed was a table it reads. On Friday the warehouse team opened a second depot and added a depot_id column to stock_levels, one row per part per depot. Their own app was updated for it. The quoting app, owned by the sales-tools team, joins parts to stock_levels on part_id and expects one row per part. Nothing failed: every query ran, and the results were wrong.
Four applications from three teams use one PostgreSQL database here: the catalogue app (part numbers, descriptions, prices), the warehouse app (stock and picking), the quoting app, and a nightly margin report written by finance. They do not call each other. They integrate through the tables, and that integration style is a Shared Database.
No app calls another. Each reads and writes the tables it needs, so every column any of them reads is part of the interface between teams.
It is the easiest way to start. Any app can read any data with one query and update several tables in one transaction, and there is nothing in between to build or run. The cost arrives later, in three ways.
The schema is an API nobody wrote down
Every column another team's app reads is part of an interface, and at the distributor that interface has no list of consumers, no version and no owner who promises anything about it. The warehouse team could not have warned the sales-tools team, because nothing told them the quoting app read stock_levels at all.
Once you know, the fix is coordination. A change to a table another team reads becomes a coordinated, risky multi-team migration: either every reader ships in step with the change, or the owner keeps the old shape alongside the new one until each reader has moved, the expand-and-contract sequence Schema migrations without downtime walks through. Wherever their apps share tables, a change the other readers would not survive has to be coordinated with every team that reads them, so their deployments stay coupled however separately they run, and direct access to the same rows blurs the boundary between their services. It also accumulates: each new reader makes the next change more expensive, which is why a shared schema called temporary rarely gets split unless someone schedules the split.
One team's query, everyone's latency
The margin report scans 30 million order lines. It is scheduled for 02:00, and one morning it was still running at 09:00, reading the disks hard enough that the quoting screens took seconds to open. The apps share one server's CPU, memory, disks and connection limit, so a workload heavy enough to saturate one of them slows all of them.
Schema changes hit the same wall. In PostgreSQL, an ALTER TABLE that takes an ACCESS EXCLUSIVE lock waits for the transactions already holding locks on that table, and later queries on that table, plain reads included, queue behind it. Run against parts while the report, which reads each part's cost, is still running, it holds up every team's queries on that table until it gets the lock and its transaction ends, unless a lock timeout makes it give up while waiting. Which statements take that lock is listed in the migrations article.
Whose rule is it?
The catalogue app refuses to set a part's price below cost plus 8%, in its code, so the rule holds only for writes that go through that code. For a spring promotion, a sales script updated parts.price directly, 20% off a whole range, and some parts sold below cost for a week. A CHECK constraint could have held this one rule, since price and cost sit in the same row, but most business rules need other rows or other systems, and live in application code that a direct write walks past. Nobody owned the row.
When one database is the right call
The trouble comes from several owners sharing tables, not from one database. Three setups use one honestly:
- One team, one release. If one team builds every app that touches the schema and releases them together, a schema change ships with its readers, and no other team has to be coordinated.
- A modular monolith with per-module tables. One deployable and one database, but each module owns its tables and other modules go through its interface, ideally enforced by a build check, or by separate schemas with grants per module when each module connects with its own database role; Modular Monolith covers the pattern. The day a module becomes a service, its tables already have one owner.
- A read-only copy for reporting. Finance's report reads a replica or a warehouse loaded from the main database, so its scans no longer compete with the quoting screens as long as that copy runs on resources of its own, and writes keep their single owner. The report still depends on the schema, so the owners treat the copied tables as a published contract and announce changes to them.
Out, one table at a time
The distributor moves in steps, one table at a time:
- Give each app its own database login, then find out who touches what. If PostgreSQL's
pg_stat_statementsextension is enabled, its statistics, aggregated per database user and statement, are a starting point that can surface the script nobody listed. It keeps a limited number of entries and evicts the least-run ones, and a job that did not run in the window, or a table reached only through a view or a function, still has to be found by asking. - Name one owning service for each table, the only one that will write it:
stock_levelsgoes to the warehouse service,partsto the catalogue service. A table two apps write is the hard case: split it, or turn one app's writes into calls to the other. - Move every other reader off the table: to an API call to the owner, to a copy fed by the owner's events, or, as a halfway step that still depends on the database, to a view the owner keeps stable while it changes the tables underneath.
- Revoke the other logins' grants on the table; until then, the boundary is a convention.
- Give the table its final home; how far to isolate it, from a schema of its own to a server of its own, is weighed in Database per Service.
The warehouse service writes and reads stock alone; the quoting app asks it. The catalogue and quoting tables are still shared, waiting their turn.
Moving one capability at a time, while the old app keeps serving everything not yet moved and callers switch over one by one, is Strangler Fig. While a table lives in both places during the move, the new store is usually kept in sync by reading the old database's log, which Change data capture explains, until the owner's copy becomes the only one. Moving the writes is a step of its own: the old writers stop, the copy catches up, and only then do writes go to the owner.
Carve out the first table
The Monolith to Microservices Challenge starts where the distributor's teams are now, with one database every capability reaches into, and forbids the new service from reading the monolith's database directly. Choose a business capability to extract, such as stock, then check that its tables can have one owner, as step 2 does. Give the new service its own datastore, keep it in sync with the monolith's database through the CDC connector during the transition, and send callers through the gateway so the route to the old code can be retired when the move is done.