How would you split a modular .NET monolith into microservices without creating a distributed monolith?
Razorpay · Full Stack Developer · 3-4-years · technical
Published
Year not specified · .NET, Microservices, System Design
Community answers
Posted by wasAsked editorial collection
Start by making module boundaries real inside the monolith: each module owns its domain, application API, and data access; other modules use contracts rather than its tables. Add observability and identify a boundary with an independent business need, scaling profile, team ownership, and acceptable failure semantics.
Extract one capability using a strangler approach. Define a versioned API/event contract, move data ownership, use an outbox for reliable events, route a small percentage, compare outcomes, then retire the old path. Avoid a shared database after extraction. Account for latency, retries, idempotency, security, deployment, and operations. Microservices add failure modes, so extraction should solve a measured problem rather than follow fashion.
Backbencher Developer · · 0 likes
A distributed monolith has the costs of microservices (network calls, deployments, eventual consistency) without the benefits, because services still change and deploy together. Avoid it by splitting along real business boundaries and keeping services autonomous.
1. Start from a well-structured modular monolith
- Identify bounded contexts with domain-driven design and event storming: Orders, Payments, Catalog, Shipping.
- Enforce module boundaries in code: modules communicate only through public interfaces or in-process events, never by reaching into each other's tables. Architecture tests (NetArchTest) can enforce this.
- Give each module its own schema or tables.
2. Choose what to extract and why
- Extract a module only for a concrete reason: independent scaling, different release cadence, team ownership, or fault isolation. "Because microservices" is not a reason.
- Start with a module that has few inbound dependencies and clear data ownership.
3. Data ownership
- Each service owns its data; no shared database tables. Other services get data through APIs or by subscribing to events and keeping local read copies.
- Use the outbox pattern so state changes and published events stay consistent.
4. Communication
- Prefer asynchronous events for propagating changes; use synchronous calls sparingly, with timeouts and circuit breakers.
- Long synchronous chains or a service that cannot work when another is down are warning signs.
5. Migrate incrementally (strangler fig)
- Route traffic through a gateway or facade, move one capability at a time, run old and new in parallel when needed, and remove the old code afterwards.
6. Signs of a distributed monolith
- Several services must be deployed together for one feature.
- Shared libraries containing domain models that force lockstep upgrades.
- Chatty calls: one request fans out to many services synchronously.
- Shared database or distributed transactions everywhere.
7. Platform readiness
- CI/CD per service, observability (tracing, central logs), contract tests and versioned APIs must exist before you split, or operations become painful.