Logical vs deployment boundaries: modules vs deployables, independent deployability, shared NuGet libraries and versioning, and the monorepo vs polyrepo trade-off.
A logical boundary decides what code may depend on: a module, an assembly, a namespace, a database schema. A deployment boundary decides what ships and runs together: one App Service, one container, one Function app.
They don't have to match. A modular monolith has many logical boundaries in one deployable. Microservices add deployment boundaries so units can be deployed independently, which only works if contracts stay backward compatible.
The quiet killer is shared libraries: a NuGet package with shared domain models or contracts that every service must upgrade together turns separate deployables back into a distributed monolith.
Monorepo vs polyrepo is about workflow, not architecture: a monorepo makes cross-cutting changes easy; a polyrepo forces versioning. The trade-off is coordination cost vs isolation.
"A logical boundary is about dependencies: which code is allowed to reference which. In .NET that's a project or assembly,
internalvisibility, namespaces, and for data, a schema. A deployment boundary is about what gets built, released and run as one unit, like one App Service or one container image. You can have many logical boundaries inside one deployment boundary, which is exactly what a modular monolith is. What you shouldn't do is put a deployment boundary through the middle of code that changes together, because every feature then needs two coordinated deploys.Independent deployability is the real goal of splitting deployables. It means I can deploy the Billing service on Tuesday without asking anyone else, so its API and events must stay backward compatible. Shared libraries are where that usually breaks. I've seen a
Company.CommonNuGet package containing domain entities, event classes and EF configurations used by [eight] services. Changing one event property meant releasing the package and redeploying all eight, in order. That's a distributed monolith: separate deployables with lockstep releases.The mistake I see is equating repositories or projects with architecture. A monorepo doesn't make you a monolith, and a polyrepo doesn't make services independent. My senior line is: draw logical boundaries generously, deployment boundaries sparingly, and only share code that's stable and technical, never your domain."
| Logical boundary | Deployment boundary | |
|---|---|---|
| Controls | Dependencies, visibility, ownership | Build, release, runtime, scaling, failure |
| .NET mechanisms | Projects, internal, InternalsVisibleTo, namespaces, schemas, architecture tests |
App Service, container image, Function app, pipeline |
| Cost of adding one | Low | Pipeline, environments, monitoring, contracts, network |
| Typical count | Many | Few |
| Share? | Example | Why |
|---|---|---|
| Yes | Logging/telemetry setup, auth helpers, resilience defaults | Stable, technical, rarely breaking |
| Carefully | Contract packages generated from OpenAPI/AsyncAPI schemas | Versioned, additive changes only |
| No | Domain entities, EF DbContexts, business rules | Couples releases and models |
| Monorepo | Polyrepo | |
|---|---|---|
| Cross-cutting refactor | One PR | Many PRs + package releases |
| Tooling consistency | Easy (Directory.Build.props, CPM) | Drifts |
| Isolation | Needs path-based CI triggers and CODEOWNERS | Natural |
| Risk | Accidental cross-references | Version skew, diamond dependencies |
Replacing a shared Common package of domain classes with per-service models and versioned contract schemas let [eight] services deploy independently; deployment frequency rose from [weekly release trains] to [several deploys a day per service].
Checks whether the candidate separates dependency structure from deployment structure and recognises how shared code and versioning undermine independent deployability.
Green flags
Red flags
Deployment boundary: one App Service
┌───────────────────────────────────────────┐
│ Host (Program.cs) │
│ ┌───────────┐ ┌───────────┐ ┌───────────┐ │
│ │ Orders │ │ Billing │ │ Catalogue │ │ ◄ logical boundaries
│ │ schema: │ │ schema: │ │ schema: │ │ (projects, internal,
│ │ orders. │ │ billing. │ │ catalog. │ │ schemas)
│ └───────────┘ └───────────┘ └───────────┘ │
└───────────────────────────────────────────┘
Logical boundaries are enforced at compile time (project references, internal) and by tests (ArchUnitNET/NetArchTest). Deployment boundaries are enforced by the network and the pipeline.
A unit is independently deployable if you can release it without changing or redeploying anything else. Requirements:
A shared package becomes a hidden contract. If service A on Common 2.0 publishes an event that service B on Common 1.4 deserialises with a different class shape, you get runtime errors. Teams respond by upgrading everything together, which is lockstep deployment.
Diamond dependencies make it worse: service A depends on Common 2.0 and Payments.Client 1.3, which itself depends on Common 1.x. NuGet picks one version, possibly breaking Payments.Client at runtime.
Rule of thumb: share infrastructure (stable, technical) and schemas (versioned, generated), not behaviour or domain types. Duplicating a ten-line DTO in two services is cheaper than coupling their releases.
Use SemVer for shared packages: breaking change = major. Enforce with package validation (EnablePackageValidation and baseline version checks in the SDK) so accidental breaking API changes fail the build. For service contracts, version APIs (/v2, media types) and events (OrderPlaced.v2 or additive fields).
A repo is a collaboration and tooling boundary. A monorepo with Central Package Management (Directory.Packages.props) keeps versions consistent and allows atomic refactors; you need path-based triggers so changing Billing doesn't redeploy Orders, and CODEOWNERS per folder. A polyrepo forces published contracts and versioning but adds release overhead and version skew. Either can host a modular monolith or services.
A monorepo layout where logical modules share one deployable, plus settings that keep shared packages honest.
repo/
Directory.Build.props # nullable, analysers, TreatWarningsAsErrors
Directory.Packages.props # Central Package Management: one version per package
src/
Shop.Host/ # the only deployable (App Service)
Modules/
Orders/Orders.Contracts | Orders.Core (internal types)
Billing/Billing.Contracts | Billing.Core
Shared/
Shop.Telemetry/ # technical, stable: OK to share
tests/
Shop.ArchitectureTests/
.github/CODEOWNERS # /src/Modules/Billing/ @billing-team
<!-- Shop.Telemetry.csproj: a shared, technical package with breaking-change detection -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<Version>2.3.0</Version>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>2.0.0</PackageValidationBaselineVersion>
</PropertyGroup>
</Project>
namespace Billing.Contracts;
// Contract types are small, additive and owned by Billing; consumers ignore unknown fields.
public sealed record InvoiceIssued(Guid InvoiceId, Guid OrderId, decimal Total, string Currency)
{
public DateOnly? DueDate { get; init; } // added in v1.1: optional, so old consumers keep working
}
I look at release history, not diagrams, to judge boundaries: if two deployables are almost always released together, they are one deployable pretending to be two, and merging them is often the right fix. Conversely, if one module in a monolith is blocked by another team's release train every week, that's evidence for a new deployment boundary.
For shared code, my bar is "would we be happy to have five versions of this in production at once?" If not, it shouldn't be a shared package.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Many modules, one deployable | One or few teams, shared cadence | Low | Modules need independent scaling or release |
| Separate deployables | Different cadence, scaling, isolation, team | Pipelines, contracts, ops | Code changes together |
| Shared technical package | Stable cross-cutting infrastructure | Versioning discipline | Domain logic, fast-changing code |
| Monorepo | One org, consistent tooling, frequent cross-cutting changes | CI path filtering needed | Strict access separation required |
An integration event is a public API owned by the publisher. Within a version I only make backward-compatible changes: add optional (nullable or defaulted) fields. I never add a required field mid-version (messages already in queues won't have it), and never rename, remove or retype. Consumers are tolerant readers: they ignore unknown fields and default missing optional ones. A breaking change becomes a new event type (orders.order-placed.v2), published alongside v1 until consumers move, then deprecated with a date.
I wrap events in a CloudEvents envelope (id, source, type, time, dataschema). Each publisher ships its own contracts package or JSON Schema; one shared events library for every service forces lockstep upgrades.
The trade-off: discipline and some duplication in exchange for independent deployments.
Make the rules executable at several levels:
internal hides implementation types so other projects can't use them.Microsoft.EntityFrameworkCore", "Billing may only use Orders.Contracts". ArchUnitNET (actively maintained) or NetArchTest (the original is unmaintained since 2021; the eNhancedEdition fork is maintained) inspect compiled assemblies inside a normal test run.DateTime.Now.Roll out with a baseline so legacy violations don't block the build. The trade-off: cheap, fast feedback, but only for static dependencies.
I keep a modular monolith until a module has a measured reason to become its own deployable: it needs to scale independently, it has a different release cadence or owning team, it needs fault or security isolation, or it needs a different runtime. "Microservices are modern" isn't a reason.
The first candidate should have few inbound dependencies, a clean contract and its own schema already. Extraction is incremental: make the module talk only through its contract, stop cross-module joins and transactions, move its data, deploy it as a service, and switch traffic behind a feature flag with a rollback path.
The trade-off: every extracted module turns method calls into network calls, so you gain autonomy and isolation but pay with latency, partial failures and eventual consistency.
How to tell it (STAR)
**S:** At [company] eight services shared a `Common` package with domain entities and events, so every release was a coordinated train. **T:** I was asked to help teams deploy independently. **A:** I mapped the dependencies, showed that [30%] of failed changes came from version mismatches, and wrote an ADR splitting the package into technical helpers and producer-owned contracts, with per-service models. I migrated the first two services myself to prove the approach and added package validation. **R:** Services began deploying independently, deployment frequency went from [weekly] to [several times a day], and version-mismatch failures dropped to [near zero].
Last updated 23 Nov 2026.