đ Monolith to Microservices
Strangler Fig Pattern
The safe, incremental strategy for migrating a live monolith to microservices
Named after the strangler fig tree that grows around a host tree and eventually replaces it, this pattern lets you migrate a live production system without a risky Big Bang rewrite. 80% of Big Bang rewrites fail â the Strangler Fig succeeds by never stopping the old system until the new one fully replaces it.
Key Concepts
Never Stop the Monolith
The monolith serves 100% of traffic on day 1. You slowly drain it. No big-bang cutover. If something breaks, traffic re-routes back instantly.
API Gateway is the Key
All traffic enters through a Gateway (Nginx, Kong, AWS API GW). The gateway decides: send to monolith or new microservice. This is your routing table.
Extract Leaf Domains First
Start with domains with few incoming/outgoing dependencies: Notifications, Reviews, File Uploads. Save Orders and Payments for last â they have the most cross-domain calls.
Dual-Write During Transition
During cutover, write to both old and new DB simultaneously. Validate consistency. Only switch reads after confidence is established.
The Strangler Fig Pattern in Action
The 4-Step Strangler Fig Process
- Step 1: Deploy API Gateway in front of Monolith â all requests go through it. Zero change to users.
- Step 2: Extract one domain (e.g., /api/reviews) into a new Microservice with its own isolated DB.
- Step 3: Update Gateway routing â /api/reviews routes to new service. Monolith code remains but now unused for this domain.
- Step 4: Remove the dead code from the Monolith. Repeat for next domain. After all domains are extracted, decommission the monolith.
Routing Configuration Example (Nginx/Kong)
gateway.confnginx
1# API Gateway routing config â Strangler Fig pattern
2server {
3 listen 80;
4
5 # Phase 1: All legacy routes go to monolith
6 location / {
7 proxy_pass http://monolith:3000;
8 }
9
10 # Phase 2: Migrated route â /api/reviews now served by new microservice
11 location /api/reviews {
12 proxy_pass http://review-service:4001;
13 # Canary: initially 10% traffic, then 100%
14 }
15
16 # Phase 3: Another extracted service
17 location /api/notifications {
18 proxy_pass http://notification-service:4002;
19 }
20}Domain Extraction Order Strategy
| Priority | Domain | Reason |
|---|---|---|
| 1st (Easiest) | Notifications / Emails | Pure output, no shared state, fire-and-forget |
| 2nd | Reviews / Comments | Read-heavy, minimal write coordination |
| 3rd | User Profile | Self-contained, rarely shared schema |
| 4th | Product Catalog | High read traffic â great scaling win once separated |
| Last (Hardest) | Orders / Payments | Complex cross-domain transactions, Saga pattern needed |
đĄ
Senior Architect Insight: The strangler fig pattern has a secret superpower: it forces you to define a proper API contract between the new service and the rest of the system. If you can't draw a clean boundary, the domain isn't ready to be extracted yet.