Rewrite vs Refactor: A Decision Framework for Engineering Leaders
The rewrite vs refactor debate comes up in almost every engineering team that has been running for more than three years. It is also one of the most reliably mishandled decisions in software. Teams rewrite when they should refactor, and refactor endlessly when they should have committed to a rewrite. Both paths end up costing more than they needed to because the choice was made on instinct rather than analysis.
The instinct to rewrite usually surfaces when engineers are frustrated. The instinct to keep refactoring usually surfaces when stakeholders are nervous about risk. Neither instinct produces good decisions. What follows is a framework that does.
Why Rewrites Fail (and Why Teams Still Choose Them)
The classic failure mode is well documented: the new system takes three times as long as estimated, the old system keeps accumulating features during the build, and the cutover never quite happens cleanly. The team ends up maintaining two systems, morale drops, and eventually the rewrite either ships in a compromised state or gets abandoned.
Joel Spolsky wrote about this in 2000 in one of the most-cited pieces of engineering writing ever published. Teams still make the same mistake. The appeal is understandable: a rewrite feels like a clean slate. The problem is that the complexity you are rewriting away usually lives in the business logic and requirements, not the code structure — and you are taking it with you.
The new system will need to handle the same edge cases as the old one. It will need to integrate with the same upstream and downstream dependencies. It will be built by the same organisation, under the same delivery pressures, making some of the same architectural decisions. The clean slate is partly an illusion.
That said, rewrites are sometimes the right call. The point is not to avoid them — it is to choose them deliberately rather than emotionally.
Why Refactors Stall
Refactors fail for a different reason. Where rewrites fail from overconfidence, refactors fail from underspecification.
“We’re refactoring the payments module” can mean anything. It can continue indefinitely while feature work competes for the same engineers. It produces no clear moment of completion, no measurable outcome, and no obvious way to decide whether it was worth doing. Without a concrete target state and a timeline, refactors become background noise that never ship and never stop.
The teams we work with that run successful refactors all have the same thing in common: they treated the refactor like a project, not a state of mind. They defined what done looked like before they started.
The Decision Framework: Three Questions
Before choosing a path, work through these three questions in order.
1. Can you describe the target state precisely?
If you cannot draw what the system should look like when the work is done — its modules, its interfaces, its data flows — you are not ready to decide between rewrite and refactor. You are not ready to start either one.
This question eliminates a large proportion of both rewrites and refactors that should not be started. “It should be cleaner” is not a target state. “The payment processing logic should be isolated behind a service boundary with a defined API, with no direct database access from calling modules” is a target state.
A rewrite requires this clarity even more than a refactor. If you cannot specify the target, the rewrite will drift toward reproducing the current system in a new language or framework, which rarely justifies the cost.
2. What is the ratio of incidental to essential complexity?
Essential complexity is the inherent difficulty of the problem domain. A payments system that handles dozens of currencies, tax regimes, and card schemes is essentially complex — that complexity does not go away regardless of how you structure the code.
Incidental complexity is the mess humans created around it: dead code paths from features that were removed, abstractions that no longer fit the domain they were built for, test coverage gaps that make every change feel dangerous, inconsistent data models that were never reconciled after a migration that half-completed.
If most of the pain you are dealing with is incidental — poor structure, unclear boundaries, accumulated shortcuts — refactoring is almost certainly the right path. The essential complexity will remain after a rewrite; only the incidental complexity disappears, and that can be addressed without starting over.
If the architecture is fundamentally mismatched to current requirements — a monolith that genuinely needs to be distributed to meet scaling requirements, a synchronous system that needs to be event-driven to meet reliability targets, a data model that cannot represent the current domain without contortion — then a rewrite may be unavoidable. Note the word “genuinely”. Most teams overestimate how often this applies to their situation.
3. Can you ship incrementally?
Rewrites that require a big-bang cutover are the most dangerous category of engineering project. They have a long time horizon with no intermediate value delivery, they accumulate risk throughout, and they require the old and new systems to be kept in sync until the cutover date — which is never as close as it looks at the start.
If you can identify seams in the system — boundaries where you can replace one component while keeping the rest running — you can use the strangler fig pattern to rewrite incrementally. The old system handles everything while the new one gradually takes over slice by slice. This approach dramatically reduces the risk profile and delivers partial value throughout.
If no such seams exist, the cost and risk of a rewrite just went up significantly. That is not a reason to abandon the decision — but it should change the approval threshold.
When to Rewrite
The legitimate cases are narrower than most teams assume:
- The technology is end-of-life with no practical upgrade path and the security risk of staying on it is unacceptable
- The architecture is fundamentally mismatched to current requirements in a way that cannot be addressed through incremental change at reasonable cost
- The cost of maintaining safe test coverage during a refactor genuinely exceeds the cost of rebuilding to a clearly-specified target — and you have done the analysis to show this, not just asserted it
If your situation does not fit one of these, you probably do not need a rewrite.
When to Refactor
Most of the time. Specifically: when the domain logic is essentially correct but the structure has degraded, when you have enough test coverage to work against safely, and when you can define milestones that each deliver value rather than accumulating toward a single distant endpoint.
A refactor that ships in milestones — each one leaving the codebase measurably better and the system fully functional — compounds. A rewrite that ships as a single release does not deliver value until it crosses the line.
The Question Engineers Hate
Every rewrite proposal should answer this: what is the rollback plan?
If the answer is “we cannot roll back once the cutover happens, the old system will be too far behind by then” — the risk profile of the project just changed substantially. That is not automatically a reason not to proceed. But it needs to be visible to everyone approving the work, and the plan for the cutover needs to reflect it.
Teams that skip this question are the ones that end up maintaining two systems indefinitely because the cutover day kept getting pushed back.
Making the Decision
The rewrite vs refactor decision is not technical. It is a risk management decision that happens to involve code. Make it with the same rigour you would apply to any other significant investment: a clear target state, an honest cost estimate including the cost of the transition period, defined success criteria, and a plan for when things take longer than expected — because they will.
The teams that handle this well are not the ones that always choose the right path. They are the ones that make the choice consciously, document why they made it, and revisit it when circumstances change.
Cloudomation helps engineering teams adopt AI development tools with the discipline and guardrails to make the results sustainable.
Book a free Assessment →