Blog
When to Rewrite vs. Refactor a Legacy System
The instinct to rewrite is almost always stronger than the case for it. Here is how to tell which one your system actually needs.
July 29, 2025 · Infinite Build Team
The instinct to rewrite a legacy system is almost always stronger than the actual case for it. Living inside a messy codebase every day makes a clean rewrite feel like the obvious answer, but the failure rate of full rewrites is high enough that the decision deserves more scrutiny than the instinct usually gets.
Refactor when the system's core architecture is sound but the implementation has decayed. If the fundamental model of the domain still makes sense, and the pain is concentrated in specific modules — inconsistent patterns, missing tests, accumulated shortcuts — that pain can usually be addressed incrementally, module by module, without stopping feature work for months.
Rewrite when the architecture itself no longer fits the problem. If the system was built around assumptions that are no longer true — a different scale, a different product direction, a data model that fundamentally does not represent what the business now does — no amount of refactoring fixes that, because the problem is not the implementation, it is the design underneath it.
The riskiest failure mode is starting a rewrite for architectural reasons and discovering, months in, that the real problems were implementation-level and could have been fixed incrementally at a fraction of the cost — while the business kept running on the old system the whole time anyway, so the rewrite bought nothing until it fully replaced it.
A useful test before committing to a rewrite: can you describe specifically what is architecturally wrong, not just what feels unpleasant to work in? "This code is ugly" is refactor territory. "This system cannot represent what our product now needs to do" is rewrite territory. If the answer is closer to the first, the discomfort is real but the fix is smaller than a rewrite.
If a rewrite is genuinely warranted, the version that survives contact with reality is rarely a clean break. It is usually incremental — running the new system alongside the old one, migrating piece by piece, keeping the business operating on something real the entire time. A rewrite that requires everything to stop until it is done is also the version most likely to run out of time, budget, or patience before it ships.