Skip to content

Legacy Code vs. Rewrites: When to Hit Reset

Software Engineering, Refactoring4 min read

Delete Everything

In the world of software engineering, the idea of completely abandoning a codebase and starting over can feel like heresy. It goes against many of the principles we hold dear: don't reinvent the wheel, don't waste resources, and, above all, don't rewrite code unless it's absolutely necessary.

I tend to agree with these principles most of the time. Rewriting code is expensive, risky, and can result in as many problems as it solves. It's easy to get caught in the trap of thinking a clean slate is the solution when, in fact, small incremental improvements can lead to a much better outcome.

However, there are times when it truly makes sense to start from scratch - and when it does, I believe the decision should be made carefully and for the right reasons.

One instance where starting over might be the best option is when inheriting badly written legacy code. Sometimes the existing code is so far gone that attempting to refactor it is like trying to build a house on a cracked foundation. You patch and patch, but the cracks keep growing, and it becomes increasingly harder to maintain. This is especially true if the code was written with short-term goals (like rapid time-to-market) rather than long-term sustainability.

A common scenario where this applies is after a startup acquisition. Startups often focus heavily on delivering a product quickly to prove market fit and attract users. The value of these companies is often in their customer base and market share, not necessarily in the engineering work behind the product. As a result, their codebases can be messy, incomplete, and poorly structured, with little thought given to scalability or maintainability.

In this case, it might be more efficient to abandon the bulk of the existing codebase and focus on what works - especially if the code doesn't align with the new company's long-term vision. Starting from scratch doesn't mean discarding everything; it means keeping the parts that matter and building something that can scale for the future. This could mean keeping the APIs or the data models (if they're still useful), but discarding everything else.

Reasons why starting over might be the best course of action:

1. Time-to-Market Is No Longer a Priority

After an acquisition, the pressure to deliver quickly is often no longer as intense. The immediate rush to get a product out the door has passed, and now it's about building something sustainable. Starting from scratch allows you to architect a solution that will last, rather than continuing to patch something that was never built to scale.

2. Long-Term Sustainability Over Quick Wins

In the early stages of a startup, speed often trumps code quality. But as the business matures, long-term sustainability becomes critical. A clean slate allows you to rethink and redesign the product with future scalability in mind.

3. Legacy Code Can Be Too Expensive to Maintain

Sometimes the cost of maintaining, debugging, and improving legacy code can outweigh the cost of building a new system. When code becomes a burden rather than a tool, it's time to ask if it's worth the effort to keep patching or if a fresh start will provide more value in the long run.

4. The Right Tools for the Job

Legacy systems often use outdated technologies or frameworks that no longer align with the needs of the business. Starting fresh lets you adopt modern technologies that can improve performance, reduce complexity, and better meet the evolving demands of the business.

5. Avoiding the Sunk Cost Fallacy

A major psychological pitfall in software development is the sunk cost fallacy - the belief that because time, effort, or resources have already been invested in the existing code, it's worth continuing to patch and improve it. But in reality, those resources are gone, and continuing to invest in a broken system doesn't help the business move forward. Sometimes, the most pragmatic choice is to recognize when you've hit a dead-end and move on - no matter how much has been invested in the original code. This mindset shift can free teams from the emotional attachment to old systems and lead to more productive, forward-thinking decisions.

How to Approach Starting Over

Starting from scratch doesn't mean throwing everything away. It's about making deliberate choices. Focus on what works and discard what doesn't. This could mean maintaining the APIs or core business logic that is still relevant and sound. Use the opportunity to refactor the pieces that matter and design the system from the ground up with scalability and future-proofing in mind.

In the end, the goal is to create a system that supports the business's growth, not just for the short term but for the long haul. Sometimes, the best way to get there is to accept that the old way won't work anymore and that starting fresh is the only way forward.

© 2025 Mat Hansen. All rights reserved.