Every CTO faces the moment: the legacy system eats more time each quarter, the team complains about the codebase, and someone proposes rewriting from scratch. The temptation is real. But rewriting is the most expensive decision a CTO can make without data.
The decision framework
Four criteria guide the choice between refactoring and rewriting:
Test coverage. If the system has reliable test coverage, refactoring is viable. Without tests, every change is a bet. Refactoring untested code is like renovating a house without a foundation.
External coupling. Systems with many integrations (APIs, databases, third-party services) are dangerous to rewrite. Each integration is an error surface that needs to be reimplemented and validated.
Living knowledge. If nobody who created the system is still at the company, the tacit knowledge is gone. Rewriting without that knowledge produces a system that makes the same mistakes differently.
Business pressure. If the business needs rapid changes that the current architecture prevents, rewriting may be justified. But only if the changes are blocked by architecture, not by a lack of people.
When rewriting makes sense
Rewriting works when the underlying technology is obsolete (language without community, framework without support), when the architecture is fundamentally incompatible with the current business, or when the cost of maintaining the existing system exceeds the cost of building a new one.
Even in those cases, rewriting incrementally with the Strangler Fig pattern reduces risk. You wrap the old system with new layers, migrate functionality one piece at a time, and keep the system running throughout the transition.
The hidden cost
Rewriting costs 3 to 5 times more than estimated. Not because the team is bad, but because rewriting includes rediscovering design decisions that weren't documented, rebuilding edge cases nobody remembers, and reintegrating services that changed while the new system was being built.
The right question is not "refactor or rewrite." It is "what exactly is blocking the business, and what is the smallest change that solves it?"