Every monolith that became unmaintainable had a document describing its modules. The document was not the problem; the fact that nothing enforced it was.
Schema-per-module makes the boundary something the database itself refuses to cross.
The idea
One database. Each module gets its own PostgreSQL schema — catalogue, ordering, payments, identity — and its own database context configured to see only that schema.
A module cannot write a join against another module's tables, because from where it sits, those tables do not exist. It reads another module's data by calling that module's public contract, the same way an external service would.
What this gets you
A boundary that cannot be crossed by accident. The most common way a monolith rots is a query someone wrote at 6pm that joins two modules because it was quicker. With separate schemas, that query does not compile.
Migrations that stay small. Each module owns its own migration history. A change to ordering does not appear in a diff alongside a change to identity.
A clear extraction path. If a module ever has to become a service, its data is already separate. Extraction changes the transport, not the data model.
Honest dependency mapping. Because cross-module access goes through explicit contracts, you can see the real dependency graph rather than guessing it from joins.
What it costs
No cross-module joins. This is the whole point, and it is also the cost. A report spanning ordering and catalogue has to be assembled in the application, or served from a purpose-built read model.
For reporting this is often fine — a read model that both modules feed is usually the better design anyway. For ad-hoc analytical queries it hurts, and the usual answer is a separate reporting schema populated from events.
No cross-module foreign keys. Referential integrity across a boundary becomes the application's job. In practice this means storing an identifier rather than a foreign key and accepting that the other side may have deleted the row.
That sounds alarming and is mostly not: it is exactly the situation you would be in with microservices, and it forces you to decide what should happen when a referenced thing is gone — a decision a foreign key silently makes for you, usually wrongly.
More setup. Each module needs its own context, its own migration configuration, and its own conventions. Worth doing once as a template.
Practical notes
One connection, many schemas. All modules share the same database and connection pool, so a transaction can still span modules when it genuinely must — for instance, writing a domain event to an outbox in the same transaction as the change that produced it.
Set the search path explicitly per context rather than relying on a default. A context that can see the public schema will eventually be used to reach into it.
Give the outbox its own schema. It is infrastructure, not domain, and every module writes to it.
Enforce it in tests too. An architecture test that fails the build when one module's assembly references another module's internals costs an afternoon and prevents years of drift.
In production
In an education and commerce platform we built, eighteen modules share one PostgreSQL database as eighteen isolated schemas, with 109 versioned migrations and 44 typed integration events between them. The whole thing deploys as one unit — which is the point: the discipline of service boundaries without the operational weight.






Comments
No comments yet. Be the first.