# Rewrite or Refactor? How to Decide for a SaaS Backend

Canonical: https://collabwire.io/blog/rewrite-or-refactor-a-saas-backend

## Summary

Field note answering whether to rewrite or refactor a SaaS backend: refactor by default, rewrite only for a demonstrable structural ceiling, replace in slices, with five decision questions and the TaxiManager rebuild as the example. Includes FAQ.

## Excerpt

Refactor by default. Rewrite only when the structure itself cannot carry the next obligation, and even then replace it piece by piece. A decision test, and what we kept when we rebuilt TaxiManager.

## Tags

architecture, engineering, operations

## Content

Refactor by default. Rewrite a SaaS backend only when you can name a specific obligation that its current structure cannot carry, and even then replace it piece by piece behind a seam instead of switching off the old system on a Friday. Ugly code is not a reason to rewrite. A ceiling is: a data model, a boundary or a deployment shape that forbids what the business must do next. If you cannot name the obligation, you are looking at a refactor, or at a discomfort that no amount of new code will cure.

The reason to be strict is that a running backend contains knowledge nobody wrote down. A rewrite throws that knowledge away and then rediscovers it one production incident at a time.


## Ugly is a feeling, a ceiling is a fact


Engineers want to rewrite old systems for understandable reasons. The code is hard to read, the original authors have gone, the framework is out of fashion, and every change feels like walking through wet cement. All of that is real, and none of it is evidence that a rewrite will be cheaper than repair.

Refactoring means changing the internal structure of a system without changing what it does. It can be done in small steps, each one shippable, each one reversible. The product keeps earning while you do it. A rewrite is a bet that the new system will reach parity with the old one before the old one stops being good enough, and parity is harder than it looks, because the old system's behaviour is the specification and nobody has read it.

A ceiling is different. It is a structural limit you can demonstrate. A data model that cannot represent something the business now sells. A single deployable that cannot be changed without freezing every team. An integration that the architecture makes impossible, such as a new regulatory interface that needs state the old design never kept. When you can point to a ceiling, and show that refactoring cannot lift it, the conversation changes.


## Five questions before you decide


First, what is the next obligation the system must carry, and why can it not carry it? If the answer is "it is messy", stop. If the answer is "it needs to keep a history it was never designed to store", you have found something.

Second, is the problem the code or the data model? Code can be restructured in place. A wrong data model is the expensive one, because every feature, report and integration has grown around it. Fixing the model is often the real project, and it can sometimes be done by migrating the model while the surrounding code stays.

Third, can you describe the current behaviour with tests? If you cannot, any change, rewrite or refactor, is blind. Writing tests that capture what the system actually does today, including its oddities, is the cheapest insurance you can buy, and it is useful for both paths.

Fourth, can the work be done in slices? Put a seam around one capability, build its replacement, route traffic to it gradually and keep the old path as a fallback. This is the strangler approach, and it turns a single high-risk event into many small ones. If your system cannot be sliced at all, that is itself a finding about the architecture.

Fifth, who understands why the old behaviour exists? The field that looks pointless often exists because one customer, one accountant or one law required it. Before you delete it, someone should be able to say why it is there.


## What we kept when we rebuilt TaxiManager


We built [TaxiManager](/works/taximanager) years ago, a tax and record-keeping platform for UK taxi and private hire drivers, built around weekly workflows and accountant-ready data. It worked, it had users, and it sold. Then the world moved. Making Tax Digital arrived, HMRC integration became a real next stage and automation became part of how the product had to grow. The foundation could still serve yesterday's product. It could not cleanly carry those obligations without turning into a museum of patches.

That is a ceiling, not a feeling, and the decision followed from it. We kept the product's core: weekly driver work, structured records and data an accountant can use. We replaced the foundation beneath it with a new technical base, a new interface and a model that can grow again. We moved a working business without a brutal switch. The old version stayed available as a safety path while the new one took production, users and sales.

The longer account, including what it feels like to meet your own earlier decisions in production, is in [Your Younger Self Is Still in Production](/blog/your-younger-self-is-still-in-production). The relevant lesson here is narrower. The expensive lie in a rewrite is that the past was simply incompetent. The old system carried real product knowledge, and the job was to separate the logic that still earns trust from the structure that can no longer hold it.


## How to run it without a big bang


If you do conclude that part of the backend has to be replaced, keep the risk small. Start by writing tests that pin down the behaviour you must preserve. Pick the capability that hurts most or is blocked by the ceiling, and build its replacement behind an interface the rest of the system already uses. Move traffic over gradually. Keep the old path alive until the new one has carried real load and real edge cases. Retire the old code only after it has stopped being called.

None of this is glamorous, and that is the point. A rewrite announced as a project with an end date tends to discover its scope late. A migration done in slices discovers its scope early, while it is still cheap to change course.

Architecture work of this kind, deciding what to defend and what to replace, is the core of our [product architecture](/services/product-architecture) practice, and the systems underneath, APIs, queues and integration layers, are covered by [backend platforms](/services/backend-platforms).

Ugly code is a reason to refactor. A ceiling is the only reason to rewrite.


## Frequently asked questions



### When should you rewrite instead of refactor a backend?


Rewrite only when the current structure cannot carry a specific, necessary obligation and refactoring cannot lift that limit. Typical cases are a data model that cannot represent what the business now needs, or an architecture that makes a required integration impossible. Poor readability alone does not justify a rewrite.


### Is a full rewrite ever a good idea?


Sometimes, for small systems, when the behaviour is fully understood and tested, or when the platform underneath is no longer supported. For a running SaaS product with paying users, replacing it in slices is almost always safer than a single cutover.


### What is the strangler approach?


You place a seam around one capability of the old system, build a replacement behind it, route traffic to the replacement gradually and retire the old code when it is no longer called. The old and new systems run side by side during the transition, so a problem can be rolled back.


### Can a rewrite be done without downtime?


Yes, if the migration is designed for it. Running old and new in parallel, moving users across gradually and keeping the old version available as a fallback avoids a hard switch. We moved TaxiManager's production, users and sales to a new foundation this way, with the old version kept as a safety path.


### How do I know the old code is safe to delete?


When tests describe its behaviour, nothing calls it any more and someone can explain why each piece existed. Code that looks pointless often encodes a rule from a customer, a law or an integration, so delete only what you can account for.
