How to Migrate a Monolith to Microservices Without a Big Rewrite

How to Migrate a Monolith to Microservices Without a Big Rewrite

To migrate a monolith to microservices without stopping feature work, extract one service at a time while the monolith keeps running. No freeze, no six-month rewrite, no launch day where everything changes at once. The strangler fig pattern makes this possible: you put a thin layer in front of the monolith, move one slice of traffic to a new service, and repeat until little of the old system matters. That is how you get microservices without a rewrite, and it works because each step is a normal deploy you can roll back.

Why Big Rewrites Fail and Small Extractions Work

A big rewrite means months of building a second system in parallel while the first one keeps changing underneath you. Features land in the monolith, bugs get fixed there, and the target moves every week. The new system arrives late, untested in production, and missing half the behavior the old one accumulated over years.

Small extractions avoid that trap. Each step is a normal deploy: one service leaves the monolith, traffic shifts gradually, and you can roll back if something breaks. The monolith stays the system of record for everything you have not moved yet.

How to Migrate a Monolith to Microservices in Small Steps

The sequence below is the whole method. Each step ships to production before the next one starts, so the system is always in a working state. To migrate a monolith to microservices this way is to extract services incrementally, one seam per deploy:

  1. Pick one seam: a module with clear inputs and outputs and few calls into the rest of the code.
  2. Put a routing layer in front of the monolith so traffic can move service by service.
  3. Build the new service behind that layer, with the monolith still handling the real traffic.
  4. Shift a small share of traffic, watch it, then shift the rest.
  5. Move the data last, once the service behavior is proven.
  6. Delete the old code from the monolith and repeat with the next seam.

Step 1: Pick the First Seam, Not the Most Important One

The first service you extract should be easy, not important. Look for a module with a narrow interface: it takes a few inputs, returns a few outputs, and touches little shared state. Good candidates are notifications, image processing, report generation, or search indexing. Bad candidates are the core domain model, the user session, or anything every module calls.

Three questions help you judge a seam. Can you name its inputs and outputs in one sentence? Does it own its own data, or read tables owned by other modules? Heavy shared reads mean splitting the database too early. Can it fail without taking the rest of the system down?

Also check how the code is organized before you cut. If several teams share one repository, where the new service lives matters as much as the code itself, and this comparison of monorepo vs polyrepo for small teams lays out the trade-offs.

Step 2: Put a Routing Layer in Front of the Monolith

Before you build any service, add something that can send a request either to the monolith or to a new service, usually an API gateway or a reverse proxy with path-based rules. Requests for /api/notifications go to the new service; everything else goes to the monolith.

The routing layer does two jobs. First, it lets you move traffic gradually: 1 percent, then 10, then all of it. Second, it gives you one place to add authentication, rate limiting, and logging once instead of rebuilding them in every service. Keep the gateway thin: route, authenticate, log. Business logic in the gateway becomes a second monolith.

Step 3: Build the New Service Behind the Gateway

Build the service as a small application of its own: its own codebase, deploy pipeline, and tests. At this stage it still reads from the monolith database or calls back into the monolith for data it does not own yet. That is fine: the goal is a service that behaves correctly, not one that is fully independent.

Define the contract first: the API the service exposes, the shape of its requests and responses, and what happens when it fails. Both sides should agree on it before you write the implementation, because changing it later means changing two systems at once. If you are choosing between API styles, this guide to REST vs GraphQL vs gRPC in 2026 compares the trade-offs for service-to-service calls.

Step 4: Use the Strangler Fig Pattern to Shift Traffic

The strangler fig pattern is the mechanism that makes the whole migration safe. The name comes from a fig tree that grows around a host tree, gradually replacing it. Your gateway is the fig: it starts by sending all traffic to the monolith, then peels off one route at a time to the new service.

Shift traffic in stages and watch the numbers at each stage: error rates, latency, and business outcomes on the old path versus the new one. If the new service misbehaves at 1 percent of traffic, you lose 1 percent of requests, not all of them. Roll back by flipping the route, fix the problem, and try again.

Step 5: Split the Database Last

The database is where migrations get painful, because the monolith and the new service often need the same tables. Split the data after the service works, not before. While the service still reads monolith tables, use an anti-corruption layer: a small adapter inside the service that translates the monolith schema into the shape the service wants. That adapter keeps the monolith schema from leaking into the new service.

Split the data in stages. Replicate the tables the service needs into its own database, read-only at first, then switch the service to read from its own copy and check the results match. Move writes over one operation at a time, then stop the monolith from writing to those tables.

Never let two services write to the same table. Shared writes rebuild the monolith as a distributed one, with all of the coupling and none of the benefits. If two services need the same data, one owns it and the other reads it through an API or an event. This guide to database migrations without downtime covers expand-and-contract changes, which let you deploy the new schema before the code that uses it.

Step 6: Make the New Service Observable Before You Need It

A monolith fails in one place. In a monolith to microservices migration, services fail in the spaces between them, and those failures are harder to see. Before you shift real traffic, give the new service structured logs, metrics, and distributed tracing with a correlation ID on every request. When a user reports a slow page, you need to follow one request across the gateway, the monolith, and the new service in a single view.

Set up alerts on error rate, latency, and saturation. A service that nobody watches fails quietly for hours. You also need a contract test that checks the service against the API the monolith expects, and an end-to-end test that walks the real path through the gateway.

Step 7: Decide How to Run the New Service

Your first extracted service does not need Kubernetes. A container on the host you already use, or a small Compose setup, is enough for one or two services. This comparison of Docker Compose vs Kubernetes and when to use each is a good check before you commit to a cluster for a single service. Whatever you choose, give each service a health endpoint, a deploy pipeline, resource limits, and a way to roll back.

A Checklist You Can Reuse

Run through this list for each service you extract:

  1. Pick a seam with a clear boundary and low blast radius.
  2. Add the route to the gateway before building the service.
  3. Write the API contract and get both sides to agree on it.
  4. Build the service with its own tests and deploy pipeline.
  5. Shift 1 percent of traffic, compare error rates and latency, then scale.
  6. Keep the old code until the new service has handled real traffic.
  7. Move the data with an anti-corruption layer and expand-and-contract schema changes.
  8. Add logs, metrics, tracing, and alerts before the full shift.
  9. Delete the old code from the monolith and confirm its tests still pass.
  10. Write down what you learned before picking the next seam.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.