📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is the difference between a logical boundary and a deployment boundary in a .NET system? Explain independent deployability, how shared libraries and versioning can quietly couple deployables, and how monorepos and polyrepos affect this.

Logical vs deployment boundaries: modules vs deployables, independent deployability, shared NuGet libraries and versioning, and the monorepo vs polyrepo trade-off.

Mid-Level Theory Intermediate architecture deployment-boundaries modular-monolith monorepo nuget versioning

🎯 Key points

  • Logical boundary = which code may depend on which (module, assembly, `internal`, namespace, schema); deployment boundary = what is built, released and run as one unit; the two need not align
  • Several logical modules can share one deployable; a deployable should never split one tightly coupled module
  • Independent deployability: deploy one unit without coordinating others, which needs backward-compatible API and event contracts and tolerant readers
  • Shared libraries with domain logic or contracts couple deployables through lockstep upgrades and diamond dependencies
  • Share only stable, technical libraries; version with SemVer and enforce with package validation
  • Manage contract change with additive changes, expand-and-contract, and versioned APIs (/v2) and events
  • Monorepo eases atomic refactors and consistent tooling; polyrepo enforces separation but adds versioning overhead
  • Lockstep deployments are the sign of a distributed monolith

⏱ 30-second answer

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.

🗣 Full answer (senior)

How I would answer this in an interview

"A logical boundary is about dependencies: which code is allowed to reference which. In .NET that's a project or assembly, internal visibility, 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.Common NuGet 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 vs deployment boundaries

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

What to share between deployables

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 vs polyrepo

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

Production example

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].

🔍 What the interviewer is checking

Checks whether the candidate separates dependency structure from deployment structure and recognises how shared code and versioning undermine independent deployability.

Green flags

  • Defines both boundaries with .NET mechanisms
  • Knows independent deployability needs backward-compatible contracts
  • Calls out shared domain packages as coupling
  • Treats monorepo vs polyrepo as a workflow choice

Red flags

  • Thinks more repos or projects means better architecture
  • Proposes a shared "Common" library with domain types
  • Ignores versioning

📚 Learn in depth

1. Two kinds of boundary

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.

2. Independent deployability

A unit is independently deployable if you can release it without changing or redeploying anything else. Requirements:

  • Backward-compatible contracts: additive changes; tolerant readers that ignore unknown fields; expand-then-contract for breaking changes.
  • Own data: no other deployable depends on its schema.
  • Own pipeline: path-filtered CI in a monorepo, or its own repo.
  • No compile-time dependency on another deployable's internals.

3. How shared libraries couple

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.

4. Versioning

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).

5. Monorepo vs polyrepo

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.

6. Signs of a distributed monolith

  • Release notes listing "deploy A, then B, then C".
  • A shared database schema.
  • A shared domain package bumped in every release.
  • End-to-end test environments required for every deploy.

Try it yourself

  1. List every NuGet package your services share; classify each as infrastructure, contract or domain.
  2. Turn on package validation for one shared library and make a breaking change to see the error.
  3. Set up a path-filtered GitHub Actions or Azure Pipelines trigger for one module in a monorepo.
  4. Review the last ten releases: how many needed coordinated deploys?
  5. Add a tolerant-reader test: deserialise a contract with an extra unknown property and confirm it still works.

💻 Code

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
}

⚠ Common mistakes

  • Mistake: Equating projects or repos with architecture. Why it is wrong: Boundaries come from dependency rules and deployment, not from folder or repo count. Instead: Define logical boundaries with references and tests, and deployment boundaries by driver.
  • Mistake: Sharing domain entities or EF DbContexts via a NuGet package. Why it is wrong: It couples services to one model; strict SemVer and side-by-side versions can soften the pain, but in practice teams end up upgrading together and both models stop evolving freely. Instead: Give each deployable its own model; share only technical libraries and versioned contract schemas.
  • Mistake: Splitting deployables through code that changes together, for example putting order validation in one service and order pricing in another when every pricing change also changes validation. Why it is wrong: Each feature then needs coordinated releases, which defeats independent deployability. Instead: Look at change history and align deployment boundaries with cohesive modules or bounded contexts.
  • Mistake: Breaking contract changes without versioning. Why it is wrong: Consumers fail at runtime after an independent deploy. Instead: Additive changes, tolerant readers, expand-and-contract, package validation.
  • Mistake: A monorepo without path-based CI. Why it is wrong: Every change rebuilds and redeploys everything, hiding coupling. Instead: Path filters per deployable and CODEOWNERS per module.
  • Mistake: Treating a polyrepo as proof of independence. Why it is wrong: Shared packages and databases can still force lockstep releases. Instead: Measure how often releases need coordination.

🏛 Senior insight: trade-offs

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

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions shared event classes or contract packages Why: Checks how they version integration contracts without coupling
    How to answer

    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.

  2. When: Candidate mentions enforcing logical boundaries Why: Checks they can automate boundary rules with architecture tests
    How to answer

    Make the rules executable at several levels:

    • Project references enforce dependency direction at compile time (Domain can't see Infrastructure if it doesn't reference it).
    • internal hides implementation types so other projects can't use them.
    • Architecture tests check rules the compiler can't: "Domain must not depend on 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.
    • Analysers, such as the banned-API analyser, block specific calls like 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.

  3. When: Candidate talks about when to add a new deployable Why: Checks their criteria and process for extracting a module
    How to answer

    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.

🛠 Real-world problems: how you handle them

A shared Common package forcing lockstep releases
Situation
A [logistics company] ran [eight] .NET services in separate repos, all depending on a `Company.Common` NuGet package containing domain entities, event classes and EF configurations.
Signals
Every release was a coordinated train listing deploy order; deserialisation errors after partial deploys; deployment frequency of [once a week]; [30%] of failed changes linked to version mismatches.
Investigation
I mapped package dependencies across repos with `dotnet list package --include-transitive`, reviewed release notes for coordinated deploys, and classified each type in the package as infrastructure, contract or domain.
Resolution
Immediate: froze the package and pinned versions. Long-term: an ADR splitting it into a small telemetry/auth package, contract schemas owned by each producing service (additive changes only, tolerant readers), and per-service domain models. Services were migrated one at a time.
Prevention
Package validation on shared libraries, a rule that shared packages may not reference EF Core or domain projects, contract tests for events, and a metric for releases needing coordination.

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].

↩ Usually asked after

More in Senior-Level Architecture

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me