Most teams inherit software that still “works” but is increasingly expensive to change. Releases get slower, incidents get weirder, and every feature request feels like spelunking through undocumented caves. Eventually someone asks the big question: should we refactor what we have, or rewrite it?
The tricky part is that both paths can succeed and both can fail. A refactor can drag on forever without reducing risk. A rewrite can ship late, miss edge cases, and quietly regress core workflows. The goal is not to pick the most exciting option, but to pick the option that reliably improves outcomes.
This post gives you a practical decision matrix, a risk assessment checklist, and a planning approach that fits small and mid-sized teams. It also includes situations where you should do neither, and what to do instead.
Define the Problem You Are Actually Solving
Before comparing refactor versus rewrite, get specific about what is broken. “The codebase is old” is not a problem statement. It is a fact. Problems are things like: “shipping a change takes three weeks,” “we cannot meet uptime goals,” or “we cannot hire people who can work in this stack.”
A useful framing is to separate business pain from engineering discomfort. Both matter, but they lead to different decisions and different success metrics.
- Business pain: lost revenue due to downtime, customer churn due to missing features, or compliance needs you cannot meet.
- Engineering pain: no tests, brittle releases, unclear ownership, or slow local development.
Finally, define what “done” means in measurable terms. If you cannot describe success, you cannot compare options.
- Lead time for changes drops from 15 days to 3 days.
- Incident rate drops by 50%.
- Onboarding a new engineer takes 2 weeks instead of 2 months.
A Simple Decision Matrix (Refactor, Rewrite, Wrap, or Retire)
Most teams treat this as a binary choice. In practice, there are four common strategies:
- Refactor: improve the existing system in place while keeping behavior stable.
- Rewrite: build a replacement system, then cut over.
- Wrap: keep the core but put a new interface around it (API layer, UI, adapters) to reduce churn and isolate changes.
- Retire: remove or replace the capability with a product/process change (sometimes the best option).
Use this matrix to pick a default direction. It is intentionally simple. It forces a conversation about constraints.
Inputs to consider:
- Domain volatility: are requirements changing fast?
- Hidden complexity: is behavior encoded in edge cases and data?
- Safety requirements: how costly is a regression?
- Delivery pressure: can you tolerate a long parallel build?
- Talent/stack constraints: can you staff the chosen approach?
Rule of thumb outcomes:
- High hidden complexity + high regression cost -> Refactor or Wrap
- Low hidden complexity + strong delivery capacity -> Rewrite
- Stable domain + integration-heavy system -> Wrap first
- Feature is low value / duplicated -> Retire
A rewrite is most attractive when the existing behavior is well understood, the domain is stable, and you can keep the old system running long enough to build confidence in the new one. If the current system’s “real requirements” live inside years of exceptions, a rewrite is a bet against unknowns.
Key Takeaways
- Make the decision about outcomes (lead time, reliability), not aesthetics.
- Consider four options, not two: refactor, rewrite, wrap, retire.
- If hidden complexity or regression cost is high, prefer approaches that preserve behavior and migrate gradually.
Assess Risk: Data, Integrations, and Hidden Requirements
Legacy software is usually “sticky” for three reasons: data, integrations, and tacit knowledge. A good decision process surfaces these early.
1) Data risk: the schema is the product
If your database contains years of special cases, workarounds, and historical states, the data model is part of your requirements. Rewrites fail when teams treat data as just “records to migrate” instead of “business logic encoded over time.”
- How many tables or collections are actively written today?
- Are there manual backfills, spreadsheet imports, or scheduled jobs editing production data?
- Are there “magic” values known only by long-time operators?
2) Integration risk: what else depends on this?
List every upstream and downstream dependency, including the unofficial ones. For example, a finance analyst might pull a nightly export, or a sales team might rely on a specific CSV format.
- Public and internal APIs
- Webhooks and scheduled jobs
- Data warehouse feeds and exports
- Email templates, PDFs, or other generated artifacts
3) Behavioral risk: the unknown requirements
When a system has been running for years, it often supports “policy,” not just “function.” Discounts, rounding rules, eligibility logic, escalation paths, and exceptions might be implicit.
A practical technique is to write a short “behavior inventory” by harvesting production logs, support tickets, and configuration. You are not trying to document everything, just to map the top 20 behaviors that must not regress.
Plan the Work: Milestones That Reduce Regret
Whichever strategy you choose, planning should reduce uncertainty early. Big plans that only validate assumptions near the end are where legacy projects go to die.
The Two-Track Approach: Stabilize and Improve
One effective pattern is running two tracks in parallel:
- Stabilization track: tests around critical behavior, observability improvements, and small refactors that reduce incident frequency. This track pays back immediately.
- Modernization track: the larger structural change (wrap or rewrite) with explicit milestones and cutover criteria.
This avoids a common failure mode where the team stops improving the current system “because the rewrite is coming,” then the rewrite slips, and now you have two bad situations instead of one.
Plan milestones that create decision points, not just progress.
- Milestone 1: baseline metrics (lead time, error rate, top workflows) and a written “definition of safe.”
- Milestone 2: a thin slice in production (even if internal only) that exercises real data and at least one integration.
- Milestone 3: side-by-side comparison of outputs for critical workflows (old vs new) with a clear threshold for acceptable differences.
- Milestone 4: gradual cutover plan with rollback and a short “freeze window” for risky changes.
Real-World Example: The Scheduling App That Couldn’t Scale
Imagine a small services company with a custom scheduling app built years ago. It handles appointments, technician assignments, and customer notifications. Growth introduces pain: it is slow at peak times, changes break reports, and only one engineer understands it.
The team considers a rewrite in a modern stack. The decision matrix reveals:
- Hidden complexity is high: dispatch rules depend on geography, technician certifications, and a handful of “VIP exceptions” that are not written down.
- Regression cost is high: scheduling mistakes create missed appointments and refunds.
- Integrations are many: SMS provider, accounting exports, and a CRM sync.
The choice: wrap first, then refactor. They build a new API façade that standardizes inputs/outputs and adds observability. Behind the façade, they add tests around the top workflows. Only after the behavior is measurable do they replace one module: notifications. Next, they replace availability calculation. Over time, the legacy core shrinks, and each replacement comes with real production validation.
The team still ends up “rewriting,” but they do it as a series of controlled replacements rather than one all-or-nothing launch.
Common Mistakes to Avoid
- Equating “new” with “better”: newer frameworks do not remove domain complexity. They can just make it easier to move faster in the wrong direction.
- Starting with the UI: a new UI on top of unstable behavior can amplify issues. Start with the critical business workflows and the data boundaries.
- No hard cutover criteria: “We’ll switch when it’s ready” is not a plan. Define measurable thresholds: error rate, performance, and workflow parity.
- Ignoring operations: migrations fail because of missing runbooks, dashboards, and rollback paths, not because of code style.
- Stopping investment in the current system: treat stabilization as a first-class workstream until the new path is proven.
When Not to Rewrite (and What to Do Instead)
Rewrites are appealing, but there are times they are simply the wrong bet. Consider not rewriting when:
- The domain is changing rapidly: you will rebuild the wrong thing. Prefer wrapping and extracting a stable contract while learning.
- You cannot run systems in parallel: if you cannot validate new behavior against real traffic or real data, risk goes up sharply. Prefer refactoring and adding tests.
- The main issue is operational: outages caused by missing monitoring, bad deployment processes, or unclear ownership are rarely fixed by a rewrite. Fix the operating model first.
- The feature is not strategic: if the capability is commodity or shrinking in value, retiring or replacing with a simpler process might beat engineering investment.
Alternatives that often deliver faster wins include: adding a protective test harness around the highest value workflows, introducing an API boundary to decouple clients, and removing rarely used features that create disproportionate maintenance drag.
Checklist: Your Next 10 Questions
Copy this checklist into a project doc and answer it before committing to a multi-month modernization effort:
- What are the top three measurable pains (lead time, incidents, cost) and their baseline values?
- Which workflows generate most revenue or customer value, and what is their acceptable error rate?
- What hidden requirements are likely (exceptions, policies, special customers), and where can we find evidence?
- How many integrations exist, including unofficial exports and manual processes?
- Can we run old and new paths in parallel for comparison? If not, what is the mitigation?
- What is the rollback plan for each cutover step?
- What is the smallest thin slice that touches real data and one integration?
- What will we do to stabilize the current system while modernization is underway?
- How will we staff the work without starving critical roadmap commitments?
- What is the explicit decision point where we would stop, pivot, or reduce scope?
Conclusion
Choosing between refactoring and rewriting is less about ideology and more about risk management. Use a matrix to consider refactor, rewrite, wrap, and retire. Then plan milestones that validate assumptions early, protect critical behavior, and keep the current system improving until the new path is proven.
If you want a simple next step: write down your success metrics, inventory your integrations, and identify the top workflows that must not regress. Those three activities alone will make the “refactor or rewrite” conversation dramatically more grounded.
FAQ
How do we estimate hidden complexity without reading the entire codebase?
Look for signals outside the code: production logs, support tickets, configuration files, and “operator knowledge” in chat threads. If a handful of people can describe dozens of exceptions from memory, complexity is likely encoded in behavior and data, not just in code structure.
Is a rewrite ever the right choice for a small team?
Yes, when the system is small enough to fully understand, the domain is stable, and you can validate correctness with a clear set of workflows and data samples. Small teams should still prefer incremental cutovers, even with a rewrite.
What is the minimum testing investment that makes modernization safer?
Start with a thin “behavior harness” around the top workflows: a small set of integration tests that exercise real data shapes and key business rules. The goal is not perfect coverage, it is confidence on the paths that pay the bills.
How do we avoid building two systems forever?
Set decommission milestones upfront: “When module X is replaced, we delete old code path Y,” and track it like any other deliverable. Also cap parallel operation time by defining readiness criteria for cutover and enforcing scope control on the legacy path.