You are staring at a codebase that has been running for years. It works. But every new feature feels like walking through a maze of tangled dependencies. The deployment pipeline is slow. One small change can break an unrelated part of the system. You know you need to move to microservices, but the thought of a big bang rewrite keeps you up at night. You do not want to tell your stakeholders that the application will be down for a weekend. You do not have to. It is possible to refactor monolith to microservices without downtime, and this guide shows you how.
The Strangler Fig pattern lets you incrementally replace pieces of a monolith with microservices while the old system stays live. You route traffic to new services one endpoint at a time. You sync data back to the legacy database during the transition. When the new service proves stable, you remove the old code. No downtime. No big bang rewrite.
Why incremental migration beats the big bang rewrite
A big bang migration means you build a new system from scratch, then cut over all users at once. That approach has a terrible track record. The new system often misses edge cases. Data gets corrupted. Users get angry. The rollback is painful because you have to restore the old database and hope nothing was lost.
Incremental migration, on the other hand, treats the monolith like a patient undergoing surgery. You operate on one organ at a time while the rest of the body keeps functioning. The Strangler Fig pattern is the most proven technique for this. Named after a vine that slowly grows around a tree, it lets you build microservices alongside the monolith. You gradually redirect traffic from the old code to the new services. If something goes wrong, you flip the traffic back. Users never notice a thing.
The Strangler Fig pattern in practice: a step by step plan
Here is the exact process I have used on multiple enterprise projects. It works whether you are running on bare metal, VMs, or containers.
-
Identify a bounded context to extract. Look for a feature that has a clear API boundary and minimal coupling to the rest of the monolith. Good candidates include user authentication, payment processing, or notification delivery. Bad candidates are features that touch dozens of database tables and share session state.
-
Create an API gateway or a routing layer. This is the traffic cop. It sits in front of your monolith. You configure it to send requests for the chosen feature to the new microservice. All other traffic continues to flow to the monolith. Kong, NGINX, and AWS API Gateway are popular choices.
-
Build the microservice with its own data store. Write the new service from scratch or extract the relevant code. Give it its own database. Do not share the monolith’s database directly. Use an event driven approach or a data sync layer to keep the two systems consistent during the transition.
-
Route traffic to the new service gradually. Start by routing a small percentage of requests, or route requests from internal testing tools first. Monitor error rates, latency, and data consistency. Increase the percentage as you gain confidence.
-
Run both systems in parallel. This is the critical phase. The monolith and the microservice both handle the same type of request. The microservice writes to its own database and also pushes updates back to the monolith’s database. That way, if you need to roll back, the monolith has all the latest data.
-
Remove the old code. Once the microservice has handled 100% of traffic for a few weeks without issues, you delete the corresponding code from the monolith. You also remove the data sync logic. The monolith becomes smaller and easier to maintain.
Common mistakes that cause downtime
Even with the Strangler Fig pattern, you can cause downtime if you ignore certain pitfalls. Here is a table of techniques versus mistakes.
| Technique | Mistake to avoid | Why it matters |
|---|---|---|
| Use an API gateway for routing | Cutting over all traffic at once | A gradual rollout lets you detect problems early without affecting all users |
| Keep a data sync layer | Assuming eventual consistency is automatic | You need explicit sync logic, or the monolith will miss data written by the microservice |
| Run both systems in parallel | Skipping the parallel run to save time | Without a parallel run, you have no fallback if the microservice has a bug |
| Monitor error rates and latency | Only monitoring uptime | A service can be up but returning wrong data or timing out under load |
| Extract one bounded context at a time | Trying to extract too many features simultaneously | Overlapping changes create cascading failures that are hard to debug |
What you need in place before you start
You cannot just start carving out microservices. You need a solid foundation first. Here are the prerequisites.
-
Comprehensive automated tests. You need a test suite that covers the critical paths of the monolith. Without it, you cannot be sure that your extraction did not break something. If your monolith has zero tests, start by adding integration tests for the feature you plan to extract. This is non negotiable.
-
Feature flags. A feature flag system lets you turn the new microservice on and off without deploying code. LaunchDarkly or a simple database backed flag both work. When the flag is off, all traffic goes to the monolith. When it is on, traffic goes to the microservice. This gives you an instant kill switch.
-
Observability. You need logs, metrics, and tracing across both the monolith and the new microservice. If something goes wrong, you need to know where. Tools like OpenTelemetry, Datadog, or even the ELK stack can help. Without observability, you are flying blind.
-
A rollback plan. Write down exactly what you will do if the microservice fails. The plan should include reverting the API gateway configuration, turning off the feature flag, and restoring the data sync if needed. Practice the rollback in a staging environment.
Why data consistency is the hardest part
The monolith’s database holds the source of truth. When you extract a microservice, you need to decide who owns what data. The cleanest approach is to give the microservice its own database and let it own its domain completely. But during the transition, the monolith still needs to read and write that data.
The solution is a data sync layer. The microservice writes to its own database and then publishes an event. A sync worker reads that event and writes the same data to the monolith’s database. The monolith can also write to its own database, and a reverse sync worker pushes those changes to the microservice. This dual write pattern is temporary. Once the monolith no longer needs the data, you remove the sync.
Expert advice: Do not try to keep both databases perfectly consistent in real time. Accept a few seconds of latency. Use an idempotent sync mechanism so that replaying events does not cause duplicates. If you need stronger consistency, consider using a shared database temporarily, but that couples the services and defeats the purpose of the migration.
How to handle authentication and session state
Authentication is often the first feature teams extract because it is a clear bounded context. But session state can be tricky. The monolith likely stores sessions in memory or in a local database. The new auth microservice will use its own session store.
The trick is to use a token based approach. The auth microservice issues JWTs or opaque tokens. The monolith and other microservices validate the token without needing to call the auth service on every request. During the transition, the monolith can accept both its old session cookies and the new tokens. This dual acceptance period lets you migrate users gradually without forcing them to log out.
A real world example: extracting payment processing
Imagine your monolith handles everything including payment processing. The payment code is deeply intertwined with the order management code. Here is how you would extract it without downtime.
First, you identify the payment bounded context. It includes charging credit cards, handling refunds, and storing transaction logs. You create a new payment microservice with its own database. You build an API gateway that routes all /payments/* requests to the new service.
Next, you set up a data sync. When the payment service creates a transaction, it writes to its own database and also publishes a payment.completed event. A sync worker listens for that event and updates the monolith’s orders table with the payment status. The monolith still owns the order data, but it no longer handles payment logic.
You run both systems for two weeks. During that time, you monitor error rates and compare transaction counts between the two systems. After two weeks with zero discrepancies, you remove the payment code from the monolith. The monolith’s orders table still receives payment status updates via the sync, but eventually you will move order management to its own service as well.
When to stop and when to keep going
You do not have to extract every single feature. Some parts of the monolith are fine as they are. The goal is to reduce pain points, not to achieve architectural purity. If a module is stable, has low change frequency, and does not block your team, leave it in the monolith.
A good rule of thumb is to extract a feature when two or more of these conditions are true:
- The team working on it needs to deploy independently from the rest of the system.
- The feature has different scaling requirements. For example, a reporting feature that runs heavy queries should not slow down the checkout flow.
- The code is causing frequent bugs in unrelated parts of the system.
- The feature needs a different technology stack. Maybe you want to use a graph database for your recommendation engine while the rest of the monolith uses PostgreSQL.
The role of your CI/CD pipeline
Your CI/CD pipeline must support deploying the monolith and the microservices independently. If your pipeline deploys everything as one unit, you will struggle. You need a pipeline that can deploy the monolith without touching the microservices and vice versa.
Start by splitting the monolith’s deployment into separate jobs for each bounded context, even if they still live in the same repository. This prepares you for the eventual extraction. Use a monorepo tool like Nx or Turborepo to manage dependencies between services while keeping the code in one place. Over time, you can move each service to its own repository if that suits your team structure.
For more on setting up a modern development environment, check out our guide on master modern web frameworks for faster development. It covers tooling that complements a microservices architecture.
The future after the migration
Once you have extracted a few services, you will notice a shift in how your team works. Deployments become faster. Teams can choose the right tool for each job. The monolith shrinks and becomes easier to understand.
But microservices introduce their own challenges. You now need service discovery, circuit breakers, and distributed tracing. You need to handle network failures gracefully. You need to think about data consistency across services. These are solvable problems, but they require a different mindset.
If you are new to building distributed systems, read our guide on the developer’s guide to building resilient microservices in 2026. It covers patterns like retries, timeouts, and bulkheads that keep your system running when things go wrong.
A final thought on team communication
The technical side of this migration is only half the battle. The other half is keeping your team and stakeholders informed. Explain that the migration will take months, not weeks. Show them the incremental progress by celebrating each extracted service. When something goes wrong, be transparent about the rollback. A failed extraction is not a failure. It is data that helps you improve the next attempt.
You already have the skills to do this. You understand APIs, databases, and deployment pipelines. The Strangler Fig pattern gives you a safe path forward. Start small. Pick one feature. Build the microservice. Route a little traffic. Observe. Repeat.
Before you know it, you will have a system that is easier to maintain, faster to deploy, and much more pleasant to work with. And you did it without ever taking the application offline.