Somewhere in the second month on an inherited codebase, someone says it out loud: we should just rewrite this. It is one of the most reliable events in software. It is also, most of the time, the least examined decision a team will make all year — because it doesn't arrive as a proposal with a cost attached. It arrives as relief.
The instinct is real, the diagnosis usually isn't
The feeling behind it is legitimate. The code is hard to change, changes break things far away from where you made them, and nobody can predict how long anything will take. Those are genuine symptoms. The mistake is assuming they share a single cause called “bad code,” curable by writing the code again, this time properly. Usually the actual cause is narrower: two or three modules with no boundary between them, a data model that encodes an assumption the business abandoned years ago, or a test suite so slow nobody runs it before pushing. A rewrite treats all of it as one problem and charges you for all of it.
It also quietly assumes something enormous: that you understand the current behaviour well enough to reproduce it. Every long-lived system contains behaviour nobody documented and nobody remembers — a rounding rule, a retry, an exception for one customer segment that mattered once and now just silently matters. That knowledge lives in the code. A rewrite is a bet you can extract it faster than the old system accumulated it, and the teams asking for a rewrite are usually asking precisely because they can't read the old system confidently.
The two questions we actually ask
Before anyone estimates anything, we try to answer one question: is the problem the code, or the shape? Bad code inside a good shape is a refactor — the boundaries are in sensible places, the responsibilities are roughly where you'd expect, and the mess is local enough to be cleaned one module at a time while the product keeps shipping. A bad shape is a different animal. If the domain model contradicts how the business now works, or there is no seam anywhere you could put a boundary, then refactoring means renovating rooms in a house whose foundation is in the wrong place.
The second question is about the platform underneath. Code you dislike is a preference. A framework that no longer gets security patches, a runtime past end of life, a critical dependency whose maintainer has vanished — those are deadlines somebody else set for you, and they are one of the few honest reasons to replace rather than improve. Note the asymmetry: the first question is about your business, the second is about the calendar. Neither is about taste, and taste is what most rewrite arguments are actually made of.
Replacing a system while it keeps running
When the answer genuinely is replace, the version that works is rarely the one people picture. The imagined version is a parallel build: a fresh team, a clean repository, a year, and a switchover weekend. The version that works is incremental — put a boundary in front of the old system, move one capability at a time behind it, and let the two coexist for as long as it takes. Every increment ships. Every increment is reversible. You find out in week three whether the new approach survives contact with the real, messy data, rather than in month fourteen.
That is slower on paper and faster in practice, for the same reason small pull requests beat big ones: you are never carrying more unverified work than you can hold in your head. It also removes the failure mode that kills most parallel rewrites — the old system doesn't stand still. It keeps getting features, because the business keeps needing them, and the replacement spends its entire life chasing a target moving as fast as it is.
The refactor that doesn't drift
Refactoring has its own failure mode, and it's the mirror image: a cleanup that never finishes because it never had a definition of done. “Improve the codebase” is not a goal, it's a mood. We tie restructuring to work that was going to happen anyway — the module you're about to add a feature to is the module you're allowed to reshape — and we write down in advance what the boundary should look like when it's finished. A refactor with a target is a project. A refactor without one is a tax that never expires, and it's why so many teams believe refactoring doesn't work.
What to tell whoever is paying
Both options are expensive; only one is expensive up front and invisible in the meantime. A refactor spends money alongside delivery, so there is always something to point at. A rewrite spends months during which nothing new reaches a customer, and asks the business to accept that on the promise that velocity returns afterwards. Sometimes that trade is correct. It is never correct by default, and it should never be made because a codebase is unpleasant to work in — only because its shape, or the platform under it, has genuinely stopped fitting what the business is now trying to do.









