Video in progress
You need to move a 10-year-old monolith to a new design. How do you plan the strangler fig approach, and where does it most often fail?
I put a routing layer in front of the monolith and move functions to a new module/service one at a time; each step is verified in prod and the old code is deleted. It most often gets hard at data migration, at the "two systems" left unfinished, and when the business doesn't stop new features.
📖 Answer
A "big rewrite" is almost always late: the old system is a moving target, and the new system doesn't know the old system's unwritten behavior. The strangler fig is gradual replacement.
The plan:
- Control the entry point. An API gateway or reverse proxy (or a facade inside the monolith): configuration decides where each endpoint goes.
- Choose the first piece. One with a clear boundary and real business value, but not central: for example, notifications or reports.
- The data strategy is the hardest part:
- the new module first reads the monolith's DB (temporarily);
- then it gets its own DB, synced with CDC (Debezium);
- in the end the monolith treats the new module as the source.
- Run in parallel and compare. For critical calculations, a "shadow" mode: both systems calculate, the results are compared, and only the old answer is returned. When the differences drop to zero, you move the traffic: 1% first, then 10%, then everything.
- Delete the old one. If the migrated code isn't removed from the monolith, supporting two systems goes on forever.
Where it fails:
- It never finishes. It stalls at 70%, and now you have two systems and double the operational load. Set an "old code deleted" criterion for each stage.
- No feature freeze. The business keeps adding new things to the monolith. The agreement: a new feature in an area being migrated goes only in the new system.
- The shared DB trap. The new service writes directly to the monolith's tables: no boundaries, just an extra deploy.
- The new design repeats old mistakes. Without an ACL, the old model moves into the new code.
Measure progress in a way the business can see: the share of traffic reaching the monolith, lines of code deleted, lead time in the migrated areas.
Sign up to mark studied questions and save your progress.