Architecture · · 8 min read
Eating the monolith, one slice at a time.
Rewrites fail. Slicing works. How to carve services and micro frontends out of a legacy system, with each new piece able to run on its own or plugged back into the old application.
By Precision Code Studios, Engineering team
Every successful software company eventually owns a monolith: one large application that does everything, deployed as a single unit, understood in full by nobody. It made the company what it is. It is also why a small change now takes three weeks, why two teams cannot release on the same day, and why the newest engineers are afraid of the oldest folders.
The tempting answer is to rewrite it. Stop, start clean, and switch over when the new system is ready. This is the most reliably disappointing project in software. The old system keeps changing while the new one chases it, the business waits years for anything it can use, and the switch-over is a single enormous bet.
The alternative: replace it while it runs
The approach that works is usually called the strangler fig pattern, after a plant that grows around a tree until it stands in the tree's place. You do not replace the monolith. You take one capability at a time, build it properly outside, send traffic to the new version, and delete the old code. The monolith keeps running throughout and simply gets smaller.
- Value arrives early. The first slice is in production in weeks, not at the end of a multi-year plan.
- Risk comes in small pieces. Each move is small enough to test thoroughly and to reverse.
- You can stop at any time. If priorities change, everything already moved keeps working.
Slicing the back end into services
A slice is a business capability, not a technical layer: billing, notifications, search, reporting. A good first candidate changes often, has clear edges and does not sit in the middle of everything. Put a routing layer in front of the monolith so that requests for that capability can be sent to the new service without the rest of the system noticing. Give the service its own data, because two systems writing to the same tables are still one system. Where the old and new worlds must talk, translate at the boundary so the old model's quirks do not leak into the new code.
The part most plans forget: the screen
Teams often split the back end beautifully and leave one giant front end sitting on top. The result is services that deploy independently behind a user interface that cannot. Every feature still queues for the same release. To finish the job, the interface has to be sliced too, into micro frontends: each capability owning its own screens as well as its own logic and data.
Why an iframe is a serious answer
There are fashionable ways to compose micro frontends, and there is the humble iframe. For a legacy migration the humble option is often the best one. The monolith's page keeps its menu and header, and where the old billing screens used to be it shows a frame containing the new billing application.
- Total isolation. The new application's styles and scripts cannot collide with fifteen years of legacy code, and the legacy code cannot break the new application.
- Freedom of technology. The monolith can stay on its old framework while each new slice uses a current one.
- Truly independent releases. The team ships its slice whenever it is ready. The monolith does not even need a redeploy.
- Almost no change to the old system. The host needs one page with a frame on it. That matters when the old code is fragile.
Standalone and plugged in
The detail that makes this approach powerful is that each micro frontend is a complete application in its own right. Open its address directly and it runs alone, with its own sign-in and its own navigation. That is how its team develops and tests it, without starting the monolith at all. Load the very same build inside the monolith's frame and it recognises that it has a host: it hides its own header, takes the user's identity from the host, and behaves like one more screen of the old product.
This has a consequence worth pausing on. On the day the monolith is finally switched off, nothing has to be rebuilt. Every slice already stands on its own. All that is needed is a thin new shell to hold them, and the old one can go.
The details that decide whether it feels like one product
- Sign-in. The host passes a short-lived token to the frame, so the user never signs in twice.
- Talking across the frame. Host and frame exchange a small, documented set of messages, and each side checks where a message came from before trusting it.
- Addresses. The page address should follow what the frame is showing, so links, bookmarks and the back button work.
- Size. The frame reports its height so the page scrolls as one, never as a box within a box.
- Look and feel. Shared design tokens for colour, type and spacing keep old and new screens visually consistent.
- Dialogs and focus. A pop-up inside a frame cannot cover the host. Plan full-page dialogs through the host, and keep keyboard navigation working across the boundary.
The honest costs
Frames are not free. Each one loads its own copy of its framework, so a page built from many small frames gets heavy; they suit whole screens far better than small widgets. Communication across the boundary is deliberate work. And on the back end, a distributed system brings its own problems: more things to deploy, monitor and secure. Slicing is worth it when the monolith is genuinely holding teams back. A small product with one team should stay a monolith and be glad of it.
A plan for the first ninety days
- Choose one capability. High rate of change, clear edges, a team that wants it.
- Put the routing layer in place. At first it sends everything to the monolith. That is fine.
- Build the service and its micro frontend together. Runnable alone from the first day.
- Frame it into the monolith behind a switch. Turn it on for staff, then for a small share of customers.
- Move the data, then delete the old code. This is the step that gets skipped, and the one that matters most.
A migration is not finished when the new code ships. It is finished when the old code is gone. Take one slice all the way to that point and the second is easier, the third is routine, and one day the monolith is simply a shell that nobody misses.