Migrating a NestJS Monolith to Microservices With Zero Downtime
Most “rewrite the monolith” stories end one of two ways: a heroic big-bang launch that breaks in production, or a migration that drags on for a year and never finishes. Neither is necessary. With the strangler-fig pattern and a bit of discipline, you can move a NestJS monolith to microservices one slice at a time, in production, with users online the whole way.
Why split at all?
A monolith is the right call early on — one repo, one deploy, fast iteration. The pain starts when unrelated parts of the system become coupled at deploy time: a change to billing forces a full redeploy, and a bug in one module can take everything down. If that is your reality, splitting along business boundaries buys you independent scaling and independent releases.
Note
Split by domain, not by layer
Good service boundaries follow business capabilities (orders, wallet, notifications), not technical layers (controllers, services, repositories). If two services constantly need to call each other to do one job, the boundary is wrong.
The target shape
An API gateway in front, independent services with their own data, async events over a message bus.
The strangler-fig migration
Instead of rewriting everything and flipping a switch, you put a gateway in front of the monolith and peel off one capability at a time. Each extracted service runs alongside the monolith until you trust it, then takes over its slice of traffic.
- Put an API gateway in front of the existing monolith — nothing else changes yet.
- Pick the most painful or most independent module and rebuild it as a service.
- Route a small percentage of its traffic to the new service; compare results.
- Ramp to 100%, then delete that code from the monolith.
- Repeat. The monolith shrinks until it is gone or reduced to a thin core.
Challenge
Keeping data consistent mid-migration
While both the old and new code paths are live, writes can land in two places. Dual-write with an idempotency key, or have the monolith publish events the new service consumes — so state converges no matter which path handled the request.
Wiring services with NestJS
NestJS has first-class microservice transport built in. For synchronous calls you can keep HTTP through the gateway; for everything else, prefer asynchronous messaging so services stay decoupled and resilient to each other’s downtime.
typescript// Emit an event instead of calling another service directly.
@Injectable()
export class OrdersService {
constructor(@Inject('BUS') private readonly bus: ClientProxy) {}
async place(order: CreateOrderDto) {
const saved = await this.repo.save(order);
// fire-and-forget: wallet + notifications react on their own schedule
this.bus.emit('order.placed', { id: saved.id, userId: saved.userId });
return saved;
}
}You need CI/CD before you need microservices
The whole approach depends on being able to deploy any single service safely and roll it back instantly. If a release is still a manual, all-or-nothing event, fix that first — otherwise microservices just multiply your deployment pain by the number of services.
Microservices are an organizational and operational choice before they are a technical one. If you can’t deploy and observe one service independently, you’re not ready to split.
Takeaways
- Split by domain boundaries, never by technical layer.
- Use the strangler-fig pattern: extract, route a slice, ramp, delete. Always reversible.
- Prefer async events over direct service-to-service calls.
- Invest in CI/CD and observability before the first service leaves the monolith.
Result
The payoff
Done this way, the migration is a series of small, boring, reversible steps — not a dramatic launch. Users never notice, and you end up with services you can scale and ship on their own.
See how we applied similar event-driven patterns in our Crypto Exchange Backend case study, or check our Backend & API Development services if you are planning a monolith split.
Working on something like this?
I build NestJS backends and AI integrations for SaaS, fintech and crypto products. Happy to talk through your architecture.
Get in touch →