An old bicycle with worn brakes, rusty gears, and a torn saddle still has years left in it if the frame is sound. Replace the parts, and it rides like new for a fraction of the price. But if the frame is cracked, no amount of new parts will make it safe. That is the whole rewrite vs refactor question for a legacy Python system: are the problems in the parts, or in the frame? An experienced Python development company will usually answer that by inspecting the frame before recommending anything.
In short, refactor when the core architecture and business logic still work, and the problems are local, such as messy modules, slow queries, or outdated libraries. Rewrite only when the foundation itself blocks the business, for example, code stuck on Python 2, an abandoned framework or an architecture that cannot support what you need next. In many cases, replacing the system in stages is safer than either extreme.
The guidance reflects how Acquaint Softtech modernises Python systems as an ISO 27001-certified technology partner, drawing on 1,300+ projects and 70+ in-house engineers serving clients in the USA, UK, Europe, and Australia.
Rewrite vs refactor: the short answer
| Factor | Refactor | Rewrite |
| Architecture | Still fits the business | Blocks key requirements |
| Runtime and framework | Supported or upgradable | End of life or abandoned |
| Business logic | Correct, just messy | Unknown or unreliable |
| Risk | Lower, gradual | Higher, delayed payoff |
| Cost profile | Spread over time | Large upfront investment |
The hidden value in old code
Legacy code often carries years of fixes for edge cases nobody documented. A rewrite throws that knowledge away unless you capture it first, which is the main reason rewrites run over time and budget.
How do I know a rewrite is needed?
A rewrite is usually justified when several of these are true at once, not just one.
- Unsupported runtime: the system still runs on Python 2, which reached end of life in January 2020, or on an old Python 3 release with no security fixes.
- Dead foundations: core libraries or the framework are abandoned and have no maintained replacement path.
- Architecture mismatch: the design cannot support needs such as multi-tenancy, real-time processing, or API-first products.
- Untestable code: logic is so tangled that adding tests means rewriting it anyway.
- Lost knowledge: nobody on the team can safely explain how key parts work.
Signs that look serious but usually are not
Ugly code, inconsistent naming, slow pages and outdated dependencies feel like reasons to start over, but they are normally fixable with refactoring, profiling and upgrades.
Read Also: Business Memoirs That Actually Teach An Operating Lesson
When refactoring is the better choice
Refactor when the system does the right things in the wrong way. The aim is to improve structure without changing behaviour, one safe step at a time.
What a refactor typically includes
- Upgrading Python to a supported version, module by module
- Upgrading frameworks, such as moving Django to a current LTS release
- Adding type hints and running mypy to expose hidden bugs
- Using Ruff or pyupgrade to modernise syntax automatically
- Breaking large modules into smaller, testable pieces
Framework upgrades are where many Python refactors spend most of their time. Django 4.2 LTS, for example, stopped receiving security fixes in April 2026, so teams still on it, or on older versions, often hire Django developers to move to a supported release without disrupting users.
The middle path: replace in stages
When parts of the system need a rewrite, but the rest is sound, use the strangler fig pattern. Build new services or modules alongside the old system, route traffic to them one capability at a time, and retire legacy code as each piece is replaced.
Why staged replacement works
- The business keeps running throughout
- Each step delivers value and can be measured
- Mistakes stay small and reversible
- Budget can be approved in phases rather than all at once
How long does a Python migration take?
Timelines depend on code size, test coverage and how many integrations the system has. As a rough guide, typical ranges look like this.
| Work | Typical timeline | Main variable |
| Refactor one module | Weeks | Test coverage |
| Python 2 to 3 migration | 2 to 6 months | Dependencies and size |
| Staged replacement | 6 to 12 months | Number of modules |
| Full rewrite | 9 to 18 months | Scope and hidden logic |
What stretches timelines
Missing tests, undocumented business rules, and libraries with no Python 3 equivalent cause most delays. Running a short discovery phase first usually pays for itself.
Reduce risk either way
Whichever route you choose, the same habits protect the business.
- Write characterisation tests: capture what the system does today before changing anything.
- Measure first: profile performance and log errors so you fix real problems.
- Ship small changes: deploy often, with rollback ready.
- Keep both systems in sync: during staged replacement, compare old and new outputs.
Get the right people involved
Modernisation needs engineers who understand both the legacy code and current Python practice. Many teams hire Python developers to run the modernisation work while their own team keeps shipping features.
Making the call
A cracked frame needs a new bicycle, but worn brakes only need new brakes. Inspect your Python system the same way. If the architecture and business logic still fit, refactor and upgrade step by step. If the foundation blocks the business, replace it in stages wherever possible, and save a full rewrite for cases where nothing else will work.
FAQs
How do I know a rewrite is needed?
When the runtime or framework is unsupported, the architecture blocks key requirements, the code cannot be tested and nobody fully understands it. One issue alone rarely justifies a rewrite.
How long does a Python migration take?
A Python 2 to 3 migration typically takes 2 to 6 months, staged replacement 6 to 12 months, and a full rewrite 9 to 18 months.
Is refactoring cheaper than rewriting?
Usually, because cost is spread over time and existing business logic is preserved.
What is the strangler fig pattern?
A way to replace a system gradually by building new parts alongside the old one and retiring legacy code piece by piece.








