Rebuild or Refactor? What to Do with Old Code
When a full rewrite makes sense, when it is a trap, and the strangler pattern for modernizing without stopping the business.
Muhammad Usman
April 20, 2026 · 2 min read
Every developer wants to rewrite the old system. Every business owner fears the cost. Both instincts are sometimes right. I have rescued enough legacy Laravel and PHP apps to have a simple framework for this call.
Refactor step by step when
- The app works and makes money today
- Problems are localized: slow pages, messy modules, missing tests
- You cannot pause new features for months
- The team understands the current system, even if they dislike it
Rebuild when
- The framework or language version is dead and unpatchable
- Every small change breaks something else and takes weeks
- The business changed and the data model no longer matches reality
- Security holes are structural, not patchable
The middle path that usually wins: strangler pattern
Keep the old system running, build replacements module by module, and route traffic over gradually. No big-bang launch, no six-month feature freeze:
# Route new modules to the new app, everything else to legacy
# nginx example
location /billing { proxy_pass http://new-app; } # rebuilt
location /reports { proxy_pass http://new-app; } # rebuilt
location / { proxy_pass http://legacy-app; } # not yet
# Repeat until location / points at the new app, then retire legacyWhy rewrites go over budget
The old code silently contains years of edge-case fixes: the customer with two accounts, the invoice rounding rule, the timezone bug from 2021. A rewrite re-discovers them one production incident at a time. Budget for that, or strangle module by module and keep the old system as the reference.
How to decide in one afternoon
List your ten most-wanted changes. Estimate each in the current codebase versus a fresh one. If most changes are painful mainly in one or two modules, refactor those modules. If every single change fights the whole system, plan the strangler rebuild.
Frequently asked questions
Why do developers always suggest a rewrite?+
Reading unfamiliar code is harder than writing new code, so rewrites feel easier than they are. They also silently re-introduce years of edge-case fixes the old code already learned.
How long does modernizing a legacy app take?+
Incremental modernization typically runs a few months alongside normal work. A full rewrite of a real production app almost always takes longer than estimated, often double.
What is the strangler pattern?+
Building the new system around the old one module by module, routing traffic to new parts as they are ready, until the legacy system can be switched off without a big-bang launch.