Migrating from a Modular Monolith to Microservices
When and how to extract a module into a microservice: signals that justify it, step-by-step extraction, data migration, strangler routing and pitfalls.
Published November 27, 2026
One of the strongest arguments for a modular monolith is that it keeps the microservices option open. When a module genuinely needs to be independent, its clean boundaries make extraction a manageable project rather than a rewrite. This article covers when extraction is justified and a step-by-step process that keeps the system working throughout.
The concept
Extraction should be driven by concrete needs, not by a desire to "be microservices". Good reasons include a module with very different scaling needs (an image processing or search module), a module that must deploy on a different cadence or by a separate team, different technology requirements (a Python ML model inside a PHP app), stricter isolation for security or compliance, or failure isolation so a misbehaving component cannot take down the rest.
The extraction itself follows the strangler pattern: introduce a network boundary behind the existing public API, move the module's code and data to a new service, switch callers over gradually, and only then remove the old code. Because the module already communicated through a facade and events, most of the application does not notice the change.
Signals that justify extraction
| Signal | Example |
|---|---|
| Independent scaling | Search needs 20 nodes at peak; the rest needs 3 |
| Independent deployment | Pricing rules change daily; core app deploys weekly |
| Different technology | Recommendation model in Python, app in PHP |
| Team ownership | A separate team owns the module end to end |
| Isolation | PCI-scoped payments isolated from everything else |
| Failure isolation | Heavy PDF generation should not starve web requests |
Step-by-step extraction
- Verify the module boundary: no cross-module table access, clean facade and events
- Define the service contract (HTTP/gRPC API + event schemas) matching the facade
- Build the service; replace the in-process facade with a client behind a feature flag
- Move data: replicate or migrate the module's tables to the service's database
- Shift traffic gradually, monitor, then remove the in-process implementation
- Move events to a broker with an outbox on both sides
Swapping the implementation
What gets harder after extraction
Be explicit about the new costs before starting. In-process calls become network calls that can time out and need retries and circuit breakers. Transactions spanning the extracted module become sagas. You need service discovery, a deployment pipeline, monitoring, tracing and on-call for the new service. Local development gets more complex. If the signals above are weak, these costs usually outweigh the benefits.
Practical examples
Client implementing the same interface as the old facade
Swap in-process and remote implementations via DI and a flag.
export interface PricingApi { quote(cart: CartDto): Promise<PriceQuoteDto> }
@Injectable()
export class RemotePricingClient implements PricingApi {
constructor(private readonly http: HttpService) {}
async quote(cart: CartDto) {
const { data } = await firstValueFrom(
this.http.post<PriceQuoteDto>('http://pricing/quotes', cart, { timeout: 800 }))
return data
}
}
// provider factory chooses InProcessPricing or RemotePricingClient per feature flagShadow traffic before switching
Call both implementations, serve the old result, and compare.
const [local, remote] = await Promise.allSettled([inProcess.quote(cart), remoteClient.quote(cart)])
if (remote.status === 'fulfilled' && local.status === 'fulfilled'
&& remote.value.totalPaise !== local.value.totalPaise) {
metrics.increment('pricing.shadow_mismatch')
}
return local.status === 'fulfilled' ? local.value : Promise.reject(local.reason)Data migration with logical replication (PostgreSQL)
Keep the new database in sync until cutover.
-- on the monolith database
CREATE PUBLICATION pricing_pub FOR TABLE pricing.rules, pricing.price_lists;
-- on the new service database
CREATE SUBSCRIPTION pricing_sub CONNECTION 'host=monolith-db dbname=app user=repl'
PUBLICATION pricing_pub;Common mistakes
- Extracting a module whose boundaries are not clean yet, creating a distributed monolith.
- Big-bang cutovers without flags, shadow traffic or rollback.
- Keeping a shared database after extraction, so the service is not really independent.
- Underestimating operational work: pipelines, monitoring, on-call, tracing.
- Extracting many modules at once instead of one, learning from it, then deciding on the next.
Key takeaways
- Extract only for concrete drivers: scaling, deployment cadence, technology, ownership or isolation.
- Clean the boundary first; then put a network boundary behind the existing facade.
- Use flags, shadow traffic and data replication for a gradual, reversible cutover.
- Plan for the new operational and consistency costs.
FAQ
How long does an extraction take?
For a well-bounded module, weeks rather than months. Most of the time goes into data migration, operational setup and verification.
Should the extracted service keep the same database technology?
Not necessarily; extraction is a chance to choose what fits. Changing technology at the same time adds risk, so many teams migrate first and switch later.
Can I merge a service back into the monolith?
Yes, and it is sometimes the right call when a service turns out to be tightly coupled. Clean interfaces make reversal possible.