Refactoring, modernization, rewrite: the short answer
Refactoring means improving the internal structure of code without changing what the software does for its users. A rewrite means rebuilding the application from scratch on a new codebase. Modernization (French buyers say refonte) is the project that covers one, the other, or most often a mix of both: an existing application is brought up to date, technically and sometimes functionally.
"Refactor or rewrite" is rarely an all-or-nothing choice. For most business applications the right answer is incremental modernization: keep what works, replace what blocks you piece by piece, and keep the application in production throughout. The full rewrite still has its place in a few specific cases, described below.
The definitions, precisely
What refactoring is
The reference definition comes from Martin Fowler, author of Refactoring. He describes it as a disciplined technique for restructuring existing code: the internal structure changes, the external behaviour does not (refactoring.com). The work proceeds as a series of small transformations, each of which preserves behaviour. Renaming a variable, extracting a function: each step is tiny, and the software keeps working between steps.
That last point is often forgotten. Fowler stresses it in a note on misuses of the word: refactoring is one specific technique within a broader activity, restructuring. If a team announces that the application will be broken for several days "while we refactor", what they are doing has another name.
Two practical consequences follow. Refactoring ships no visible feature, which makes it hard to sell internally. And it requires a safety net: automated tests that prove, after each step, that behaviour is intact.
What modernization covers
"Modernization", "revamp" and "re-platforming" have no academic definition. In tenders and quotes they describe a project that updates an existing application. It may include a language and framework upgrade, an architecture change, a new interface, a hosting migration, a revised data model and sometimes new features. Before comparing two modernization proposals, check what each one puts behind the word.
What a rewrite is
A rewrite, or "big bang" replacement, starts from an empty repository. The old application serves as the functional reference, and the new one replaces it in one go on cutover day. In between, the two systems coexist without talking to each other.
| Refactoring | Incremental modernization | Full rewrite | |
|---|---|---|---|
| Codebase | Kept | Replaced piece by piece | New |
| Visible behaviour | Unchanged | Unchanged, then extended | Reproduced, then extended |
| Releases | Continuous | One per increment | One final cutover |
| Value delivered along the way | Indirect (cheaper maintenance) | Yes, increment by increment | No, everything arrives at the end |
| Main risk | Invisible effort, never prioritised | A transition phase that never ends | Schedule drift and lost business rules |
Six criteria to decide
1. Are the business rules still valid? If the application does what the business expects and the problem is technical (slow to change, obsolete version, painful deployments), the code holds an asset worth preserving. If the business has changed so much that the coded rules no longer match the activity, there is less to save.
2. What is the test coverage? With tests, code can be transformed with confidence. Without tests, the first job is to write some, and that effort belongs in the budget whichever scenario you choose. In a rewrite, missing tests also mean that no executable specification describes the behaviour to reproduce.
3. Is the technology reaching end of support? A language or framework that no longer receives security fixes sets a deadline. When an upgrade path exists, moving up version by version is almost always preferable. When none exists (abandoned framework, language with no successor, discontinued proprietary platform), replacement becomes unavoidable, but it can still be incremental.
4. Does the team know the system? If the people who wrote the application have left and no documentation exists, the code is the only reliable specification. Throwing it away means throwing away the specification. That is an argument for keeping the code and mapping what exists before deciding anything, not for rewriting.
5. Is the data model healthy? Data outlives code. A coherent schema can be carried over under a modernized application. A degraded schema (columns used for something else, duplicates, missing constraints) is the most delicate workstream, because data has to be migrated without interrupting the business, whichever option you pick.
6. How fast does the business change? An application whose rules change every month cannot tolerate a feature freeze lasting several quarters. The faster the pace, the stronger the case for the incremental approach.
Decision table
| Situation | Direction |
|---|---|
| Valid rules, tests in place, supported technology | Continuous refactoring as part of everyday work |
| Valid rules, few tests, version near end of support with an upgrade path | Incremental modernization: characterization tests, then step-by-step upgrades |
| Valid rules, architecture that blocks change | Incremental modernization, one business domain at a time |
| Technology with no successor and no upgrade path | Incremental replacement behind a facade; full rewrite only if the application is small |
| Business deeply transformed, small scope, documented rules | A rewrite is a reasonable option |
| Degraded data model | Incremental modernization with a dedicated data workstream, tackled first |
A code and security audit exists precisely to fill in this table with facts rather than impressions.
Why the full rewrite is risky
The urge to rewrite everything is old, and so are the warnings. Back in 2000, Joel Spolsky argued in a much-cited essay that old code, however ugly, holds years of fixes learned from real use, and that rewriting it means giving up that knowledge. Fowler, for his part, observes that complete replacement plans fail most of the time (Strangler Fig Application). Three mechanisms explain those failures.
The feature freeze. During the rewrite, either the old application stops evolving and the business waits, or it keeps evolving and the new one chases a moving target.
The double run. Two systems have to be hosted, fixed and maintained in parallel until cutover. Every urgent fix on the old one has to be carried over to the new one.
The lost implicit rules. A ten-year-old application contains behaviours nobody documented: a particular rounding rule, an exception for one customer, a check added after an incident. They appear in no specification and resurface as defects after cutover, when users notice that "the old system used to do that".
The incremental route: four techniques
Strangler fig
Martin Fowler named the pattern after the strangler figs he saw in Queensland, which grow around a host tree until they replace it. First published as "Strangler Application", it is now called Strangler Fig Application. The principle: build the new system alongside the old one, then move behaviour across piece by piece. A facade (reverse proxy, application router) sends each request to the old or the new code. Each increment is small, therefore less risky, and delivers value without waiting for the end. We walk through a concrete case in migrating from PHP 5.6 to PHP 8.3 with the strangler pattern.
Characterization tests
The term comes from Michael Feathers, in Working Effectively with Legacy Code. A characterization test describes the actual behaviour of existing code: it does not check what the code should do, it pins down what it does today. You record the outputs produced for a representative set of inputs, then make sure they stay identical after every change. This is the answer to the implicit-rules problem: you do not need to know the rules in order to protect them.
Anti-corruption layer
Described by Eric Evans in Domain-Driven Design, the anti-corruption layer is a translation layer placed between two systems that do not share the same model. The new code works with clean concepts; the layer converts to and from the old system's tables and formats. It stops the flaws of the legacy design from leaking into the new code. It has a cost: one more component to maintain and monitor, and a decision to make about whether it is temporary or permanent.
Branch by abstraction
This technique replaces an internal component (an ORM, a library, a module) without a long-lived branch. Fowler describes it in Branch By Abstraction and credits Paul Hammant with the name. You introduce an abstraction between the calling code and the old component, route every call through it, build the new component behind the same abstraction, then switch callers over gradually before deleting the old one. The application remains releasable at every step.
Planning and budgeting a modernization in stages
- Diagnose. Inventory of versions and dependencies, state of the tests, map of business domains and data flows, list of known vulnerabilities.
- Set measurable objectives. Leave an unsupported version, shorten the time to production, make one module changeable again. A modernization with no verifiable objective has no end.
- Put the safety net in place. Characterization tests on critical journeys, a continuous integration pipeline, a representative staging environment.
- Split the work into releasable increments. Each one matches a domain or a technical step, goes to production on its own and can be rolled back.
- Start with a low-risk increment that teaches a lot. It validates the facade, the deployment and the method before you touch the core.
- Estimate increment by increment. The first increment gets a precise estimate; the following ones get a range, refined as the existing system becomes better known. Fixing a price for the whole modernization up front is a bet on code nobody has read in full yet.
- Reserve capacity for business as usual. Fixes and small changes continue during the work; leaving them out of the plan guarantees a delay.
- Delete the old code. Each increment ends with the removal of what it replaces. A modernization that deletes nothing adds a second system to the first.
The budget is then managed as a staged investment: at the end of each increment you decide to continue, reorder or stop, and in every case you are left with a working application.
What to demand from a supplier
- A written diagnosis before any commitment on scope, with its limits clearly stated.
- A reasoned recommendation between refactoring, incremental modernization and rewrite, backed by criteria.
- A plan made of increments, each released separately, with a rollback procedure.
- An explicit test strategy: what will be covered before the code is touched, and how.
- A data migration plan that is separate from the code migration plan.
- Permanent access to the source repository, the continuous integration and the environments.
- A list of what will be deleted in each increment, not only what will be added.
- Documentation and knowledge transfer planned from the start, so that you can change supplier.
Frequently asked questions
What is refactoring in software development?
It is the restructuring of existing code through a succession of small transformations, with no change to its external behaviour. The aim is code that is easier to read and to change. Users see no difference; the team maintaining the application does.
What is the difference between refactoring and rewriting?
Refactoring keeps the codebase and changes its structure step by step while the software keeps running. Rewriting discards the codebase and reproduces the behaviour in new code. The first is continuous and reversible; the second concentrates risk on a single cutover.
When should you rewrite an application from scratch?
Rarely. A rewrite is defensible when the application is small, its rules are documented, and the business has changed enough that the existing system is no longer a useful reference. In other cases incremental replacement reaches the same result with less risk, because the application stays in production and each step can be undone.
Is refactoring the same as paying down technical debt?
Refactoring is one of the main ways to do it. The metaphor, coined by Ward Cunningham, treats the extra effort caused by poor structure as interest; cleaning up the code repays the principal (Fowler on technical debt). Upgrading versions or replacing a component also reduces debt, and those are not refactoring in the strict sense.
How long does it take to modernize a legacy application?
It depends on the size of the code, the state of the tests and the data model, and no generic figure is credible without a diagnosis. The better question is how long before the first increment reaches production. In an incremental modernization that delay is counted in weeks, and each following increment produces a visible result.
Conclusion
Refactoring, modernization and rewrite are not three competing options but three levels of intervention. Refactoring belongs in everyday work. Incremental modernization deals with structural blockers without stopping the business. The full rewrite remains the exception, reserved for small applications or for those whose business has changed in nature. In every case the decision rests on facts: state of the tests, validity of the rules, support status of the technology, health of the data. If the modernization also has to settle an architecture question, see our article on monolith vs microservices.
To assess your application and choose the right path, write to us at contact@your-digital-hub.com or see our legacy application modernization service. You can also describe your modernization project on our contact page.