When to Rewrite vs Refactor
You'll learn how to evaluate whether incremental improvement or a complete rewrite is the right path for legacy systems.
The Core Decision
When facing a messy legacy codebase, you face a tempting choice: should you patiently refactor it piece by piece, or tear it down and rebuild from scratch? This decision has made or broken countless projects.
Refactoring means gradually improving the existing structure while preserving behavior—you're renovating the house room by room while people still live in it.
Rewriting means building a new system from scratch to replace the old one—you're demolishing the house and constructing a new one, hoping everyone can move seamlessly.
The Rewrite Red Flags
Complete rewrites often fail because:
- You lose institutional knowledge embedded in "ugly" code (like edge case handling and business rules)
- Features keep getting added to the old system while you build the new one, creating a moving target
- Time estimates are wildly optimistic—the old system took years and many people to build
- You repeat past mistakes without the benefit of accumulated wisdom
- Business value delivery stops during the rewrite
When Refactoring Wins
Choose incremental refactoring when:
- The system still delivers value
- You can identify seams to work safely
- The core architecture is salvageable
- You need to keep delivering features
When Rewriting Makes Sense
Consider a rewrite only when:
- The technology is genuinely obsolete (unmaintainable, unsupported)
- The architecture fundamentally cannot support required capabilities
- You have extraordinary resources and timeline flexibility
- The scope is truly small and well-understood
Think of it like car repair: you don't replace your entire car because the transmission is rough—you fix the transmission. You only buy a new car when repairs exceed the car's value.
Key Takeaway: Default to incremental refactoring over rewrites—rewriting is high-risk and usually underestimates the complexity hidden in legacy systems.