Rebuild or rescue a legacy app: how to decide
A full rewrite is the most expensive way to fix software. Here is the test for when a rebuild is genuinely the cheaper option, and when it is not.
12 min readBy Team Stallwart
On this page
The short answer
A full rewrite is the most expensive way to fix software, and it is the easiest decision to justify emotionally. Everybody who works on an old system wants to replace it, because the pain is daily and the replacement is imaginary and therefore perfect. That asymmetry, not an engineering analysis, is what drives most rewrite decisions.
The test that holds up is narrow. A rebuild is the cheaper option when the thing that is wrong cannot be reached incrementally: the data model is wrong at the root, the platform is out of support with no upgrade path, or the architecture makes a change the business now requires structurally impossible. Everything else, including ugly code, missing tests, slow pages, and a stack nobody wants to work in, is almost always cheaper to fix in place.
The reason is not sentiment about old code. It is that a working system, however unpleasant, encodes years of accumulated correctness that nobody has written down: the edge cases, the exceptions, the quiet fix for the customer whose data was always different. A rewrite starts by deleting that knowledge and then rediscovers it one production incident at a time. That rediscovery is the real cost of a rewrite, it is almost never in the estimate, and it is why rewrites overrun in a pattern that looks the same across very different companies.
Why the rewrite instinct is usually wrong
Start with the comparison that gets made. The existing system is judged on everything it does badly, which is visible every day. The replacement is judged on an imagined version that does everything well, because it does not exist yet and therefore has no flaws. No real system has ever won that comparison, including the replacement once it ships.
Then there is the part of the estimate that is always missing. A rewrite has to reproduce the whole surface of the old system before it can be switched on, including the twenty percent of features that eighty percent of users never touch but a specific important customer depends on absolutely. Those features are not in anybody's head, they are not in the documentation, and they surface during migration as a series of small emergencies.
Meanwhile the old system cannot be frozen. The business keeps needing changes, so either the team maintains two codebases at once, which roughly doubles the cost of every change during the rewrite, or it freezes features for the duration, which is a commitment almost no business can actually keep. The usual outcome is a partial freeze that satisfies nobody, and a rewrite whose target keeps moving.
And the risk profile is the opposite of what it feels like. Incremental change ships small pieces that can each be verified and reverted. A rewrite concentrates all of the risk into one switch-over event. Every verification happens at once, under pressure, usually at a weekend, with no good way back. That is the most dangerous shape a software project can have, and it is the shape a rewrite necessarily takes.
The four cases where a rebuild is genuinely cheaper
There are real cases. They have a specific quality in common: the problem is in a foundation that incremental change cannot reach, so the incremental path does not converge no matter how long you walk it.
The first is a data model that is wrong at the root. Not untidy. Wrong in a way that makes correct behaviour impossible: one entity doing the work of three, a relationship the business genuinely has that the schema cannot express, identity handled in a way that makes multi-tenancy or auditability unachievable. Every feature then fights the schema, and the workarounds accumulate faster than the features. This is the strongest rebuild case, and it is the one worth testing hardest, because a schema that is merely awkward can usually be migrated in place.
The second is a platform with no upgrade path. A framework, runtime, or database version that is out of support, where the vendor's migration route has been removed or was never there, and where security patches have stopped. This is a hard deadline set by someone else, and the decision is about timing rather than whether.
The third is an architecture that structurally cannot do what the business now requires. A single-tenant application that has to become multi-tenant. A system built entirely around synchronous requests that now needs to process long-running work reliably. A desktop-era data model being asked to serve a mobile client with offline behaviour. When the requirement contradicts a foundational assumption, incremental change ends up building the new architecture alongside the old one anyway, and doing that deliberately is cheaper than doing it by accident.
The fourth is the honest commercial case: the system works but nobody can safely change it, and the cost of that is now larger than the cost of replacement. This is measurable rather than a feeling. How long does a one-line change take to ship? What share of changes cause an incident? How many people can safely deploy it? If a small change takes weeks, breaks something more often than not, and only one person dares to do it, the maintenance cost is already paying for a rebuild every year without producing one.
- The data model is wrong at the root, so every feature fights the schema rather than merely working around it.
- The platform is out of support with no migration path, which is a deadline set externally.
- The architecture structurally contradicts a requirement the business now has.
- Change has become unsafe and slow enough that measured maintenance cost already exceeds replacement cost.
What a rescue actually involves
A rescue is not a tidy-up, and describing it as refactoring undersells it. It is a sequence with an order, and the order matters more than any individual step.
The first move is to make the system observable and reversible, because nothing else is safe until it is. That means structured logs and error tracking so failures are visible rather than reported by customers, a deployment path that can be reverted in minutes, and a staging environment that resembles production closely enough to tell you something. None of this changes a line of business logic, and it is what makes every later step possible.
The second move is a test harness around the behaviour you must not break, built from the outside. Not unit tests on the internals you are about to change, which lock in the current structure. End-to-end tests that exercise the real paths through the system and assert the outcomes the business depends on. These tests are the thing that lets you change the inside with confidence, and in a rescue they are the highest-value code anybody writes.
The third move is to stop the bleeding at the top of the list: the specific slow page, the specific nightly job that fails, the specific dependency that cannot be patched. Fixing the three worst things usually changes the organisation's mood about the system more than six months of architectural work, and that matters, because a rescue needs continued support to finish.
Only then is it worth restructuring, and the technique that works is to carve out one capability at a time behind a stable interface. New code goes into the new structure; old code gets moved when it is touched for another reason. The old system keeps running throughout, each piece is verified in production as it moves, and the project can stop at any boundary with the work so far still delivering value. That last property is the one a rewrite cannot offer, and it is the whole argument.
The decision about who should do this work is not the same as the decision about who should build new features. A rescue rewards people who have done it before, because the sequencing is counterintuitive and the failure modes are specific. The general version of that evaluation is covered in [custom development versus an in-house team](/blog/custom-ai-development-vs-in-house-team), and the vendor-selection questions in [how to tell an engineering specialist from a generalist](/blog/ai-engineering-company-vs-dev-shop) transfer directly.
The middle path, and how to keep it honest
Most real answers are neither a full rewrite nor an indefinite rescue. They are an incremental replacement: the old system keeps serving traffic while new capabilities are built alongside it, and functionality moves across one piece at a time until the old system is doing little enough to retire quietly. There is no switch-over weekend, because there is no single switch.
What makes this work is that a boundary has to be real, not notional. The new component owns its data, the old system reads it through an interface rather than reaching into its tables, and traffic can be routed to either side and back. Where both sides need the same data during the transition, which direction is authoritative has to be decided and written down per entity, because this is the specific place incremental migrations go wrong: two systems both believing they own a record, and a reconciliation job quietly papering over the disagreement.
What makes it fail is the absence of an end date and an owner. An incremental migration with no deadline becomes permanent, and permanent means maintaining two systems, two deployment paths, and two mental models indefinitely. That is worse than either pure option. The discipline is to name the capabilities that will move, in order, with a date by which the old system is retired, and to treat a slipped date as a decision point rather than a status update.
It is also worth being explicit about what you will not move. Some functionality in an old system is genuinely dead, used by nobody, and retiring it is cheaper than migrating it. Finding that out requires instrumentation rather than opinion: log what is actually used for a quarter before deciding what has to be reproduced. Teams routinely discover that a meaningful share of the surface they were planning to rebuild has no users at all.
Deciding, and writing it down
The decision deserves a short written document, because the main risk is that it gets made on frustration and then defended on sunk cost. Four things belong in it.
First, the specific problem, stated as something a change would fix rather than as a complaint about the code. Second, the measurements: how long a small change takes to ship today, what share of changes cause an incident, how many people can deploy safely, and what the system costs to run. Third, which of the four rebuild cases applies, if any, and the evidence for it rather than the intuition. Fourth, the thing the rebuild case is tested against: what the incremental path would cost to fix the same problem, estimated with the same seriousness as the rebuild.
If the rebuild case is real, that document is also the scope control for the project, because it names what the rebuild is for. A rebuild without that constraint expands to include every improvement anybody has wanted for years, which is how a twelve-month estimate becomes a three-year programme.
If the rebuild case is not real, the same document is the rescue plan, in the order above: observability and reversibility first, then tests around behaviour that must not break, then the three worst specific problems, then restructuring behind stable interfaces, one capability at a time.
That is the conversation Stallwart would want to have first. If the honest answer is that the system should be rescued rather than replaced, that is a smaller engagement than a rebuild, and it is the one we would recommend.
The short version
- A rewrite compares a real system judged on its daily faults against an imagined one with none. No existing system wins that comparison, including the replacement once it ships.
- The cost nobody estimates is rediscovering the undocumented correctness a working system accumulated, one production incident at a time.
- A rebuild is genuinely cheaper in four cases: a root-level data model error, an unsupported platform with no upgrade path, an architecture that contradicts a new requirement, or measured maintenance cost already exceeding replacement.
- Rescue has an order: observability and reversibility, then end-to-end tests around behaviour that must not break, then the three worst specific problems, then restructuring behind stable interfaces.
- Incremental replacement needs real boundaries and a named retirement date. Without the date it becomes permanent, which is worse than either pure option.
- Instrument before deciding what to reproduce. A meaningful share of the surface teams plan to rebuild turns out to have no users.
Questions this raises
- Should we rewrite our legacy application or refactor it?
- Refactor, unless the problem is in a foundation that incremental change cannot reach. A rebuild is the cheaper option when the data model is wrong at the root, the platform is out of support with no upgrade path, the architecture structurally contradicts a requirement the business now has, or change has become so slow and unsafe that measured maintenance cost already exceeds replacement. Ugly code, missing tests, slow pages, and an unfashionable stack are all cheaper to fix in place.
- Why do software rewrites usually overrun?
- Because the estimate covers rebuilding the known features and not rediscovering the undocumented correctness the old system accumulated: edge cases, exceptions, and the quiet fixes for customers whose data was always different. On top of that, the old system cannot be frozen, so the team either maintains two codebases at once or attempts a feature freeze the business cannot keep. The target keeps moving while the cost of every change roughly doubles.
- What are the signs that a legacy system genuinely needs replacing?
- Measure rather than infer. How long does a one-line change take to ship? What share of changes cause an incident? How many people can deploy it safely? What does it cost to run? If a small change takes weeks, breaks something more often than not, and only one person dares deploy it, the maintenance cost is already paying for a rebuild each year without producing one. A root-level schema error or an out-of-support platform with no migration path are the other clear cases.
- What is the safest way to replace an old system?
- Incrementally, with the old system serving traffic throughout. Carve out one capability at a time behind a stable interface, give the new component ownership of its own data, make traffic routable to either side and back, and decide per entity which side is authoritative during the transition. Each piece is verified in production as it moves, and the project can stop at any boundary with the work so far still delivering value. A rewrite concentrates all the risk into one switch-over event instead.
- Where do incremental migrations go wrong?
- Two places. The first is shared data with no decision about which side is authoritative, so both systems believe they own a record and a reconciliation job quietly hides the disagreement. The second is the absence of a retirement date and an owner, which turns the migration permanent and leaves you maintaining two systems, two deployment paths, and two mental models indefinitely. That is worse than either a rescue or a rebuild.
- What should happen first in a legacy rescue?
- Observability and reversibility, before any business logic changes. Structured logs and error tracking so failures are visible rather than customer-reported, a deployment path that reverts in minutes, and a staging environment close enough to production to be informative. Then end-to-end tests asserting the outcomes the business depends on, built from the outside so they do not lock in the structure you are about to change. Those tests are the highest-value code in a rescue.
- Do we have to rebuild every feature the old system has?
- Probably not, and finding out requires instrumentation rather than opinion. Log what is actually used over a quarter before deciding what has to be reproduced. Teams routinely find that a meaningful share of the surface they planned to rebuild has no users, and retiring dead functionality is cheaper than migrating it. The features that do matter include the ones a single important customer depends on absolutely, which is why usage data beats a feature inventory.
Recognize this in your own operation?
Bring us the version of it happening in your business and we will tell you which part a system can take over.