Risk

When to rewrite vs refactor

Full rewrites fail far more often than teams expect, and for reasons that are predictable. How to tell the rare case where a rewrite is genuinely right from the common case where it is a story people tell themselves.

3 min readBy Mayur Kale

Key takeaways

  • The instinct to rewrite is usually about not understanding the existing system rather than the system being unfixable.
  • Rewrites fail because the old system keeps changing while the new one is built, so you are chasing a moving target with half your capacity.
  • Incremental replacement, routing traffic piece by piece from old to new, gets most of the benefit with a fraction of the risk.
  • A genuine rewrite case exists when the platform is unsupported, the data model is fundamentally wrong, or the system cannot meet a hard requirement it now has.
  • If you do rewrite, freeze the old system's feature set first. A rewrite against a moving target is the standard way these fail.

At some point every engineering team proposes a rewrite. The argument is always coherent: the current system is a mess, progress has slowed, and a clean start with what we know now would be faster in the long run.

It is occasionally correct. It is more often the most expensive mistake available, and the reasons are well enough understood to check against.

Why the instinct is unreliable

Reading unfamiliar code is much harder than writing new code. This produces a persistent illusion: the existing system looks worse than it is, because the reader does not know why each strange piece exists.

Most of those strange pieces are not mess. They are encoded reality, the bug fix for the customer whose data had an unexpected shape, the workaround for the third-party API that returns an error on Sundays, the special case for the enterprise account that pays for a quarter of your revenue.

A rewrite discards all of it, and rediscovers it through production incidents over the following year.

The structural reason rewrites fail

The decisive problem is not technical. It is that the business does not stop.

While you rewrite, the old system keeps accruing bug fixes, compliance changes and features that customers are paying for. So you are building toward a target that moves, with a team split across both. The new system is perpetually a few months from parity, and "a few months from parity" is a state that can persist for years.

Meanwhile nothing ships to customers, which becomes progressively harder to defend.

Incremental replacement instead

The pattern that works is to replace pieces while the system keeps running, Fowler's strangler fig. Build the new component alongside the old, route the relevant traffic to it, verify, move on.

  • Each increment delivers value on its own
  • Each can be reversed independently if it goes wrong
  • The system is working throughout
  • You can stop at any point and still be better off
  • Learning from the first piece informs the second

It is slower in total than an idealised rewrite. It is faster than a real one, and it does not require anyone to hold their nerve for eighteen months.

When a rewrite is genuinely right

The narrow set of cases:

The platform is unsupported. A runtime with no security patches, a database version past end of life. This is a hard deadline, not a preference.

The data model cannot express the business. If every new feature requires a workaround because the fundamental shape is wrong, incremental change genuinely cannot fix it, you are patching around the foundation.

A hard requirement cannot be met. A regulatory obligation, a security posture or a performance floor the architecture cannot reach. Note the word cannot; "would be difficult" does not qualify.

It is small. If a full rewrite is three weeks, do whichever you prefer. The risk of a small rewrite is small.

What is not on this list: the team dislikes the language, a newer framework exists, or the code is ugly. Those are real feelings and they are not business cases.

If you do it, do it properly

Freeze the old system. Critical fixes only. Building against a moving target is the standard failure, and the freeze is the single most important decision.

Feature parity and nothing else. Every improvement gets deferred to after the switch. Scope expansion during a rewrite is how eighteen months becomes three years.

Ship in slices. Even a rewrite can be migrated incrementally, take real traffic on part of it as early as possible. A cutover that has never carried production load is an unbounded risk.

Keep the old system running until you are certain. The ability to route back is worth the cost of maintaining both.

Set a reassessment date. A point at which you will honestly evaluate whether to continue. Sunk cost is at its most persuasive halfway through a rewrite.

The question to ask first

Before approving either: what specific thing will we be able to do afterwards that we cannot do now?

If the answer is a concrete capability, meet a regulation, support a volume, ship a feature that is currently impossible, you have a business case, and you can size it.

If the answer is "development will be faster", ask for the number. How much faster, measured how, and how long until the rewrite has paid back the year it cost? That question resolves most rewrite proposals on its own.

Frequently asked questions

Should we rewrite our legacy system?

Usually not, and the instinct is worth interrogating before acting on it. Most rewrite proposals come from unfamiliarity with the existing system rather than from a specific defect in it, the code looks worse than it is because the reader does not know why each odd thing is there. Genuine cases exist, but they are narrower than they feel: an unsupported platform, a data model that cannot express the current business, or a hard requirement the architecture cannot meet.

Why do software rewrites fail so often?

Mainly because the business does not stop while you rewrite. The old system continues accruing fixes and features, so the new one is chasing a moving target with a fraction of the team. Meanwhile all the accumulated edge-case handling in the old code, which looks like mess but is usually years of encoded reality, gets lost and has to be rediscovered through production incidents.

What is incremental replacement?

Building the new system alongside the old one and moving functionality across piece by piece, with traffic routed to whichever handles a given path. Each increment delivers value and can be reversed independently, so the risk is bounded at every step. It takes longer in total than an idealised rewrite and succeeds far more often than a real one.

When is a full rewrite actually justified?

When the platform is genuinely unsupported and cannot be patched; when the data model cannot represent what the business now does, so every feature requires a workaround; when a hard requirement, regulatory, security, performance, cannot be met by the current architecture; or when the system is small enough that a rewrite is a matter of weeks. Note that 'the team dislikes the technology' is not on that list.

How do we stop a rewrite from dragging on?

Freeze the old system to critical fixes only, so you are not building against a moving target. Set a hard scope: feature parity and nothing more, with every improvement deferred to after the switch. Ship the new system to real traffic in slices rather than in one cutover. And set a date at which you will stop and reassess rather than continuing on sunk cost.

References & further reading

  1. [1]
  2. [2]
  3. [3]

Turn the trend into shipped software

I contract as a senior fullstack and data engineer, building the production systems your customers and your reporting depend on.

Explore services↗