Modular monolith first: the criteria for splitting a module out, choosing the first candidate, and the step-by-step extraction (contract, data, traffic switch) with rollback.
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.
"My default is a modular monolith: one deployable, but modules with their own schema and a public contract, enforced by architecture tests. It gives us most of the modifiability of microservices without the distributed systems tax. I'd only split a module out when there's a measured driver. The common ones are independent scaling, for example a document-rendering module that pegs the CPU and forces us to scale the whole app; a different release cadence because another team owns it; fault isolation, so a memory leak in one area can't take down checkout; or a security boundary, such as a module that handles card data and should sit in a smaller PCI scope.
For example, at [company] our [quote PDF generation] module caused [70%] of our CPU at month-end and forced us to run [8] App Service instances for everything. I wrote an ADR proposing to extract just that module. Because it already had its own schema and a contract interface, the work was mostly mechanical: we replaced the in-process implementation with an HTTP client behind the same interface, moved its tables with a one-off migration, published 'quote requested' messages through an outbox instead of calling it synchronously, and routed traffic with a feature flag so we could flip back in seconds. Month-end instance count for the main app dropped from [8] to [3], and the PDF service scaled on queue length on its own.
The mistake I see is splitting along technical layers or extracting a module that's tangled with everything else, which produces a distributed monolith where every deploy is coordinated. My senior line is: extract modules for a reason you can measure, one at a time, and make the boundary right inside the monolith before you make it a network boundary."
| Good driver | Evidence to look for |
|---|---|
| Independent scaling | One module dominates CPU/memory; scaling the whole app is wasteful |
| Release cadence / team autonomy | A separate team blocked by shared release trains |
| Fault isolation | Incidents in one area take down unrelated features |
| Security / compliance scope | PCI, health data, a smaller audited surface |
| Different technology | GPU workload, Python ML model, different data store |
| Weak reason | Why |
|---|---|
| "Microservices are best practice" | No driver, all cost |
| "The codebase is messy" | A network boundary doesn't fix poor modularity |
| "So teams can choose any language" | Usually raises ops and hiring cost |
| Criterion | Prefer |
|---|---|
| Inbound dependencies | Few callers; ideally it is called asynchronously |
| Data coupling | Own schema, no cross-module joins |
| Driver | Clear, measurable (scaling, isolation) |
| Risk | Not on the critical revenue path for the first attempt, or well covered by tests |
| Step | Done when |
|---|---|
| 1. Harden boundary in-process | Only the contract is referenced; architecture tests pass |
| 2. Remove shared transactions and joins | Module data accessed only through its contract or events |
| 3. Move data | Tables moved to a new database; sync or cut-over plan rehearsed |
| 4. Deploy the service | Same contract over HTTP/gRPC or messages, with health checks, telemetry |
| 5. Switch traffic behind a flag | Canary, compare error rates and latency |
| 6. Remove the old code path | Flag removed after a stable period |
Extracting the [PDF generation] module cut month-end App Service instances for the main app from [8] to [3], saved about [$3k] a month, and removed the CPU spikes that had pushed checkout p95 above [1.5 s].
Checks whether the candidate can make a driver-based decision to split and execute an incremental, reversible extraction that handles data and failure modes.
Green flags
Red flags
A logical boundary (module, namespace, assembly, schema) controls what code can depend on. A physical boundary (process, deployable, database server) controls how it runs and fails. Microservices add physical boundaries; you can get most of the design benefit from logical ones alone.
Modular monolith (one process) After extracting Documents
┌───────────────────────────────────┐ ┌────────────────────────┐ msg ┌──────────────────┐
│ Quotes ──► IDocuments contract │ │ Monolith │ ─────► │ Documents service │
│ Policies │ │ │ Quotes, Policies, │ │ own DB, scales │
│ Billing ▼ │ │ Billing │ ◄───── │ on queue length │
│ Documents module │ │ DB: quotes., billing. │ event │ │
│ DB schemas: quotes. documents. … │ └────────────────────────┘ └──────────────────┘
└───────────────────────────────────┘
Martin Fowler's "MonolithFirst" argument: you rarely know the right boundaries at the start, and moving a boundary inside one codebase is a refactor, while moving it between services is a migration. A modular monolith lets the domain teach you where the seams are.
X.Contracts, never X.Domain or X.Infrastructure (verify with ArchUnitNET or NetArchTest).DbContext spanning both.The hardest part is data, not code.
An in-process call can't fail halfway; a network call can. When converting:
| In-process | Over the network |
|---|---|
| Exceptions | Timeouts, transient errors, 5xx |
| Same transaction | Outbox + idempotent consumer, or saga |
| Microseconds | 1-5 ms in-region plus serialisation |
| Refactor freely | Versioned contract |
Use Microsoft.Extensions.Http.Resilience (standard resilience handler: timeout, retry, circuit breaker) for HTTP, and the outbox pattern for messages.
Route through a feature flag (Azure App Configuration or Microsoft.FeatureManagement) at the contract implementation: in-process vs remote. Start with a small percentage, compare error rate and p95 in Application Insights, then increase. Keep the in-process path until the service has been stable for a release or two.
Switching one module's contract from in-process to remote behind a feature flag, so extraction is gradual and reversible.
namespace Documents.Contracts;
public sealed record RenderQuotePdf(Guid QuoteId, string TemplateCode);
public sealed record RenderedDocument(Guid DocumentId, Uri Location);
public interface IDocumentsModule
{
Task<RenderedDocument> RenderQuotePdfAsync(RenderQuotePdf request, CancellationToken ct);
}
namespace Host.Composition;
using Documents.Contracts;
using Microsoft.FeatureManagement;
// Routes to the old in-process module or the new service; flipping the flag is the rollback.
public sealed class RoutingDocumentsModule(
IFeatureManager features,
Documents.InProcess.DocumentsModule local,
Documents.Client.DocumentsHttpClient remote) : IDocumentsModule
{
public async Task<RenderedDocument> RenderQuotePdfAsync(RenderQuotePdf request, CancellationToken ct) =>
await features.IsEnabledAsync("Documents.UseRemoteService", ct)
? await remote.RenderQuotePdfAsync(request, ct)
: await local.RenderQuotePdfAsync(request, ct);
}
// Program.cs
builder.Services.AddFeatureManagement();
builder.Services.AddScoped<Documents.InProcess.DocumentsModule>();
builder.Services
.AddHttpClient<Documents.Client.DocumentsHttpClient>(c => c.BaseAddress = new Uri("https://documents.internal"))
.AddStandardResilienceHandler(); // timeout, retry with jitter, circuit breaker
builder.Services.AddScoped<IDocumentsModule, Host.Composition.RoutingDocumentsModule>();
AddStandardResilienceHandler), and prefer asynchronous messages where possible.The question isn't monolith vs microservices; it's where you need physical boundaries. Most systems need very few. I treat each extraction as its own business case with a driver, a cost estimate and a success metric, and I'd rather extract two services that clearly pay off than ten that don't.
Also watch the organisational side: a service without a clear owning team becomes an orphan. Extraction should follow team ownership (Conway's law), not precede it.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Stay modular monolith | One to a few teams, no strong scaling/isolation driver | Low | One module dominates resources or needs isolation |
| Extract one module | Clear driver, clean boundary, owning team | Medium per service | Boundary still leaky; no owner |
| Broad decomposition | Many teams, mature platform, independent cadences | High | Small org, unclear domain |
A modular monolith is one deployable split into modules aligned to business capabilities — Orders, Billing, Catalogue — each with hard boundaries.
DbContext, no cross-module joins or foreign keys.internal.internal types, architecture tests, even per-schema database permissions.You get microservice-style boundaries with monolith-style operations: one pipeline, in-process calls, easy refactoring. The trade-off: one runtime, one release and one scaling unit, and it only works if the boundaries are enforced — otherwise it decays into a big ball of mud.
Microservices are small, independently deployable services, each owning one business capability and its own data, talking over the network via APIs or messages.
They fit when you have several teams, stable boundaries and mature DevOps. Otherwise a modular monolith gives most of the benefits for a fraction of the cost. The worst outcome is a distributed monolith: all the cost, none of the independence.
Each service changes its own data and writes outgoing messages in one transaction (outbox), and dedups incoming messages (inbox). A saga orchestrator persists the order's progress: on OrderPlaced it sends ReserveStock; on StockReserved it sends CapturePayment; on PaymentCaptured it completes. If payment fails it sends the compensation ReleaseStock.
At every step a crash either committed nothing (the message is redelivered) or committed everything (the outbox resends). Duplicates hit the inbox. Missing replies trigger scheduled timeouts, and late replies after a timeout get their own handling, such as refunding a late capture. Poison messages dead-letter with alerts.
The trade-off: reliability without distributed transactions, paid for with eventual consistency, more states and more operational tooling.
How to tell it (STAR)
**S:** At [company] our modular monolith scaled to [8] instances every month-end because one module, PDF generation, used [70%] of the CPU. **T:** I was asked to fix the cost and the checkout slowdown without a rewrite. **A:** I proved the cause with Application Insights and dotnet-counters, wrote an ADR to extract only that module, and because it already had its own schema and a contract, we swapped the in-process implementation for messages through an outbox, moved its tables, and switched traffic gradually behind a feature flag with an instant rollback. **R:** Month-end instances for the main app dropped from [8] to [3], checkout p95 stayed under [400 ms], and we saved about [$3k] a month.
Last updated 23 Nov 2026.